Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="prev" href="logging-config-api.html" /> | |
13 | <link rel="parent" href="node361.html" /> | |
14 | <link rel="next" href="module-platform.html" /> | |
15 | <meta name='aesop' content='information' /> | |
16 | <title>6.29.10.2 Configuration file format</title> | |
17 | </head> | |
18 | <body> | |
19 | <DIV CLASS="navigation"> | |
20 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
21 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
22 | <tr> | |
23 | <td class='online-navigation'><a rel="prev" title="6.29.10.1 Configuration functions" | |
24 | href="logging-config-api.html"><img src='../icons/previous.png' | |
25 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
26 | <td class='online-navigation'><a rel="parent" title="6.29.10 Configuration" | |
27 | href="node361.html"><img src='../icons/up.png' | |
28 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
29 | <td class='online-navigation'><a rel="next" title="6.30 platform " | |
30 | href="module-platform.html"><img src='../icons/next.png' | |
31 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
32 | <td align="center" width="100%">Python Library Reference</td> | |
33 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
34 | href="contents.html"><img src='../icons/contents.png' | |
35 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
36 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
37 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
38 | <td class='online-navigation'><a rel="index" title="Index" | |
39 | href="genindex.html"><img src='../icons/index.png' | |
40 | border='0' height='32' alt='Index' width='32' /></A></td> | |
41 | </tr></table> | |
42 | <div class='online-navigation'> | |
43 | <b class="navlabel">Previous:</b> | |
44 | <a class="sectref" rel="prev" href="logging-config-api.html">6.29.10.1 Configuration functions</A> | |
45 | <b class="navlabel">Up:</b> | |
46 | <a class="sectref" rel="parent" href="node361.html">6.29.10 Configuration</A> | |
47 | <b class="navlabel">Next:</b> | |
48 | <a class="sectref" rel="next" href="module-platform.html">6.30 platform </A> | |
49 | </div> | |
50 | <hr /></div> | |
51 | </DIV> | |
52 | <!--End of Navigation Panel--> | |
53 | ||
54 | <H3><A NAME="SECTION00829102000000000000000"></A><A NAME="logging-config-fileformat"></A> | |
55 | <BR> | |
56 | 6.29.10.2 Configuration file format | |
57 | </H3> | |
58 | ||
59 | <P> | |
60 | The configuration file format understood by <tt class="function">fileConfig()</tt> is | |
61 | based on ConfigParser functionality. The file must contain sections | |
62 | called <code>[loggers]</code>, <code>[handlers]</code> and <code>[formatters]</code> | |
63 | which identify by name the entities of each type which are defined in | |
64 | the file. For each such entity, there is a separate section which | |
65 | identified how that entity is configured. Thus, for a logger named | |
66 | <code>log01</code> in the <code>[loggers]</code> section, the relevant | |
67 | configuration details are held in a section | |
68 | <code>[logger_log01]</code>. Similarly, a handler called <code>hand01</code> in | |
69 | the <code>[handlers]</code> section will have its configuration held in a | |
70 | section called <code>[handler_hand01]</code>, while a formatter called | |
71 | <code>form01</code> in the <code>[formatters]</code> section will have its | |
72 | configuration specified in a section called | |
73 | <code>[formatter_form01]</code>. The root logger configuration must be | |
74 | specified in a section called <code>[logger_root]</code>. | |
75 | ||
76 | <P> | |
77 | Examples of these sections in the file are given below. | |
78 | ||
79 | <P> | |
80 | <div class="verbatim"><pre> | |
81 | [loggers] | |
82 | keys=root,log02,log03,log04,log05,log06,log07 | |
83 | ||
84 | [handlers] | |
85 | keys=hand01,hand02,hand03,hand04,hand05,hand06,hand07,hand08,hand09 | |
86 | ||
87 | [formatters] | |
88 | keys=form01,form02,form03,form04,form05,form06,form07,form08,form09 | |
89 | </pre></div> | |
90 | ||
91 | <P> | |
92 | The root logger must specify a level and a list of handlers. An | |
93 | example of a root logger section is given below. | |
94 | ||
95 | <P> | |
96 | <div class="verbatim"><pre> | |
97 | [logger_root] | |
98 | level=NOTSET | |
99 | handlers=hand01 | |
100 | </pre></div> | |
101 | ||
102 | <P> | |
103 | The <code>level</code> entry can be one of <code>DEBUG, INFO, WARNING, | |
104 | ERROR, CRITICAL</code> or <code>NOTSET</code>. For the root logger only, | |
105 | <code>NOTSET</code> means that all messages will be logged. Level values are | |
106 | <tt class="function">eval()</tt>uated in the context of the <code>logging</code> package's | |
107 | namespace. | |
108 | ||
109 | <P> | |
110 | The <code>handlers</code> entry is a comma-separated list of handler names, | |
111 | which must appear in the <code>[handlers]</code> section. These names must | |
112 | appear in the <code>[handlers]</code> section and have corresponding | |
113 | sections in the configuration file. | |
114 | ||
115 | <P> | |
116 | For loggers other than the root logger, some additional information is | |
117 | required. This is illustrated by the following example. | |
118 | ||
119 | <P> | |
120 | <div class="verbatim"><pre> | |
121 | [logger_parser] | |
122 | level=DEBUG | |
123 | handlers=hand01 | |
124 | propagate=1 | |
125 | qualname=compiler.parser | |
126 | </pre></div> | |
127 | ||
128 | <P> | |
129 | The <code>level</code> and <code>handlers</code> entries are interpreted as for | |
130 | the root logger, except that if a non-root logger's level is specified | |
131 | as <code>NOTSET</code>, the system consults loggers higher up the hierarchy | |
132 | to determine the effective level of the logger. The <code>propagate</code> | |
133 | entry is set to 1 to indicate that messages must propagate to handlers | |
134 | higher up the logger hierarchy from this logger, or 0 to indicate that | |
135 | messages are <strong>not</strong> propagated to handlers up the hierarchy. The | |
136 | <code>qualname</code> entry is the hierarchical channel name of the logger, | |
137 | that is to say the name used by the application to get the logger. | |
138 | ||
139 | <P> | |
140 | Sections which specify handler configuration are exemplified by the | |
141 | following. | |
142 | ||
143 | <P> | |
144 | <div class="verbatim"><pre> | |
145 | [handler_hand01] | |
146 | class=StreamHandler | |
147 | level=NOTSET | |
148 | formatter=form01 | |
149 | args=(sys.stdout,) | |
150 | </pre></div> | |
151 | ||
152 | <P> | |
153 | The <code>class</code> entry indicates the handler's class (as determined by | |
154 | <tt class="function">eval()</tt> in the <code>logging</code> package's namespace). The | |
155 | <code>level</code> is interpreted as for loggers, and <code>NOTSET</code> is taken | |
156 | to mean "log everything". | |
157 | ||
158 | <P> | |
159 | The <code>formatter</code> entry indicates the key name of the formatter for | |
160 | this handler. If blank, a default formatter | |
161 | (<code>logging._defaultFormatter</code>) is used. If a name is specified, it | |
162 | must appear in the <code>[formatters]</code> section and have a | |
163 | corresponding section in the configuration file. | |
164 | ||
165 | <P> | |
166 | The <code>args</code> entry, when <tt class="function">eval()</tt>uated in the context of | |
167 | the <code>logging</code> package's namespace, is the list of arguments to | |
168 | the constructor for the handler class. Refer to the constructors for | |
169 | the relevant handlers, or to the examples below, to see how typical | |
170 | entries are constructed. | |
171 | ||
172 | <P> | |
173 | <div class="verbatim"><pre> | |
174 | [handler_hand02] | |
175 | class=FileHandler | |
176 | level=DEBUG | |
177 | formatter=form02 | |
178 | args=('python.log', 'w') | |
179 | ||
180 | [handler_hand03] | |
181 | class=handlers.SocketHandler | |
182 | level=INFO | |
183 | formatter=form03 | |
184 | args=('localhost', handlers.DEFAULT_TCP_LOGGING_PORT) | |
185 | ||
186 | [handler_hand04] | |
187 | class=handlers.DatagramHandler | |
188 | level=WARN | |
189 | formatter=form04 | |
190 | args=('localhost', handlers.DEFAULT_UDP_LOGGING_PORT) | |
191 | ||
192 | [handler_hand05] | |
193 | class=handlers.SysLogHandler | |
194 | level=ERROR | |
195 | formatter=form05 | |
196 | args=(('localhost', handlers.SYSLOG_UDP_PORT), handlers.SysLogHandler.LOG_USER) | |
197 | ||
198 | [handler_hand06] | |
199 | class=handlers.NTEventLogHandler | |
200 | level=CRITICAL | |
201 | formatter=form06 | |
202 | args=('Python Application', '', 'Application') | |
203 | ||
204 | [handler_hand07] | |
205 | class=handlers.SMTPHandler | |
206 | level=WARN | |
207 | formatter=form07 | |
208 | args=('localhost', 'from@abc', ['user1@abc', 'user2@xyz'], 'Logger Subject') | |
209 | ||
210 | [handler_hand08] | |
211 | class=handlers.MemoryHandler | |
212 | level=NOTSET | |
213 | formatter=form08 | |
214 | target= | |
215 | args=(10, ERROR) | |
216 | ||
217 | [handler_hand09] | |
218 | class=handlers.HTTPHandler | |
219 | level=NOTSET | |
220 | formatter=form09 | |
221 | args=('localhost:9022', '/log', 'GET') | |
222 | </pre></div> | |
223 | ||
224 | <P> | |
225 | Sections which specify formatter configuration are typified by the following. | |
226 | ||
227 | <P> | |
228 | <div class="verbatim"><pre> | |
229 | [formatter_form01] | |
230 | format=F1 %(asctime)s %(levelname)s %(message)s | |
231 | datefmt= | |
232 | </pre></div> | |
233 | ||
234 | <P> | |
235 | The <code>format</code> entry is the overall format string, and the | |
236 | <code>datefmt</code> entry is the <tt class="function">strftime()</tt>-compatible date/time format | |
237 | string. If empty, the package substitutes ISO8601 format date/times, which | |
238 | is almost equivalent to specifying the date format string "The ISO8601 format also specifies milliseconds, which are appended to the | |
239 | result of using the above format string, with a comma separator. An example | |
240 | time in ISO8601 format is <code>2003-01-23 00:29:50,411</code>. | |
241 | ||
242 | <DIV CLASS="navigation"> | |
243 | <div class='online-navigation'> | |
244 | <p></p><hr /> | |
245 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
246 | <tr> | |
247 | <td class='online-navigation'><a rel="prev" title="6.29.10.1 Configuration functions" | |
248 | href="logging-config-api.html"><img src='../icons/previous.png' | |
249 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
250 | <td class='online-navigation'><a rel="parent" title="6.29.10 Configuration" | |
251 | href="node361.html"><img src='../icons/up.png' | |
252 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
253 | <td class='online-navigation'><a rel="next" title="6.30 platform " | |
254 | href="module-platform.html"><img src='../icons/next.png' | |
255 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
256 | <td align="center" width="100%">Python Library Reference</td> | |
257 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
258 | href="contents.html"><img src='../icons/contents.png' | |
259 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
260 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
261 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
262 | <td class='online-navigation'><a rel="index" title="Index" | |
263 | href="genindex.html"><img src='../icons/index.png' | |
264 | border='0' height='32' alt='Index' width='32' /></A></td> | |
265 | </tr></table> | |
266 | <div class='online-navigation'> | |
267 | <b class="navlabel">Previous:</b> | |
268 | <a class="sectref" rel="prev" href="logging-config-api.html">6.29.10.1 Configuration functions</A> | |
269 | <b class="navlabel">Up:</b> | |
270 | <a class="sectref" rel="parent" href="node361.html">6.29.10 Configuration</A> | |
271 | <b class="navlabel">Next:</b> | |
272 | <a class="sectref" rel="next" href="module-platform.html">6.30 platform </A> | |
273 | </div> | |
274 | </div> | |
275 | <hr /> | |
276 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
277 | </DIV> | |
278 | <!--End of Navigation Panel--> | |
279 | <ADDRESS> | |
280 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
281 | </ADDRESS> | |
282 | </BODY> | |
283 | </HTML> |