Created
July 12, 2021 06:45
-
-
Save seahrh/2594469a3e9dd8197ef3279551ea246a to your computer and use it in GitHub Desktop.
python logging config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from logging.config import fileConfig | |
LOG_INI = CONF[ENVIRONMENT]["LOG_INI"] | |
LOG_DIR = CONF[ENVIRONMENT]["LOG_DIR"] | |
def get_logger(name: str = None): | |
logging.config.fileConfig(LOG_INI, defaults={"logdir": LOG_DIR}) | |
return logging.getLogger(name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[loggers] | |
keys=root,uvicorn | |
[handlers] | |
keys=consoleHandler,fileHandler | |
[formatters] | |
keys=simpleFormatter | |
[logger_root] | |
level=DEBUG | |
handlers=consoleHandler,fileHandler | |
[logger_uvicorn] | |
qualname=uvicorn | |
level=INFO | |
handlers=consoleHandler,fileHandler | |
propagate=0 | |
[handler_consoleHandler] | |
class=StreamHandler | |
level=DEBUG | |
formatter=simpleFormatter | |
args=(sys.stdout,) | |
[handler_fileHandler] | |
class=handlers.RotatingFileHandler | |
level=DEBUG | |
formatter=simpleFormatter | |
args=('%(logdir)smyapp.log','a',10000000,10) | |
[formatter_simpleFormatter] | |
format=[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s | |
datefmt= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment