0

I'm running a small python web app on Heroku and I've drained the logs to loggly. When an exception is raised, the traceback appears as separate lines in loggly. This is of course hard to search.

How do you make tracebacks appear as a single log on Loggly?

Example: enter image description here

Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359

1 Answers1

0

You should set up python logging according to the instructions in this page:

https://www.loggly.com/docs/python-http/

Modify Step 3 (where you are sending the log events) so that you can send an exception, as follows:

import logging
import logging.config
import loggly.handlers

logging.config.fileConfig('python.conf')
logger = logging.getLogger('myLogger')

logger.info('Test log')

try:
    main_loop()
except Exception:
    logger.exception("Fatal error in main loop")

You will see that the exception appears as a single log event:

{ "loggerName":"myLogger", "asciTime":"2015-08-04 15:09:00,220", "fileName":"test_log.py", "logRecordCreationTime":"1438726140.220768", "functionName":"<module>", "levelNo":"40", "lineNo":"15", "time":"220", "levelName":"ERROR", "message":"Fatal error in main loop"}
Traceback (most recent call last):
  File "./test_log.py", line 13, in <module>
    main_loop()
NameError: name 'main_loop' is not defined
}
MauricioRoman
  • 832
  • 1
  • 9
  • 15