Logging multiple lines
Nikolaus at rath.org
Wed Jun 17 04:22:31 CEST 2009
Are there any best practices for handling multi-line log messages?
For example, the program,
main = logging.getLogger()
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
bla = 42/0
generates the log messages
2009-06-16 22:19:57,515 INFO Starting
2009-06-16 22:19:57,518 ERROR Oops...
Traceback (most recent call last):
File "/home/nikratio/lib/EclipseWorkspace/playground/src/mytests.py", line 27, in <module>
bla = 42/0
ZeroDivisionError: integer division or modulo by zero
which are a mess in any logfile because they make it really difficult to
How do you usually handle multi-line messages? Do you avoid them
completely (and therefore also the exception logging facilities provided
by logging)? Or is it possible to tweak the formatter so that it inserts
the prefix at the beginning of every line?
»Time flies like an arrow, fruit flies like a Banana.«
PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
More information about the Python-list