Skip to content
Snippets Groups Projects
Commit 35a7310e authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Log Level are int or string

Sound strange, but this is the default in colorlog.
parent 0aa83798
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@ import logging
import logging.handlers
import os
import time
from typing import Any, Optional
from typing import Any, Optional, Union
import coloredlogs
from decorator import decorator
......@@ -40,14 +40,13 @@ def set_console_title(value: str):
# set xterm title
print("\x1b]0;xAAL => %s\x07" % value, end="\r")
def setup_console_logger(level: str = config.log_level):
def setup_console_logger(level: Union[str, int] = config.log_level):
fmt = "%(asctime)s %(name)-25s %(funcName)-18s %(levelname)-8s %(message)s"
# fmt = '[%(name)s] %(funcName)s %(levelname)s: %(message)s'
coloredlogs.install(level=level, fmt=fmt)
def setup_file_logger(name: str, level: str = config.log_level, filename: Optional[str] = None):
def setup_file_logger(name: str, level: Union[str, int] = config.log_level, filename: Optional[str] = None):
filename = filename or os.path.join(config.log_path, "%s.log" % name)
formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s")
handler = logging.handlers.RotatingFileHandler(filename, "a", 10000, 1, "utf8")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment