Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import datetime
import logging
import daiquiri
daiquiri.setup(
level=logging.DEBUG,
outputs=(
daiquiri.output.File('errors.log', level=logging.ERROR),
daiquiri.output.TimedRotatingFile(
'everything.log',
level=logging.DEBUG,
interval=datetime.timedelta(hours=1))
)
)
logger = daiquiri.getLogger(__name__)
logger.info('only to rotating file logger')
logger.error('both log files, including errors only')
:param suffix: The log file name suffix.
This will be only used if no filename has been provided.
:param program_name: Program name. Autodetected by default.
:param interval: datetime.timedelta instance representing
how often a new log file should be created.
:param backup_count: the maximum number of files to rotate
logging output between.
"""
logpath = _get_log_file_path(filename, directory,
program_name, suffix)
handler = logging.handlers.TimedRotatingFileHandler(
logpath,
when='S',
interval=self._timedelta_to_seconds(interval),
backupCount=backup_count)
super(TimedRotatingFile, self).__init__(handler, formatter, level)
def setup_logging():
outputs = []
if config.LOG_STDOUT:
outputs.append(
daiquiri.output.Stream(
sys.stdout, formatter=CustomFormatter(fmt=CELERY_EXTRAS_FORMAT)
)
)
if config.LOG_JSON_FILE:
outputs.append(
daiquiri.output.TimedRotatingFile(
filename=config.LOG_JSON_FILE,
level=logging.DEBUG,
interval=datetime.timedelta(seconds=5),
backup_count=48,
formatter=daiquiri.formatter.JSON_FORMATTER,
)
)
daiquiri.setup(
outputs=outputs, level=(logging.DEBUG if config.DEBUG else logging.INFO),
)
daiquiri.set_default_log_levels(
[
("celery", "INFO"),
("kombu", "WARN"),
("github.Requester", "WARN"),