Chameleon
Chameleon

Reputation: 10138

How to change Python logging format in Google App Engine globally for SDK/Production?

How to change logging format in Google App Engine with some global settings in Development or Production server. Current logging format is not much usable in some case as above since not allow to locate code which emit messages.

I want to to change this format in Development server do something showing source location for init.py from:

DEBUG    2012-10-25 21:09:11,717 __init__.py:135] google, [email protected]

To:

DEBUG    2012-10-25 21:09:11,717 parentDirectory/__init__.py:135] google, [email protected]

In production I want change it from:

DEBUG    2012-10-25 21:09:11,717 google, [email protected]

To:

DEBUG    2012-10-25 21:09:11,717 parentDirectory/__init__.py:135] google, [email protected]

Please suggest some global configurationloader - if not possible I could place in in every script but it waste of time I think - help if you know some solution to solve this problem. I was search many pages but not find solution.

Upvotes: 2

Views: 408

Answers (1)

P Shved
P Shved

Reputation: 99304

If you use webapp2 framework, you can add "global" code to appengine_config.py, which is automatically included by some AppEngine modules at import. While it seems hacky, adding logger configuration to this file seems perfectly sane, since it's a global setting as well.

The code to re-configure your logger can be found in this StackOverflow answer. Basically, you'll need to import logging, and hack into the logger that is preconfigured by AppEngine itself:

logging.getLogger().handlers[0].setFormatter(fr)

Upvotes: 2

Related Questions