| 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="next" href="minimal-example.html" /> |
| 13 | <link rel="prev" href="module-logging.html" /> |
| 14 | <link rel="parent" href="module-logging.html" /> |
| 15 | <link rel="next" href="minimal-example.html" /> |
| 16 | <meta name='aesop' content='information' /> |
| 17 | <title>6.29.1 Logger Objects</title> |
| 18 | </head> |
| 19 | <body> |
| 20 | <DIV CLASS="navigation"> |
| 21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 23 | <tr> |
| 24 | <td class='online-navigation'><a rel="prev" title="6.29 logging " |
| 25 | href="module-logging.html"><img src='../icons/previous.png' |
| 26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 27 | <td class='online-navigation'><a rel="parent" title="6.29 logging " |
| 28 | href="module-logging.html"><img src='../icons/up.png' |
| 29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 30 | <td class='online-navigation'><a rel="next" title="6.29.2 Basic example" |
| 31 | href="minimal-example.html"><img src='../icons/next.png' |
| 32 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 33 | <td align="center" width="100%">Python Library Reference</td> |
| 34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 35 | href="contents.html"><img src='../icons/contents.png' |
| 36 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 38 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 39 | <td class='online-navigation'><a rel="index" title="Index" |
| 40 | href="genindex.html"><img src='../icons/index.png' |
| 41 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 42 | </tr></table> |
| 43 | <div class='online-navigation'> |
| 44 | <b class="navlabel">Previous:</b> |
| 45 | <a class="sectref" rel="prev" href="module-logging.html">6.29 logging </A> |
| 46 | <b class="navlabel">Up:</b> |
| 47 | <a class="sectref" rel="parent" href="module-logging.html">6.29 logging </A> |
| 48 | <b class="navlabel">Next:</b> |
| 49 | <a class="sectref" rel="next" href="minimal-example.html">6.29.2 Basic example</A> |
| 50 | </div> |
| 51 | <hr /></div> |
| 52 | </DIV> |
| 53 | <!--End of Navigation Panel--> |
| 54 | |
| 55 | <H2><A NAME="SECTION0082910000000000000000"> |
| 56 | 6.29.1 Logger Objects</A> |
| 57 | </H2> |
| 58 | |
| 59 | <P> |
| 60 | Loggers have the following attributes and methods. Note that Loggers are |
| 61 | never instantiated directly, but always through the module-level function |
| 62 | <tt class="function">logging.getLogger(name)</tt>. |
| 63 | |
| 64 | <P> |
| 65 | <dl><dt><b><tt id='l2h-2473' xml:id='l2h-2473'>propagate</tt></b></dt> |
| 66 | <dd> |
| 67 | If this evaluates to false, logging messages are not passed by this |
| 68 | logger or by child loggers to higher level (ancestor) loggers. The |
| 69 | constructor sets this attribute to 1. |
| 70 | </dd></dl> |
| 71 | |
| 72 | <P> |
| 73 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 74 | <td><nobr><b><tt id='l2h-2474' xml:id='l2h-2474' class="method">setLevel</tt></b>(</nobr></td> |
| 75 | <td><var>lvl</var>)</td></tr></table></dt> |
| 76 | <dd> |
| 77 | Sets the threshold for this logger to <var>lvl</var>. Logging messages |
| 78 | which are less severe than <var>lvl</var> will be ignored. When a logger is |
| 79 | created, the level is set to <tt class="constant">NOTSET</tt> (which causes all messages |
| 80 | to be processed when the logger is the root logger, or delegation to the |
| 81 | parent when the logger is a non-root logger). Note that the root logger |
| 82 | is created with level <tt class="constant">WARNING</tt>. |
| 83 | </dl> |
| 84 | |
| 85 | <P> |
| 86 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 87 | <td><nobr><b><tt id='l2h-2475' xml:id='l2h-2475' class="method">isEnabledFor</tt></b>(</nobr></td> |
| 88 | <td><var>lvl</var>)</td></tr></table></dt> |
| 89 | <dd> |
| 90 | Indicates if a message of severity <var>lvl</var> would be processed by |
| 91 | this logger. This method checks first the module-level level set by |
| 92 | <tt class="function">logging.disable(lvl)</tt> and then the logger's effective level as |
| 93 | determined by <tt class="method">getEffectiveLevel()</tt>. |
| 94 | </dl> |
| 95 | |
| 96 | <P> |
| 97 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 98 | <td><nobr><b><tt id='l2h-2476' xml:id='l2h-2476' class="method">getEffectiveLevel</tt></b>(</nobr></td> |
| 99 | <td><var></var>)</td></tr></table></dt> |
| 100 | <dd> |
| 101 | Indicates the effective level for this logger. If a value other than |
| 102 | <tt class="constant">NOTSET</tt> has been set using <tt class="method">setLevel()</tt>, it is returned. |
| 103 | Otherwise, the hierarchy is traversed towards the root until a value |
| 104 | other than <tt class="constant">NOTSET</tt> is found, and that value is returned. |
| 105 | </dl> |
| 106 | |
| 107 | <P> |
| 108 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 109 | <td><nobr><b><tt id='l2h-2477' xml:id='l2h-2477' class="method">debug</tt></b>(</nobr></td> |
| 110 | <td><var>msg</var><big>[</big><var>, *args</var><big>[</big><var>, **kwargs</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> |
| 111 | <dd> |
| 112 | Logs a message with level <tt class="constant">DEBUG</tt> on this logger. |
| 113 | The <var>msg</var> is the message format string, and the <var>args</var> are the |
| 114 | arguments which are merged into <var>msg</var>. The only keyword argument in |
| 115 | <var>kwargs</var> which is inspected is <var>exc_info</var> which, if it does not |
| 116 | evaluate as false, causes exception information to be added to the logging |
| 117 | message. If an exception tuple (as provided by <tt class="function">sys.exc_info()</tt>) |
| 118 | is provided, it is used; otherwise, <tt class="function">sys.exc_info()</tt> is called |
| 119 | to get the exception information. |
| 120 | </dl> |
| 121 | |
| 122 | <P> |
| 123 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 124 | <td><nobr><b><tt id='l2h-2478' xml:id='l2h-2478' class="method">info</tt></b>(</nobr></td> |
| 125 | <td><var>msg</var><big>[</big><var>, *args</var><big>[</big><var>, **kwargs</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> |
| 126 | <dd> |
| 127 | Logs a message with level <tt class="constant">INFO</tt> on this logger. |
| 128 | The arguments are interpreted as for <tt class="method">debug()</tt>. |
| 129 | </dl> |
| 130 | |
| 131 | <P> |
| 132 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 133 | <td><nobr><b><tt id='l2h-2479' xml:id='l2h-2479' class="method">warning</tt></b>(</nobr></td> |
| 134 | <td><var>msg</var><big>[</big><var>, *args</var><big>[</big><var>, **kwargs</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> |
| 135 | <dd> |
| 136 | Logs a message with level <tt class="constant">WARNING</tt> on this logger. |
| 137 | The arguments are interpreted as for <tt class="method">debug()</tt>. |
| 138 | </dl> |
| 139 | |
| 140 | <P> |
| 141 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 142 | <td><nobr><b><tt id='l2h-2480' xml:id='l2h-2480' class="method">error</tt></b>(</nobr></td> |
| 143 | <td><var>msg</var><big>[</big><var>, *args</var><big>[</big><var>, **kwargs</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> |
| 144 | <dd> |
| 145 | Logs a message with level <tt class="constant">ERROR</tt> on this logger. |
| 146 | The arguments are interpreted as for <tt class="method">debug()</tt>. |
| 147 | </dl> |
| 148 | |
| 149 | <P> |
| 150 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 151 | <td><nobr><b><tt id='l2h-2481' xml:id='l2h-2481' class="method">critical</tt></b>(</nobr></td> |
| 152 | <td><var>msg</var><big>[</big><var>, *args</var><big>[</big><var>, **kwargs</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> |
| 153 | <dd> |
| 154 | Logs a message with level <tt class="constant">CRITICAL</tt> on this logger. |
| 155 | The arguments are interpreted as for <tt class="method">debug()</tt>. |
| 156 | </dl> |
| 157 | |
| 158 | <P> |
| 159 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 160 | <td><nobr><b><tt id='l2h-2482' xml:id='l2h-2482' class="method">log</tt></b>(</nobr></td> |
| 161 | <td><var>lvl, msg</var><big>[</big><var>, *args</var><big>[</big><var>, **kwargs</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> |
| 162 | <dd> |
| 163 | Logs a message with integer level <var>lvl</var> on this logger. |
| 164 | The other arguments are interpreted as for <tt class="method">debug()</tt>. |
| 165 | </dl> |
| 166 | |
| 167 | <P> |
| 168 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 169 | <td><nobr><b><tt id='l2h-2483' xml:id='l2h-2483' class="method">exception</tt></b>(</nobr></td> |
| 170 | <td><var>msg</var><big>[</big><var>, *args</var><big>]</big><var></var>)</td></tr></table></dt> |
| 171 | <dd> |
| 172 | Logs a message with level <tt class="constant">ERROR</tt> on this logger. |
| 173 | The arguments are interpreted as for <tt class="method">debug()</tt>. Exception info |
| 174 | is added to the logging message. This method should only be called |
| 175 | from an exception handler. |
| 176 | </dl> |
| 177 | |
| 178 | <P> |
| 179 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 180 | <td><nobr><b><tt id='l2h-2484' xml:id='l2h-2484' class="method">addFilter</tt></b>(</nobr></td> |
| 181 | <td><var>filt</var>)</td></tr></table></dt> |
| 182 | <dd> |
| 183 | Adds the specified filter <var>filt</var> to this logger. |
| 184 | </dl> |
| 185 | |
| 186 | <P> |
| 187 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 188 | <td><nobr><b><tt id='l2h-2485' xml:id='l2h-2485' class="method">removeFilter</tt></b>(</nobr></td> |
| 189 | <td><var>filt</var>)</td></tr></table></dt> |
| 190 | <dd> |
| 191 | Removes the specified filter <var>filt</var> from this logger. |
| 192 | </dl> |
| 193 | |
| 194 | <P> |
| 195 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 196 | <td><nobr><b><tt id='l2h-2486' xml:id='l2h-2486' class="method">filter</tt></b>(</nobr></td> |
| 197 | <td><var>record</var>)</td></tr></table></dt> |
| 198 | <dd> |
| 199 | Applies this logger's filters to the record and returns a true value if |
| 200 | the record is to be processed. |
| 201 | </dl> |
| 202 | |
| 203 | <P> |
| 204 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 205 | <td><nobr><b><tt id='l2h-2487' xml:id='l2h-2487' class="method">addHandler</tt></b>(</nobr></td> |
| 206 | <td><var>hdlr</var>)</td></tr></table></dt> |
| 207 | <dd> |
| 208 | Adds the specified handler <var>hdlr</var> to this logger. |
| 209 | </dl> |
| 210 | |
| 211 | <P> |
| 212 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 213 | <td><nobr><b><tt id='l2h-2488' xml:id='l2h-2488' class="method">removeHandler</tt></b>(</nobr></td> |
| 214 | <td><var>hdlr</var>)</td></tr></table></dt> |
| 215 | <dd> |
| 216 | Removes the specified handler <var>hdlr</var> from this logger. |
| 217 | </dl> |
| 218 | |
| 219 | <P> |
| 220 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 221 | <td><nobr><b><tt id='l2h-2489' xml:id='l2h-2489' class="method">findCaller</tt></b>(</nobr></td> |
| 222 | <td><var></var>)</td></tr></table></dt> |
| 223 | <dd> |
| 224 | Finds the caller's source filename and line number. Returns the filename |
| 225 | and line number as a 2-element tuple. |
| 226 | </dl> |
| 227 | |
| 228 | <P> |
| 229 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 230 | <td><nobr><b><tt id='l2h-2490' xml:id='l2h-2490' class="method">handle</tt></b>(</nobr></td> |
| 231 | <td><var>record</var>)</td></tr></table></dt> |
| 232 | <dd> |
| 233 | Handles a record by passing it to all handlers associated with this logger |
| 234 | and its ancestors (until a false value of <var>propagate</var> is found). |
| 235 | This method is used for unpickled records received from a socket, as well |
| 236 | as those created locally. Logger-level filtering is applied using |
| 237 | <tt class="method">filter()</tt>. |
| 238 | </dl> |
| 239 | |
| 240 | <P> |
| 241 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 242 | <td><nobr><b><tt id='l2h-2491' xml:id='l2h-2491' class="method">makeRecord</tt></b>(</nobr></td> |
| 243 | <td><var>name, lvl, fn, lno, msg, args, exc_info</var>)</td></tr></table></dt> |
| 244 | <dd> |
| 245 | This is a factory method which can be overridden in subclasses to create |
| 246 | specialized <tt class="class">LogRecord</tt> instances. |
| 247 | </dl> |
| 248 | |
| 249 | <P> |
| 250 | |
| 251 | <DIV CLASS="navigation"> |
| 252 | <div class='online-navigation'> |
| 253 | <p></p><hr /> |
| 254 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 255 | <tr> |
| 256 | <td class='online-navigation'><a rel="prev" title="6.29 logging " |
| 257 | href="module-logging.html"><img src='../icons/previous.png' |
| 258 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 259 | <td class='online-navigation'><a rel="parent" title="6.29 logging " |
| 260 | href="module-logging.html"><img src='../icons/up.png' |
| 261 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 262 | <td class='online-navigation'><a rel="next" title="6.29.2 Basic example" |
| 263 | href="minimal-example.html"><img src='../icons/next.png' |
| 264 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 265 | <td align="center" width="100%">Python Library Reference</td> |
| 266 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 267 | href="contents.html"><img src='../icons/contents.png' |
| 268 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 269 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 270 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 271 | <td class='online-navigation'><a rel="index" title="Index" |
| 272 | href="genindex.html"><img src='../icons/index.png' |
| 273 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 274 | </tr></table> |
| 275 | <div class='online-navigation'> |
| 276 | <b class="navlabel">Previous:</b> |
| 277 | <a class="sectref" rel="prev" href="module-logging.html">6.29 logging </A> |
| 278 | <b class="navlabel">Up:</b> |
| 279 | <a class="sectref" rel="parent" href="module-logging.html">6.29 logging </A> |
| 280 | <b class="navlabel">Next:</b> |
| 281 | <a class="sectref" rel="next" href="minimal-example.html">6.29.2 Basic example</A> |
| 282 | </div> |
| 283 | </div> |
| 284 | <hr /> |
| 285 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 286 | </DIV> |
| 287 | <!--End of Navigation Panel--> |
| 288 | <ADDRESS> |
| 289 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 290 | </ADDRESS> |
| 291 | </BODY> |
| 292 | </HTML> |