using tabulation in Python logging format
Have you tried entering a literal tab character in the config file instead of \t
? This works for me.
Sorry for coming late to the party, but the info could be useful for others also ...
I also wanted a tabulated looking log, especially the "levelname" field
my format was looking like this
format = %(asctime)s - %(levelname)s - %(name)s - %(message)s
which made my logs look something like this
2014-10-01 17:42:54,261 - INFO - internal.....
2014-10-01 17:43:09,700 - DEBUG - internal.....
2014-10-01 17:44:02,994 - WARNING - internal.....
2014-10-01 17:44:31,686 - CRTITICAL - internal.....
my solution was to change the format like this
format = %(asctime)s - %(levelname)-8s - %(name)s - %(message)s
which turned my logs in something like this
2014-10-01 17:42:54,261 - INFO - internal.....
2014-10-01 17:43:09,700 - DEBUG - internal.....
2014-10-01 17:44:02,994 - WARNING - internal.....
2014-10-01 17:44:31,686 - CRITICAL - internal.....
The "8" is the length of the longest string that is expected there, in this case, "CRITICAL". The "-" tells to right-pad the string
side-note: doing
print "-%3s-" % "abcd"
will output
-abcd-
... the string doesn't get truncated