Senthilkumar M
Senthilkumar M

Reputation: 151

How to set logging format as same as Gunicorn logging format for my customized loggers

I am working on flask app which runs through gunicorn. I need to use the same logging format of gunicorn for my customized logger. I am able to use the gunicorn's handlers and levels for my customized logger using the below code, the only thing is missing is logging format.

 if __name__ != '__main__':
     gunicorn_logger = logging_app.get_logger('gunicorn.error')
     log.handlers = gunicorn_logger.handlers
     log.setLevel(gunicorn_logger.level)

here log is my customized logger.

Upvotes: 0

Views: 437

Answers (1)

blues
blues

Reputation: 5185

The format is not a property of the logger. It is a property of the handlers. Since you are copying the handlers you are already copying the format. If you don't want to just use the same handlers you can copy the format of one handler to another like this:

new_handler.setFormatter(old_handler.formatter)

Upvotes: 1

Related Questions