1

I've created a Flask app, throughout which I create loggers in each module with the line LOGGER = logging.getLogger(__name__). In the app's main module is

if __name__ == '__main__':
   app.run(host='0.0.0.0', port=9876)
   # subprocess.call(['gunicorn', 'main:app', '-w', '5', '-b', '0.0.0.0:9876'])

The two lines under the if are alternatively commented and uncommented whether I choose to run through gunicorn or not. When not running through gunicorn, a request to an endpoint will result in logs being printed. For example:

07-23 10:38 - INFO - 127.0.0.1 - - [23/Jul/2018 10:38:49] "POST /path/to-endpoint HTTP/1.1" 200 -

But when run through gunicorn, no such logs are printed (though the expected results of the request are returned.

This question is similar to the one posed here, but the scenario is different enough that the proposed fix does not help.

Any ideas?

davidism
  • 121,510
  • 29
  • 395
  • 339
Mike S
  • 1,451
  • 1
  • 16
  • 34

1 Answers1

0

I would recommend specifying a custom name to use for your logger. I think that __name__ is probably returning something different when running it from gunicorn which you can fix by just specifying your own logger name to use across the modules.

So in every place where you get your logger object, create it like this instead:

LOGGER = logging.getLogger('my-logger-name')

Where my-logger-name is any string that you should keep the same across modules.

Karl
  • 1,664
  • 2
  • 12
  • 19