13 lines
488 B
Python
13 lines
488 B
Python
import logging
|
|
from logging.handlers import RotatingFileHandler
|
|
from pathlib import Path
|
|
|
|
def configure_logging(app):
|
|
log_dir = Path('instance')
|
|
log_dir.mkdir(exist_ok=True)
|
|
handler = RotatingFileHandler(log_dir / 'app.log', maxBytes=1_000_000, backupCount=5)
|
|
handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s [%(name)s] %(message)s'))
|
|
app.logger.setLevel(app.config['LOG_LEVEL'])
|
|
if not app.logger.handlers:
|
|
app.logger.addHandler(handler)
|