13.4. Logging Config Basic
filename
- Specifies that aFileHandler
be created, using the specified filename, rather than aStreamHandler
filemode
- If filename is specified, open the file in this mode. Defaults to'a'
format
- Use the specified format string for the handlerdatefmt
- Use the specified date/time format, as accepted bytime.strftime()
style
- If format is specified, use this style for the format string. One of'%'
,'{'
or'$'
for printf-style,str.format()
orstring.Template
respectively. Defaults to'%'
level
- Set the root logger level to the specified levelstream
- Use the specified stream to initialize theStreamHandler
. Note that this argument is incompatible withfilename
- if both are present, aValueError
is raisedhandlers
- If specified, this should be an iterable of already created handlers to add to the root logger. Any handlers which don't already have a formatter set will be assigned the default formatter created in this function. Note that this argument is incompatible withfilename
orstream
- if both are present, aValueError
is raised
import logging
logging.basicConfig(
level='DEBUG',
datefmt='%Y-%m-%d %H:%M:%S',
format='{asctime} {levelname} {message}',
style='{',
filename='/tmp/myfile.log',
filemode='w',
)