make *_logging_config independent from config.py
This commit is contained in:
parent
a10d79357e
commit
d69b24e3b5
32
__init__.py
32
__init__.py
@ -29,7 +29,6 @@ report (Report Module)
|
|||||||
__DEPENDENCIES__ = []
|
__DEPENDENCIES__ = []
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
import config
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from logging.config import dictConfig
|
from logging.config import dictConfig
|
||||||
@ -37,6 +36,18 @@ import logging.handlers
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
try:
|
||||||
|
from config import DEBUG
|
||||||
|
except ImportError:
|
||||||
|
DEBUG = True
|
||||||
|
try:
|
||||||
|
from config import LOG_LEVEL
|
||||||
|
except ImportError:
|
||||||
|
LOG_LEVEL = logging.DEBUG
|
||||||
|
try:
|
||||||
|
from config import LOG_HOSTNAME
|
||||||
|
except ImportError:
|
||||||
|
LOG_HOSTNAME = 'localhost'
|
||||||
try:
|
try:
|
||||||
from config import APP_NAME as ROOT_LOGGER_NAME
|
from config import APP_NAME as ROOT_LOGGER_NAME
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -205,14 +216,25 @@ def add_handler_socket(logger: logging.Logger, level: int = logging.DEBUG, host:
|
|||||||
|
|
||||||
|
|
||||||
def app_logging_config():
|
def app_logging_config():
|
||||||
|
"""You are able to configure logging by a config file including these line:
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
DEBUG = False
|
||||||
|
#
|
||||||
|
# Logging
|
||||||
|
#
|
||||||
|
LOG_HOSTNAME = "loggy" # When DEBUG is True
|
||||||
|
"""
|
||||||
logger = logging.getLogger(ROOT_LOGGER_NAME)
|
logger = logging.getLogger(ROOT_LOGGER_NAME)
|
||||||
if config.DEBUG:
|
if DEBUG:
|
||||||
add_handler_socket(logger, host=config.LOG_HOSTNAME)
|
add_handler_socket(logger, host=LOG_HOSTNAME)
|
||||||
return logger.getChild('main')
|
return logger.getChild('main')
|
||||||
|
|
||||||
|
|
||||||
def default_logging_config(fmt=JOURNAL_FMT):
|
def default_logging_config(fmt=JOURNAL_FMT):
|
||||||
"""This requires a config file with at least these line:
|
"""You are able to configure logging by a config file including these line:
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -227,7 +249,7 @@ def default_logging_config(fmt=JOURNAL_FMT):
|
|||||||
"""
|
"""
|
||||||
logger = logging.getLogger(ROOT_LOGGER_NAME)
|
logger = logging.getLogger(ROOT_LOGGER_NAME)
|
||||||
|
|
||||||
add_handler_stdout(logger, config.LOG_LEVEL, fmt=fmt)
|
add_handler_stdout(logger, LOG_LEVEL, fmt=fmt)
|
||||||
return app_logging_config()
|
return app_logging_config()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user