Log levels also in 'request' type log entries
fegyi001 opened this issue · 2 comments
fegyi001 commented
It would be nice if the request log would also contain a default "level", e.g. level: DEBUG or level: INFO or whatever. Is there a way to do so?
bobbui commented
yes
we can add a new method to set log level in this class https://github.com/thangbn/json-logging-python/blob/master/json_logging/framework_base.py#L184.
PR is welcome 😉
bobbui commented
actually u can access the request log directly and do whatever you want with it.
app = Flask(__name__)
json_logging.ENABLE_JSON_LOGGING = True
json_logging.init_flask()
json_logging.init_request_instrument(app)
logger = logging.getLogger("test-logger")
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler(sys.stdout))
logger.addHandler(logging.handlers.RotatingFileHandler(
filename="./output.log",
maxBytes=5000000,
backupCount=10
))
request_logger = json_logging.get_request_logger()
request_logger.addHandler(logging.handlers.RotatingFileHandler(
filename="./output.log",
maxBytes=5000000,
backupCount=10
))