Initial Commit
This commit is contained in:
parent
ecdfb090e8
commit
f928c6df20
8 changed files with 270 additions and 1 deletions
0
applog/__init__.py
Normal file
0
applog/__init__.py
Normal file
40
applog/logging.yaml
Normal file
40
applog/logging.yaml
Normal file
|
@ -0,0 +1,40 @@
|
|||
version: 1
|
||||
disable_existing_loggers: True
|
||||
formatters:
|
||||
simple:
|
||||
format: "%(asctime)s - [%(threadName)s|%(levelname)s] - %(message)s"
|
||||
handlers:
|
||||
console:
|
||||
class: logging.StreamHandler
|
||||
level: DEBUG
|
||||
formatter: simple
|
||||
stream: ext://sys.stdout
|
||||
info_file_handler:
|
||||
class: logging.handlers.RotatingFileHandler
|
||||
level: INFO
|
||||
formatter: simple
|
||||
filename: applog/info.log
|
||||
maxBytes: 10485760 # 10MB
|
||||
backupCount: 20
|
||||
encoding: utf8
|
||||
error_file_handler:
|
||||
class: logging.handlers.RotatingFileHandler
|
||||
level: ERROR
|
||||
formatter: simple
|
||||
filename: applog/errors.log
|
||||
maxBytes: 10485760 # 10MB
|
||||
backupCount: 20
|
||||
encoding: utf8
|
||||
loggers:
|
||||
system:
|
||||
level: INFO
|
||||
handlers: [ console, info_file_handler ]
|
||||
propogate: no
|
||||
discord:
|
||||
level: INFO
|
||||
handlers: [ console, info_file_handler ]
|
||||
propogate: no
|
||||
bot:
|
||||
level: INFO
|
||||
handlers: [ console, info_file_handler ]
|
||||
propogate: no
|
26
applog/utils.py
Normal file
26
applog/utils.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
"""Original Credit: https://github.com/tiangolo/fastapi/issues/290#issuecomment-500119238"""
|
||||
|
||||
import logging.config
|
||||
import os
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
def read_logging_config(default_path="logging.yaml", env_key="LOG_CFG"):
|
||||
path = default_path
|
||||
value = os.getenv(env_key, None)
|
||||
if value:
|
||||
path = value
|
||||
if os.path.exists(path):
|
||||
with open(path, "rt") as f:
|
||||
logging_config = yaml.safe_load(f.read())
|
||||
return logging_config
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def setup_logging(logging_config, default_level=logging.INFO):
|
||||
if logging_config:
|
||||
logging.config.dictConfig(logging_config)
|
||||
else:
|
||||
logging.basicConfig(level=default_level)
|
Loading…
Add table
Add a link
Reference in a new issue