Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have file name and line number in GAE Python logging.info logs?

In the logs, the timestamp is available but the "source file name" and "line number" are not logged with every log message.

How to log file name and line number in GAE Python logging.info (or logging.warn or logging.error and others) ?

By "source file name", I mean the Python code file (*.py) which generated the log.

like image 479
gsinha Avatar asked Nov 09 '22 21:11

gsinha


1 Answers

In your main.py add:

formatter = logging.Formatter('%(levelname)-8s %(asctime)s %(filename)s:%(lineno)s] %(message)s')

logging.getLogger().handlers[0].setFormatter(formatter)
like image 157
Eyal Levin Avatar answered Nov 14 '22 23:11

Eyal Levin