add logging and database migration
This commit is contained in:
24
app/logging_config.py
Normal file
24
app/logging_config.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
def setup_logging(app_env: str):
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
fmt = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
|
||||
|
||||
# Always log to console (terminal / systemd)
|
||||
sh = logging.StreamHandler()
|
||||
sh.setFormatter(fmt)
|
||||
logger.addHandler(sh)
|
||||
|
||||
# Dev → additional file logging
|
||||
if app_env == "dev":
|
||||
log_dir = Path("logs")
|
||||
log_dir.mkdir(exist_ok=True)
|
||||
fh = logging.FileHandler(log_dir / "app.log", encoding="utf-8")
|
||||
fh.setFormatter(fmt)
|
||||
logger.addHandler(fh)
|
||||
|
||||
return logger
|
||||
|
||||
Reference in New Issue
Block a user