mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-03-04 12:43:13 -05:00
Feature/migration-rewrite (#278)
* start * migration rewrite * update name * convert chowdown to new methods * refactor/remove duplicate code * refactor to unify logger + log to file * remove toolbox * Display report on UI Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
@@ -40,7 +40,6 @@ def determine_secrets(data_dir: Path, production: bool) -> str:
|
||||
|
||||
# General
|
||||
DATA_DIR = determine_data_dir(PRODUCTION)
|
||||
LOGGER_FILE = DATA_DIR.joinpath("mealie.log")
|
||||
|
||||
|
||||
class AppDirectories:
|
||||
|
||||
43
mealie/core/root_logger.py
Normal file
43
mealie/core/root_logger.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from mealie.core.config import DATA_DIR
|
||||
|
||||
LOGGER_FILE = DATA_DIR.joinpath("mealie.log")
|
||||
LOGGER_FORMAT = "%(levelname)s: \t%(message)s"
|
||||
DATE_FORMAT = "%d-%b-%y %H:%M:%S"
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format=LOGGER_FORMAT, datefmt="%d-%b-%y %H:%M:%S")
|
||||
|
||||
|
||||
def logger_init() -> logging.Logger:
|
||||
""" Returns the Root Loggin Object for Mealie """
|
||||
logger = logging.getLogger("mealie")
|
||||
logger.propagate = False
|
||||
|
||||
# File Handler
|
||||
output_file_handler = logging.FileHandler(LOGGER_FILE)
|
||||
handler_format = logging.Formatter(LOGGER_FORMAT, datefmt=DATE_FORMAT)
|
||||
output_file_handler.setFormatter(handler_format)
|
||||
|
||||
# Stdout
|
||||
stdout_handler = logging.StreamHandler(sys.stdout)
|
||||
stdout_handler.setFormatter(handler_format)
|
||||
|
||||
logger.addHandler(output_file_handler)
|
||||
logger.addHandler(stdout_handler)
|
||||
|
||||
return logger
|
||||
|
||||
|
||||
def get_logger(module=None) -> logging.Logger:
|
||||
""" Returns a child logger for mealie """
|
||||
global root_logger
|
||||
|
||||
if module is None:
|
||||
return root_logger
|
||||
|
||||
return root_logger.getChild(module)
|
||||
|
||||
|
||||
root_logger = logger_init()
|
||||
Reference in New Issue
Block a user