1

I have tried to search answers for this question online, but in vain. I do see the answer for "How do set the log level in google app engine python dev server", which is useful to know - but if I understand correctly, this doesn't automatically translate to the production environment, right?

Deploying my dev code with hundreds of logging.debug() statements always makes them show up on the production server logs. Is there a simple switch I could flip on the production server to set the logging level and avoid clogging the logs with all debug messages? At least from looking at the Google App Engine's admin console, I haven't found there is a way to do this. This is hard to believe because one would think that App Engine developers would have provisioned a super simple way to do this.

Community
  • 1
  • 1
jar kir ang 1
  • 55
  • 1
  • 7
  • you can simply set a filter on the log to the level you are interested in. On the logging screen change where it says "any log level" to the level you are interested in. – Paul Collingwood Aug 30 '15 at 11:10

1 Answers1

0

As Paul Collingwood said in his comment, it is easy to set a filter in the Developer Console, in order to reduce visual clutter.

If there are cases in which you do not wish to have the debug logs recorded at all (e.g. while in production), you might like to write a little wrapper function for the logging calls, which checks whether the app is in dev or production, and based on that decides whether to write something to log.

I'm thinking something like:

import logging
class Logger()
    def debug(*args, **kwargs):
        if not running_in_production(): # needs to be implemented elsewhere.
            logging.debug(*args, **kwargs)

    def info(*args, **kwargs):
        """ any rules here? """
        logging.info(*args, **kwargs)

   # other functions here.

Then, in your individual files, you could replace import logging with import logger as logging for a drop-in replacement which is adaptable to the environment where it is running - and to any other imaginable factors.

Wilson Canda
  • 434
  • 5
  • 19
  • Thanks for the info. I am not concerned about dev environment, but only the production environment. But again this seems like a complicated solution that has to be custom implemented. This is what I am referring to as "hard to believe", since one would think that GAE would have implemented a super simple "out of the box" solution for this (like setting the log level in some configuration file etc.). Why would they make it so hard? Beats me. – jar kir ang 1 Aug 30 '15 at 19:13
  • 1
    make what so hard? Logging is fully automatic, and you can filter to the level you are interested in. You can also add additional logging statements in your code and see them in the log if desired. Seems like a reasonable system to me, especially as you can download the logs and process them locally if desired and you can store many GB's of logs quite cheaply. – Paul Collingwood Aug 31 '15 at 13:27