Skip to content

Commit

Permalink
Don't rotate logs by default (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
sayanarijit committed Jun 18, 2024
1 parent 16b800c commit 0c3268a
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions apphelpers/loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,24 @@
from loguru import logger as loguru_logger


def build_api_logger():
def build_api_logger(rotate=False):
"""
Builds multiprocess-safe (hence loguru over stdlib logger) API logger
"""
level = settings.API_LOGGER.LEVEL
handler = settings.API_LOGGER.FILEPATH
if handler: # Else log to sys.stderr by default
rotation = settings.API_LOGGER.ROTATION
retention = settings.API_LOGGER.RETENTION
loguru_logger.add(
handler,
retention=retention,
rotation=rotation,
retention=settings.API_LOGGER.RETENTION if rotate else None,
rotation=settings.API_LOGGER.ROTATION if rotate else None,
format="{time:YYYY-MM-DD HH:mm:ss} | {message}",
enqueue=True,
level=level,
level=settings.API_LOGGER.LEVEL,
)
return loguru_logger


def build_app_logger(name="app", logfile="app.log", debug=True):
def build_app_logger(name="app", logfile="app.log", debug=True, rotate=False):
"""
General purpose application logger. Useful mainly for debugging
"""
Expand All @@ -36,7 +33,11 @@ def build_app_logger(name="app", logfile="app.log", debug=True):
os.mkdir(logdir)
logpath = os.path.join(logdir, logfile)
maxBytes = 1024 * 1024 * 10
handler = RotatingFileHandler(logpath, maxBytes=maxBytes, backupCount=100)

if rotate:
handler = RotatingFileHandler(logpath, maxBytes=maxBytes, backupCount=100)
else:
handler = logging.FileHandler(logpath)
handler.setLevel(level)
formatter = logging.Formatter("[%(levelname)s] %(asctime)s: %(message)s")
handler.setFormatter(formatter)
Expand Down

0 comments on commit 0c3268a

Please sign in to comment.