What is Python's default logging formatter?
The default format is located here which is:
BASIC_FORMAT = "%(levelname)s:%(name)s:%(message)s"
The Format code will tell you how you can customize it. Here is one example on how you can customize it.
import sys
import logging
logging.basicConfig(
level=logging.DEBUG,
format="[%(asctime)s] %(levelname)s [%(name)s.%(funcName)s:%(lineno)d] %(message)s",
datefmt="%d/%b/%Y %H:%M:%S",
stream=sys.stdout)
logging.info("HEY")
Which results in:
[26/May/2013 06:41:40] INFO [root.<module>:1] HEY
import logging
print(logging.BASIC_FORMAT)
Old thread but this comes up first in my google search results for the query "python logging default format", so I thought I should add my answer.
Also some comments asked about how one could have come to discover this on their own. Here is a natural thing to do:
import logging
print(dir(logging))
BASIC_FORMAT is in there, in fact it is the first entry in the result in my case.
It's in the source of logging/__init__.py
:
_defaultFormatter = Formatter()
The default formatting string is %(message)s
, which is in the source as well:
if fmt:
self._fmt = fmt
else:
self._fmt = "%(message)s"