<!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN">
<link rel=
"STYLESHEET" href=
"lib.css" type='text/css'
/>
<link rel=
"SHORTCUT ICON" href=
"../icons/pyfav.png" type=
"image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index'
/>
<link rel=
"first" href=
"lib.html" title='Python Library Reference'
/>
<link rel='contents' href='contents.html'
title=
"Contents" />
<link rel='index' href='genindex.html' title='Index'
/>
<link rel='last' href='about.html' title='About this document...'
/>
<link rel='help' href='about.html' title='About this document...'
/>
<link rel=
"prev" href=
"logging-config-api.html" />
<link rel=
"parent" href=
"node361.html" />
<link rel=
"next" href=
"module-platform.html" />
<meta name='aesop' content='information'
/>
<title>6.29.10.2 Configuration file format
</title>
<div id='top-navigation-panel' xml:id='top-navigation-panel'
>
<table align=
"center" width=
"100%" cellpadding=
"0" cellspacing=
"2">
<td class='online-navigation'
><a rel=
"prev" title=
"6.29.10.1 Configuration functions"
href=
"logging-config-api.html"><img src='../icons/previous.png'
border='
0' height='
32' alt='Previous Page' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"parent" title=
"6.29.10 Configuration"
href=
"node361.html"><img src='../icons/up.png'
border='
0' height='
32' alt='Up One Level' width='
32'
/></A></td>
<td class='online-navigation'
><a rel=
"next" title=
"6.30 platform "
href=
"module-platform.html"><img src='../icons/next.png'
border='
0' height='
32' alt='Next Page' width='
32'
/></A></td>
<td align=
"center" width=
"100%">Python Library Reference
</td>
<td class='online-navigation'
><a rel=
"contents" title=
"Table of Contents"
href=
"contents.html"><img src='../icons/contents.png'
border='
0' height='
32' alt='Contents' width='
32'
/></A></td>
<td class='online-navigation'
><a href=
"modindex.html" title=
"Module Index"><img src='../icons/modules.png'
border='
0' height='
32' alt='Module Index' width='
32'
/></a></td>
<td class='online-navigation'
><a rel=
"index" title=
"Index"
href=
"genindex.html"><img src='../icons/index.png'
border='
0' height='
32' alt='Index' width='
32'
/></A></td>
<div class='online-navigation'
>
<b class=
"navlabel">Previous:
</b>
<a class=
"sectref" rel=
"prev" href=
"logging-config-api.html">6.29.10.1 Configuration functions
</A>
<b class=
"navlabel">Up:
</b>
<a class=
"sectref" rel=
"parent" href=
"node361.html">6.29.10 Configuration
</A>
<b class=
"navlabel">Next:
</b>
<a class=
"sectref" rel=
"next" href=
"module-platform.html">6.30 platform
</A>
<!--End of Navigation Panel-->
<H3><A NAME=
"SECTION00829102000000000000000"></A><A NAME=
"logging-config-fileformat"></A>
6.29.10.2 Configuration file format
The configuration file format understood by
<tt class=
"function">fileConfig()
</tt> is
based on ConfigParser functionality. The file must contain sections
called
<code>[loggers]
</code>,
<code>[handlers]
</code> and
<code>[formatters]
</code>
which identify by name the entities of each type which are defined in
the file. For each such entity, there is a separate section which
identified how that entity is configured. Thus, for a logger named
<code>log01
</code> in the
<code>[loggers]
</code> section, the relevant
configuration details are held in a section
<code>[logger_log01]
</code>. Similarly, a handler called
<code>hand01
</code> in
the
<code>[handlers]
</code> section will have its configuration held in a
section called
<code>[handler_hand01]
</code>, while a formatter called
<code>form01
</code> in the
<code>[formatters]
</code> section will have its
configuration specified in a section called
<code>[formatter_form01]
</code>. The root logger configuration must be
specified in a section called
<code>[logger_root]
</code>.
Examples of these sections in the file are given below.
<div class=
"verbatim"><pre>
keys=root,log02,log03,log04,log05,log06,log07
keys=hand01,hand02,hand03,hand04,hand05,hand06,hand07,hand08,hand09
keys=form01,form02,form03,form04,form05,form06,form07,form08,form09
The root logger must specify a level and a list of handlers. An
example of a root logger section is given below.
<div class=
"verbatim"><pre>
The
<code>level
</code> entry can be one of
<code>DEBUG, INFO, WARNING,
ERROR, CRITICAL
</code> or
<code>NOTSET
</code>. For the root logger only,
<code>NOTSET
</code> means that all messages will be logged. Level values are
<tt class=
"function">eval()
</tt>uated in the context of the
<code>logging
</code> package's
The
<code>handlers
</code> entry is a comma-separated list of handler names,
which must appear in the
<code>[handlers]
</code> section. These names must
appear in the
<code>[handlers]
</code> section and have corresponding
sections in the configuration file.
For loggers other than the root logger, some additional information is
required. This is illustrated by the following example.
<div class=
"verbatim"><pre>
The
<code>level
</code> and
<code>handlers
</code> entries are interpreted as for
the root logger, except that if a non-root logger's level is specified
as
<code>NOTSET
</code>, the system consults loggers higher up the hierarchy
to determine the effective level of the logger. The
<code>propagate
</code>
entry is set to
1 to indicate that messages must propagate to handlers
higher up the logger hierarchy from this logger, or
0 to indicate that
messages are
<strong>not
</strong> propagated to handlers up the hierarchy. The
<code>qualname
</code> entry is the hierarchical channel name of the logger,
that is to say the name used by the application to get the logger.
Sections which specify handler configuration are exemplified by the
<div class=
"verbatim"><pre>
The
<code>class
</code> entry indicates the handler's class (as determined by
<tt class=
"function">eval()
</tt> in the
<code>logging
</code> package's namespace). The
<code>level
</code> is interpreted as for loggers, and
<code>NOTSET
</code> is taken
to mean
"log everything".
The
<code>formatter
</code> entry indicates the key name of the formatter for
this handler. If blank, a default formatter
(
<code>logging._defaultFormatter
</code>) is used. If a name is specified, it
must appear in the
<code>[formatters]
</code> section and have a
corresponding section in the configuration file.
The
<code>args
</code> entry, when
<tt class=
"function">eval()
</tt>uated in the context of
the
<code>logging
</code> package's namespace, is the list of arguments to
the constructor for the handler class. Refer to the constructors for
the relevant handlers, or to the examples below, to see how typical
<div class=
"verbatim"><pre>
class=handlers.SocketHandler
args=('localhost', handlers.DEFAULT_TCP_LOGGING_PORT)
class=handlers.DatagramHandler
args=('localhost', handlers.DEFAULT_UDP_LOGGING_PORT)
class=handlers.SysLogHandler
args=(('localhost', handlers.SYSLOG_UDP_PORT), handlers.SysLogHandler.LOG_USER)
class=handlers.NTEventLogHandler
args=('Python Application', '', 'Application')
class=handlers.SMTPHandler
args=('localhost', 'from@abc', ['user1@abc', 'user2@xyz'], 'Logger Subject')
class=handlers.MemoryHandler
class=handlers.HTTPHandler
args=('localhost:
9022', '/log', 'GET')
Sections which specify formatter configuration are typified by the following.
<div class=
"verbatim"><pre>
format=F1 %(asctime)s %(levelname)s %(message)s
The
<code>format
</code> entry is the overall format string, and the
<code>datefmt
</code> entry is the
<tt class=
"function">strftime()
</tt>-compatible date/time format
string. If empty, the package substitutes ISO8601 format date/times, which
is almost equivalent to specifying the date format string
"The ISO8601 format also specifies milliseconds, which are appended to the
result of using the above format string, with a comma separator. An example
time in ISO8601 format is <code>2003-01-23 00:29:50,411</code>.
<div class='online-navigation'>
<table align="center
" width="100%
" cellpadding="0" cellspacing="2">
<td class='online-navigation'><a rel="prev
" title="6.29.10.1 Configuration functions
"
href="logging-config-api.html
"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent
" title="6.29.10 Configuration
"
href="node361.html
"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next
" title="6.30 platform
"
href="module-platform.html
"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center
" width="100%
">Python Library Reference</td>
<td class='online-navigation'><a rel="contents
" title="Table of Contents
"
href="contents.html
"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html
" title="Module Index
"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index
" title="Index
"
href="genindex.html
"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
<div class='online-navigation'>
<b class="navlabel
">Previous:</b>
<a class="sectref
" rel="prev
" href="logging-config-api.html
">6.29.10.1 Configuration functions</A>
<b class="navlabel
">Up:</b>
<a class="sectref
" rel="parent
" href="node361.html
">6.29.10 Configuration</A>
<b class="navlabel
">Next:</b>
<a class="sectref
" rel="next
" href="module-platform.html
">6.30 platform </A>
<span class="release-info
">Release 2.4.2, documentation updated on 28 September 2005.</span>
<!--End of Navigation Panel-->
See <i><a href="about.html
">About this document...</a></i> for information on suggesting changes.