gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1657 line
149KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="logging.handlers — Logging handlers" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/logging.handlers.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/logging/handlers.py Important: This page contains only reference information. For tutorials, please see Basic Tutorial, Advanced Tutorial, Logging Cookbook. The following useful ha..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Source code: Lib/logging/handlers.py Important: This page contains only reference information. For tutorials, please see Basic Tutorial, Advanced Tutorial, Logging Cookbook. The following useful ha..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>logging.handlers — Logging handlers &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="getpass — Portable password input" href="getpass.html" />
  33. <link rel="prev" title="logging.config — Logging configuration" href="logging.config.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/logging.handlers.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code> — Logging handlers</a><ul>
  86. <li><a class="reference internal" href="#streamhandler">StreamHandler</a></li>
  87. <li><a class="reference internal" href="#filehandler">FileHandler</a></li>
  88. <li><a class="reference internal" href="#nullhandler">NullHandler</a></li>
  89. <li><a class="reference internal" href="#watchedfilehandler">WatchedFileHandler</a></li>
  90. <li><a class="reference internal" href="#baserotatinghandler">BaseRotatingHandler</a></li>
  91. <li><a class="reference internal" href="#rotatingfilehandler">RotatingFileHandler</a></li>
  92. <li><a class="reference internal" href="#timedrotatingfilehandler">TimedRotatingFileHandler</a></li>
  93. <li><a class="reference internal" href="#sockethandler">SocketHandler</a></li>
  94. <li><a class="reference internal" href="#datagramhandler">DatagramHandler</a></li>
  95. <li><a class="reference internal" href="#sysloghandler">SysLogHandler</a></li>
  96. <li><a class="reference internal" href="#nteventloghandler">NTEventLogHandler</a></li>
  97. <li><a class="reference internal" href="#smtphandler">SMTPHandler</a></li>
  98. <li><a class="reference internal" href="#memoryhandler">MemoryHandler</a></li>
  99. <li><a class="reference internal" href="#httphandler">HTTPHandler</a></li>
  100. <li><a class="reference internal" href="#queuehandler">QueueHandler</a></li>
  101. <li><a class="reference internal" href="#queuelistener">QueueListener</a></li>
  102. </ul>
  103. </li>
  104. </ul>
  105. </div>
  106. <div>
  107. <h4>Previous topic</h4>
  108. <p class="topless"><a href="logging.config.html"
  109. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.config</span></code> — Logging configuration</a></p>
  110. </div>
  111. <div>
  112. <h4>Next topic</h4>
  113. <p class="topless"><a href="getpass.html"
  114. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">getpass</span></code> — Portable password input</a></p>
  115. </div>
  116. <div role="note" aria-label="source link">
  117. <h3>This Page</h3>
  118. <ul class="this-page-menu">
  119. <li><a href="../bugs.html">Report a Bug</a></li>
  120. <li>
  121. <a href="https://github.com/python/cpython/blob/main/Doc/library/logging.handlers.rst"
  122. rel="nofollow">Show Source
  123. </a>
  124. </li>
  125. </ul>
  126. </div>
  127. </nav>
  128. </div>
  129. </div>
  130. <div class="related" role="navigation" aria-label="related navigation">
  131. <h3>Navigation</h3>
  132. <ul>
  133. <li class="right" style="margin-right: 10px">
  134. <a href="../genindex.html" title="General Index"
  135. accesskey="I">index</a></li>
  136. <li class="right" >
  137. <a href="../py-modindex.html" title="Python Module Index"
  138. >modules</a> |</li>
  139. <li class="right" >
  140. <a href="getpass.html" title="getpass — Portable password input"
  141. accesskey="N">next</a> |</li>
  142. <li class="right" >
  143. <a href="logging.config.html" title="logging.config — Logging configuration"
  144. accesskey="P">previous</a> |</li>
  145. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  146. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  147. <li class="switchers">
  148. <div class="language_switcher_placeholder"></div>
  149. <div class="version_switcher_placeholder"></div>
  150. </li>
  151. <li>
  152. </li>
  153. <li id="cpython-language-and-version">
  154. <a href="../index.html">3.12.3 Documentation</a> &#187;
  155. </li>
  156. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  157. <li class="nav-item nav-item-2"><a href="allos.html" accesskey="U">Generic Operating System Services</a> &#187;</li>
  158. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code> — Logging handlers</a></li>
  159. <li class="right">
  160. <div class="inline-search" role="search">
  161. <form class="inline-search" action="../search.html" method="get">
  162. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  163. <input type="submit" value="Go" />
  164. </form>
  165. </div>
  166. |
  167. </li>
  168. <li class="right">
  169. <label class="theme-selector-label">
  170. Theme
  171. <select class="theme-selector" oninput="activateTheme(this.value)">
  172. <option value="auto" selected>Auto</option>
  173. <option value="light">Light</option>
  174. <option value="dark">Dark</option>
  175. </select>
  176. </label> |</li>
  177. </ul>
  178. </div>
  179. <div class="document">
  180. <div class="documentwrapper">
  181. <div class="bodywrapper">
  182. <div class="body" role="main">
  183. <section id="module-logging.handlers">
  184. <span id="logging-handlers-logging-handlers"></span><h1><a class="reference internal" href="#module-logging.handlers" title="logging.handlers: Handlers for the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code></a> — Logging handlers<a class="headerlink" href="#module-logging.handlers" title="Link to this heading">¶</a></h1>
  185. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/logging/handlers.py">Lib/logging/handlers.py</a></p>
  186. <aside class="sidebar">
  187. <p class="sidebar-title">Important</p>
  188. <p>This page contains only reference information. For tutorials,
  189. please see</p>
  190. <ul class="simple">
  191. <li><p><a class="reference internal" href="../howto/logging.html#logging-basic-tutorial"><span class="std std-ref">Basic Tutorial</span></a></p></li>
  192. <li><p><a class="reference internal" href="../howto/logging.html#logging-advanced-tutorial"><span class="std std-ref">Advanced Tutorial</span></a></p></li>
  193. <li><p><a class="reference internal" href="../howto/logging-cookbook.html#logging-cookbook"><span class="std std-ref">Logging Cookbook</span></a></p></li>
  194. </ul>
  195. </aside>
  196. <hr class="docutils" />
  197. <p>The following useful handlers are provided in the package. Note that three of
  198. the handlers (<a class="reference internal" href="#logging.StreamHandler" title="logging.StreamHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">StreamHandler</span></code></a>, <a class="reference internal" href="#logging.FileHandler" title="logging.FileHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">FileHandler</span></code></a> and
  199. <a class="reference internal" href="#logging.NullHandler" title="logging.NullHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">NullHandler</span></code></a>) are actually defined in the <a class="reference internal" href="logging.html#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a> module itself,
  200. but have been documented here along with the other handlers.</p>
  201. <section id="streamhandler">
  202. <span id="stream-handler"></span><h2>StreamHandler<a class="headerlink" href="#streamhandler" title="Link to this heading">¶</a></h2>
  203. <p>The <a class="reference internal" href="#logging.StreamHandler" title="logging.StreamHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">StreamHandler</span></code></a> class, located in the core <a class="reference internal" href="logging.html#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a> package,
  204. sends logging output to streams such as <em>sys.stdout</em>, <em>sys.stderr</em> or any
  205. file-like object (or, more precisely, any object which supports <code class="xref py py-meth docutils literal notranslate"><span class="pre">write()</span></code>
  206. and <code class="xref py py-meth docutils literal notranslate"><span class="pre">flush()</span></code> methods).</p>
  207. <dl class="py class">
  208. <dt class="sig sig-object py" id="logging.StreamHandler">
  209. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">StreamHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">stream</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.StreamHandler" title="Link to this definition">¶</a></dt>
  210. <dd><p>Returns a new instance of the <a class="reference internal" href="#logging.StreamHandler" title="logging.StreamHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">StreamHandler</span></code></a> class. If <em>stream</em> is
  211. specified, the instance will use it for logging output; otherwise, <em>sys.stderr</em>
  212. will be used.</p>
  213. <dl class="py method">
  214. <dt class="sig sig-object py" id="logging.StreamHandler.emit">
  215. <span class="sig-name descname"><span class="pre">emit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.StreamHandler.emit" title="Link to this definition">¶</a></dt>
  216. <dd><p>If a formatter is specified, it is used to format the record. The record
  217. is then written to the stream followed by <a class="reference internal" href="#logging.StreamHandler.terminator" title="logging.StreamHandler.terminator"><code class="xref py py-attr docutils literal notranslate"><span class="pre">terminator</span></code></a>. If exception information
  218. is present, it is formatted using <a class="reference internal" href="traceback.html#traceback.print_exception" title="traceback.print_exception"><code class="xref py py-func docutils literal notranslate"><span class="pre">traceback.print_exception()</span></code></a> and
  219. appended to the stream.</p>
  220. </dd></dl>
  221. <dl class="py method">
  222. <dt class="sig sig-object py" id="logging.StreamHandler.flush">
  223. <span class="sig-name descname"><span class="pre">flush</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.StreamHandler.flush" title="Link to this definition">¶</a></dt>
  224. <dd><p>Flushes the stream by calling its <a class="reference internal" href="#logging.StreamHandler.flush" title="logging.StreamHandler.flush"><code class="xref py py-meth docutils literal notranslate"><span class="pre">flush()</span></code></a> method. Note that the
  225. <code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code> method is inherited from <a class="reference internal" href="logging.html#logging.Handler" title="logging.Handler"><code class="xref py py-class docutils literal notranslate"><span class="pre">Handler</span></code></a> and so
  226. does no output, so an explicit <a class="reference internal" href="#logging.StreamHandler.flush" title="logging.StreamHandler.flush"><code class="xref py py-meth docutils literal notranslate"><span class="pre">flush()</span></code></a> call may be needed at times.</p>
  227. </dd></dl>
  228. <dl class="py method">
  229. <dt class="sig sig-object py" id="logging.StreamHandler.setStream">
  230. <span class="sig-name descname"><span class="pre">setStream</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">stream</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.StreamHandler.setStream" title="Link to this definition">¶</a></dt>
  231. <dd><p>Sets the instance’s stream to the specified value, if it is different.
  232. The old stream is flushed before the new stream is set.</p>
  233. <dl class="field-list simple">
  234. <dt class="field-odd">Parameters<span class="colon">:</span></dt>
  235. <dd class="field-odd"><p><strong>stream</strong> – The stream that the handler should use.</p>
  236. </dd>
  237. <dt class="field-even">Returns<span class="colon">:</span></dt>
  238. <dd class="field-even"><p>the old stream, if the stream was changed, or <em>None</em> if it wasn’t.</p>
  239. </dd>
  240. </dl>
  241. <div class="versionadded">
  242. <p><span class="versionmodified added">New in version 3.7.</span></p>
  243. </div>
  244. </dd></dl>
  245. <dl class="py attribute">
  246. <dt class="sig sig-object py" id="logging.StreamHandler.terminator">
  247. <span class="sig-name descname"><span class="pre">terminator</span></span><a class="headerlink" href="#logging.StreamHandler.terminator" title="Link to this definition">¶</a></dt>
  248. <dd><p>String used as the terminator when writing a formatted record to a stream.
  249. Default value is <code class="docutils literal notranslate"><span class="pre">'\n'</span></code>.</p>
  250. <p>If you don’t want a newline termination, you can set the handler instance’s
  251. <code class="docutils literal notranslate"><span class="pre">terminator</span></code> attribute to the empty string.</p>
  252. <p>In earlier versions, the terminator was hardcoded as <code class="docutils literal notranslate"><span class="pre">'\n'</span></code>.</p>
  253. <div class="versionadded">
  254. <p><span class="versionmodified added">New in version 3.2.</span></p>
  255. </div>
  256. </dd></dl>
  257. </dd></dl>
  258. </section>
  259. <section id="filehandler">
  260. <span id="file-handler"></span><h2>FileHandler<a class="headerlink" href="#filehandler" title="Link to this heading">¶</a></h2>
  261. <p>The <a class="reference internal" href="#logging.FileHandler" title="logging.FileHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">FileHandler</span></code></a> class, located in the core <a class="reference internal" href="logging.html#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a> package,
  262. sends logging output to a disk file. It inherits the output functionality from
  263. <a class="reference internal" href="#logging.StreamHandler" title="logging.StreamHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">StreamHandler</span></code></a>.</p>
  264. <dl class="py class">
  265. <dt class="sig sig-object py" id="logging.FileHandler">
  266. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">FileHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'a'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">encoding</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">delay</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">errors</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.FileHandler" title="Link to this definition">¶</a></dt>
  267. <dd><p>Returns a new instance of the <a class="reference internal" href="#logging.FileHandler" title="logging.FileHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">FileHandler</span></code></a> class. The specified file is
  268. opened and used as the stream for logging. If <em>mode</em> is not specified,
  269. <code class="docutils literal notranslate"><span class="pre">'a'</span></code> is used. If <em>encoding</em> is not <code class="docutils literal notranslate"><span class="pre">None</span></code>, it is used to open the file
  270. with that encoding. If <em>delay</em> is true, then file opening is deferred until the
  271. first call to <a class="reference internal" href="#logging.FileHandler.emit" title="logging.FileHandler.emit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">emit()</span></code></a>. By default, the file grows indefinitely. If
  272. <em>errors</em> is specified, it’s used to determine how encoding errors are handled.</p>
  273. <div class="versionchanged">
  274. <p><span class="versionmodified changed">Changed in version 3.6: </span>As well as string values, <a class="reference internal" href="pathlib.html#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">Path</span></code></a> objects are also accepted
  275. for the <em>filename</em> argument.</p>
  276. </div>
  277. <div class="versionchanged">
  278. <p><span class="versionmodified changed">Changed in version 3.9: </span>The <em>errors</em> parameter was added.</p>
  279. </div>
  280. <dl class="py method">
  281. <dt class="sig sig-object py" id="logging.FileHandler.close">
  282. <span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.FileHandler.close" title="Link to this definition">¶</a></dt>
  283. <dd><p>Closes the file.</p>
  284. </dd></dl>
  285. <dl class="py method">
  286. <dt class="sig sig-object py" id="logging.FileHandler.emit">
  287. <span class="sig-name descname"><span class="pre">emit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.FileHandler.emit" title="Link to this definition">¶</a></dt>
  288. <dd><p>Outputs the record to the file.</p>
  289. <p>Note that if the file was closed due to logging shutdown at exit and the file
  290. mode is ‘w’, the record will not be emitted (see <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=42378">bpo-42378</a>).</p>
  291. </dd></dl>
  292. </dd></dl>
  293. </section>
  294. <section id="nullhandler">
  295. <span id="null-handler"></span><h2>NullHandler<a class="headerlink" href="#nullhandler" title="Link to this heading">¶</a></h2>
  296. <div class="versionadded">
  297. <p><span class="versionmodified added">New in version 3.1.</span></p>
  298. </div>
  299. <p>The <a class="reference internal" href="#logging.NullHandler" title="logging.NullHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">NullHandler</span></code></a> class, located in the core <a class="reference internal" href="logging.html#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a> package,
  300. does not do any formatting or output. It is essentially a ‘no-op’ handler
  301. for use by library developers.</p>
  302. <dl class="py class">
  303. <dt class="sig sig-object py" id="logging.NullHandler">
  304. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.</span></span><span class="sig-name descname"><span class="pre">NullHandler</span></span><a class="headerlink" href="#logging.NullHandler" title="Link to this definition">¶</a></dt>
  305. <dd><p>Returns a new instance of the <a class="reference internal" href="#logging.NullHandler" title="logging.NullHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">NullHandler</span></code></a> class.</p>
  306. <dl class="py method">
  307. <dt class="sig sig-object py" id="logging.NullHandler.emit">
  308. <span class="sig-name descname"><span class="pre">emit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.NullHandler.emit" title="Link to this definition">¶</a></dt>
  309. <dd><p>This method does nothing.</p>
  310. </dd></dl>
  311. <dl class="py method">
  312. <dt class="sig sig-object py" id="logging.NullHandler.handle">
  313. <span class="sig-name descname"><span class="pre">handle</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.NullHandler.handle" title="Link to this definition">¶</a></dt>
  314. <dd><p>This method does nothing.</p>
  315. </dd></dl>
  316. <dl class="py method">
  317. <dt class="sig sig-object py" id="logging.NullHandler.createLock">
  318. <span class="sig-name descname"><span class="pre">createLock</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.NullHandler.createLock" title="Link to this definition">¶</a></dt>
  319. <dd><p>This method returns <code class="docutils literal notranslate"><span class="pre">None</span></code> for the lock, since there is no
  320. underlying I/O to which access needs to be serialized.</p>
  321. </dd></dl>
  322. </dd></dl>
  323. <p>See <a class="reference internal" href="../howto/logging.html#library-config"><span class="std std-ref">Configuring Logging for a Library</span></a> for more information on how to use
  324. <a class="reference internal" href="#logging.NullHandler" title="logging.NullHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">NullHandler</span></code></a>.</p>
  325. </section>
  326. <section id="watchedfilehandler">
  327. <span id="watched-file-handler"></span><h2>WatchedFileHandler<a class="headerlink" href="#watchedfilehandler" title="Link to this heading">¶</a></h2>
  328. <p>The <a class="reference internal" href="#logging.handlers.WatchedFileHandler" title="logging.handlers.WatchedFileHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">WatchedFileHandler</span></code></a> class, located in the <a class="reference internal" href="#module-logging.handlers" title="logging.handlers: Handlers for the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code></a>
  329. module, is a <code class="xref py py-class docutils literal notranslate"><span class="pre">FileHandler</span></code> which watches the file it is logging to. If
  330. the file changes, it is closed and reopened using the file name.</p>
  331. <p>A file change can happen because of usage of programs such as <em>newsyslog</em> and
  332. <em>logrotate</em> which perform log file rotation. This handler, intended for use
  333. under Unix/Linux, watches the file to see if it has changed since the last emit.
  334. (A file is deemed to have changed if its device or inode have changed.) If the
  335. file has changed, the old file stream is closed, and the file opened to get a
  336. new stream.</p>
  337. <p>This handler is not appropriate for use under Windows, because under Windows
  338. open log files cannot be moved or renamed - logging opens the files with
  339. exclusive locks - and so there is no need for such a handler. Furthermore,
  340. <em>ST_INO</em> is not supported under Windows; <a class="reference internal" href="os.html#os.stat" title="os.stat"><code class="xref py py-func docutils literal notranslate"><span class="pre">stat()</span></code></a> always returns zero
  341. for this value.</p>
  342. <dl class="py class">
  343. <dt class="sig sig-object py" id="logging.handlers.WatchedFileHandler">
  344. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.handlers.</span></span><span class="sig-name descname"><span class="pre">WatchedFileHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'a'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">encoding</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">delay</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">errors</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.WatchedFileHandler" title="Link to this definition">¶</a></dt>
  345. <dd><p>Returns a new instance of the <a class="reference internal" href="#logging.handlers.WatchedFileHandler" title="logging.handlers.WatchedFileHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">WatchedFileHandler</span></code></a> class. The specified
  346. file is opened and used as the stream for logging. If <em>mode</em> is not specified,
  347. <code class="docutils literal notranslate"><span class="pre">'a'</span></code> is used. If <em>encoding</em> is not <code class="docutils literal notranslate"><span class="pre">None</span></code>, it is used to open the file
  348. with that encoding. If <em>delay</em> is true, then file opening is deferred until the
  349. first call to <a class="reference internal" href="#logging.handlers.WatchedFileHandler.emit" title="logging.handlers.WatchedFileHandler.emit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">emit()</span></code></a>. By default, the file grows indefinitely. If
  350. <em>errors</em> is provided, it determines how encoding errors are handled.</p>
  351. <div class="versionchanged">
  352. <p><span class="versionmodified changed">Changed in version 3.6: </span>As well as string values, <a class="reference internal" href="pathlib.html#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">Path</span></code></a> objects are also accepted
  353. for the <em>filename</em> argument.</p>
  354. </div>
  355. <div class="versionchanged">
  356. <p><span class="versionmodified changed">Changed in version 3.9: </span>The <em>errors</em> parameter was added.</p>
  357. </div>
  358. <dl class="py method">
  359. <dt class="sig sig-object py" id="logging.handlers.WatchedFileHandler.reopenIfNeeded">
  360. <span class="sig-name descname"><span class="pre">reopenIfNeeded</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.WatchedFileHandler.reopenIfNeeded" title="Link to this definition">¶</a></dt>
  361. <dd><p>Checks to see if the file has changed. If it has, the existing stream is
  362. flushed and closed and the file opened again, typically as a precursor to
  363. outputting the record to the file.</p>
  364. <div class="versionadded">
  365. <p><span class="versionmodified added">New in version 3.6.</span></p>
  366. </div>
  367. </dd></dl>
  368. <dl class="py method">
  369. <dt class="sig sig-object py" id="logging.handlers.WatchedFileHandler.emit">
  370. <span class="sig-name descname"><span class="pre">emit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.WatchedFileHandler.emit" title="Link to this definition">¶</a></dt>
  371. <dd><p>Outputs the record to the file, but first calls <a class="reference internal" href="#logging.handlers.WatchedFileHandler.reopenIfNeeded" title="logging.handlers.WatchedFileHandler.reopenIfNeeded"><code class="xref py py-meth docutils literal notranslate"><span class="pre">reopenIfNeeded()</span></code></a> to
  372. reopen the file if it has changed.</p>
  373. </dd></dl>
  374. </dd></dl>
  375. </section>
  376. <section id="baserotatinghandler">
  377. <span id="base-rotating-handler"></span><h2>BaseRotatingHandler<a class="headerlink" href="#baserotatinghandler" title="Link to this heading">¶</a></h2>
  378. <p>The <a class="reference internal" href="#logging.handlers.BaseRotatingHandler" title="logging.handlers.BaseRotatingHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseRotatingHandler</span></code></a> class, located in the <a class="reference internal" href="#module-logging.handlers" title="logging.handlers: Handlers for the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code></a>
  379. module, is the base class for the rotating file handlers,
  380. <a class="reference internal" href="#logging.handlers.RotatingFileHandler" title="logging.handlers.RotatingFileHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">RotatingFileHandler</span></code></a> and <a class="reference internal" href="#logging.handlers.TimedRotatingFileHandler" title="logging.handlers.TimedRotatingFileHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">TimedRotatingFileHandler</span></code></a>. You should
  381. not need to instantiate this class, but it has attributes and methods you may
  382. need to override.</p>
  383. <dl class="py class">
  384. <dt class="sig sig-object py" id="logging.handlers.BaseRotatingHandler">
  385. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.handlers.</span></span><span class="sig-name descname"><span class="pre">BaseRotatingHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">encoding</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">delay</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">errors</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.BaseRotatingHandler" title="Link to this definition">¶</a></dt>
  386. <dd><p>The parameters are as for <code class="xref py py-class docutils literal notranslate"><span class="pre">FileHandler</span></code>. The attributes are:</p>
  387. <dl class="py attribute">
  388. <dt class="sig sig-object py" id="logging.handlers.BaseRotatingHandler.namer">
  389. <span class="sig-name descname"><span class="pre">namer</span></span><a class="headerlink" href="#logging.handlers.BaseRotatingHandler.namer" title="Link to this definition">¶</a></dt>
  390. <dd><p>If this attribute is set to a callable, the <a class="reference internal" href="#logging.handlers.BaseRotatingHandler.rotation_filename" title="logging.handlers.BaseRotatingHandler.rotation_filename"><code class="xref py py-meth docutils literal notranslate"><span class="pre">rotation_filename()</span></code></a>
  391. method delegates to this callable. The parameters passed to the callable
  392. are those passed to <a class="reference internal" href="#logging.handlers.BaseRotatingHandler.rotation_filename" title="logging.handlers.BaseRotatingHandler.rotation_filename"><code class="xref py py-meth docutils literal notranslate"><span class="pre">rotation_filename()</span></code></a>.</p>
  393. <div class="admonition note">
  394. <p class="admonition-title">Note</p>
  395. <p>The namer function is called quite a few times during rollover,
  396. so it should be as simple and as fast as possible. It should also
  397. return the same output every time for a given input, otherwise the
  398. rollover behaviour may not work as expected.</p>
  399. <p>It’s also worth noting that care should be taken when using a namer to
  400. preserve certain attributes in the filename which are used during rotation.
  401. For example, <a class="reference internal" href="#logging.handlers.RotatingFileHandler" title="logging.handlers.RotatingFileHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">RotatingFileHandler</span></code></a> expects to have a set of log files
  402. whose names contain successive integers, so that rotation works as expected,
  403. and <a class="reference internal" href="#logging.handlers.TimedRotatingFileHandler" title="logging.handlers.TimedRotatingFileHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">TimedRotatingFileHandler</span></code></a> deletes old log files (based on the
  404. <code class="docutils literal notranslate"><span class="pre">backupCount</span></code> parameter passed to the handler’s initializer) by determining
  405. the oldest files to delete. For this to happen, the filenames should be
  406. sortable using the date/time portion of the filename, and a namer needs to
  407. respect this. (If a namer is wanted that doesn’t respect this scheme, it will
  408. need to be used in a subclass of <a class="reference internal" href="#logging.handlers.TimedRotatingFileHandler" title="logging.handlers.TimedRotatingFileHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">TimedRotatingFileHandler</span></code></a> which
  409. overrides the <a class="reference internal" href="#logging.handlers.TimedRotatingFileHandler.getFilesToDelete" title="logging.handlers.TimedRotatingFileHandler.getFilesToDelete"><code class="xref py py-meth docutils literal notranslate"><span class="pre">getFilesToDelete()</span></code></a> method to
  410. fit in with the custom naming scheme.)</p>
  411. </div>
  412. <div class="versionadded">
  413. <p><span class="versionmodified added">New in version 3.3.</span></p>
  414. </div>
  415. </dd></dl>
  416. <dl class="py attribute">
  417. <dt class="sig sig-object py" id="logging.handlers.BaseRotatingHandler.rotator">
  418. <span class="sig-name descname"><span class="pre">rotator</span></span><a class="headerlink" href="#logging.handlers.BaseRotatingHandler.rotator" title="Link to this definition">¶</a></dt>
  419. <dd><p>If this attribute is set to a callable, the <a class="reference internal" href="#logging.handlers.BaseRotatingHandler.rotate" title="logging.handlers.BaseRotatingHandler.rotate"><code class="xref py py-meth docutils literal notranslate"><span class="pre">rotate()</span></code></a> method
  420. delegates to this callable. The parameters passed to the callable are
  421. those passed to <a class="reference internal" href="#logging.handlers.BaseRotatingHandler.rotate" title="logging.handlers.BaseRotatingHandler.rotate"><code class="xref py py-meth docutils literal notranslate"><span class="pre">rotate()</span></code></a>.</p>
  422. <div class="versionadded">
  423. <p><span class="versionmodified added">New in version 3.3.</span></p>
  424. </div>
  425. </dd></dl>
  426. <dl class="py method">
  427. <dt class="sig sig-object py" id="logging.handlers.BaseRotatingHandler.rotation_filename">
  428. <span class="sig-name descname"><span class="pre">rotation_filename</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">default_name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.BaseRotatingHandler.rotation_filename" title="Link to this definition">¶</a></dt>
  429. <dd><p>Modify the filename of a log file when rotating.</p>
  430. <p>This is provided so that a custom filename can be provided.</p>
  431. <p>The default implementation calls the ‘namer’ attribute of the handler,
  432. if it’s callable, passing the default name to it. If the attribute isn’t
  433. callable (the default is <code class="docutils literal notranslate"><span class="pre">None</span></code>), the name is returned unchanged.</p>
  434. <dl class="field-list simple">
  435. <dt class="field-odd">Parameters<span class="colon">:</span></dt>
  436. <dd class="field-odd"><p><strong>default_name</strong> – The default name for the log file.</p>
  437. </dd>
  438. </dl>
  439. <div class="versionadded">
  440. <p><span class="versionmodified added">New in version 3.3.</span></p>
  441. </div>
  442. </dd></dl>
  443. <dl class="py method">
  444. <dt class="sig sig-object py" id="logging.handlers.BaseRotatingHandler.rotate">
  445. <span class="sig-name descname"><span class="pre">rotate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">source</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dest</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.BaseRotatingHandler.rotate" title="Link to this definition">¶</a></dt>
  446. <dd><p>When rotating, rotate the current log.</p>
  447. <p>The default implementation calls the ‘rotator’ attribute of the handler,
  448. if it’s callable, passing the source and dest arguments to it. If the
  449. attribute isn’t callable (the default is <code class="docutils literal notranslate"><span class="pre">None</span></code>), the source is simply
  450. renamed to the destination.</p>
  451. <dl class="field-list simple">
  452. <dt class="field-odd">Parameters<span class="colon">:</span></dt>
  453. <dd class="field-odd"><ul class="simple">
  454. <li><p><strong>source</strong> – The source filename. This is normally the base
  455. filename, e.g. ‘test.log’.</p></li>
  456. <li><p><strong>dest</strong> – The destination filename. This is normally
  457. what the source is rotated to, e.g. ‘test.log.1’.</p></li>
  458. </ul>
  459. </dd>
  460. </dl>
  461. <div class="versionadded">
  462. <p><span class="versionmodified added">New in version 3.3.</span></p>
  463. </div>
  464. </dd></dl>
  465. </dd></dl>
  466. <p>The reason the attributes exist is to save you having to subclass - you can use
  467. the same callables for instances of <a class="reference internal" href="#logging.handlers.RotatingFileHandler" title="logging.handlers.RotatingFileHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">RotatingFileHandler</span></code></a> and
  468. <a class="reference internal" href="#logging.handlers.TimedRotatingFileHandler" title="logging.handlers.TimedRotatingFileHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">TimedRotatingFileHandler</span></code></a>. If either the namer or rotator callable
  469. raises an exception, this will be handled in the same way as any other
  470. exception during an <code class="xref py py-meth docutils literal notranslate"><span class="pre">emit()</span></code> call, i.e. via the <code class="xref py py-meth docutils literal notranslate"><span class="pre">handleError()</span></code> method
  471. of the handler.</p>
  472. <p>If you need to make more significant changes to rotation processing, you can
  473. override the methods.</p>
  474. <p>For an example, see <a class="reference internal" href="../howto/logging-cookbook.html#cookbook-rotator-namer"><span class="std std-ref">Using a rotator and namer to customize log rotation processing</span></a>.</p>
  475. </section>
  476. <section id="rotatingfilehandler">
  477. <span id="rotating-file-handler"></span><h2>RotatingFileHandler<a class="headerlink" href="#rotatingfilehandler" title="Link to this heading">¶</a></h2>
  478. <p>The <a class="reference internal" href="#logging.handlers.RotatingFileHandler" title="logging.handlers.RotatingFileHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">RotatingFileHandler</span></code></a> class, located in the <a class="reference internal" href="#module-logging.handlers" title="logging.handlers: Handlers for the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code></a>
  479. module, supports rotation of disk log files.</p>
  480. <dl class="py class">
  481. <dt class="sig sig-object py" id="logging.handlers.RotatingFileHandler">
  482. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.handlers.</span></span><span class="sig-name descname"><span class="pre">RotatingFileHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'a'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">maxBytes</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">backupCount</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">encoding</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">delay</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">errors</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.RotatingFileHandler" title="Link to this definition">¶</a></dt>
  483. <dd><p>Returns a new instance of the <a class="reference internal" href="#logging.handlers.RotatingFileHandler" title="logging.handlers.RotatingFileHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">RotatingFileHandler</span></code></a> class. The specified
  484. file is opened and used as the stream for logging. If <em>mode</em> is not specified,
  485. <code class="docutils literal notranslate"><span class="pre">'a'</span></code> is used. If <em>encoding</em> is not <code class="docutils literal notranslate"><span class="pre">None</span></code>, it is used to open the file
  486. with that encoding. If <em>delay</em> is true, then file opening is deferred until the
  487. first call to <a class="reference internal" href="#logging.handlers.RotatingFileHandler.emit" title="logging.handlers.RotatingFileHandler.emit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">emit()</span></code></a>. By default, the file grows indefinitely. If
  488. <em>errors</em> is provided, it determines how encoding errors are handled.</p>
  489. <p>You can use the <em>maxBytes</em> and <em>backupCount</em> values to allow the file to
  490. <em class="dfn">rollover</em> at a predetermined size. When the size is about to be exceeded,
  491. the file is closed and a new file is silently opened for output. Rollover occurs
  492. whenever the current log file is nearly <em>maxBytes</em> in length; but if either of
  493. <em>maxBytes</em> or <em>backupCount</em> is zero, rollover never occurs, so you generally want
  494. to set <em>backupCount</em> to at least 1, and have a non-zero <em>maxBytes</em>.
  495. When <em>backupCount</em> is non-zero, the system will save old log files by appending
  496. the extensions ‘.1’, ‘.2’ etc., to the filename. For example, with a <em>backupCount</em>
  497. of 5 and a base file name of <code class="file docutils literal notranslate"><span class="pre">app.log</span></code>, you would get <code class="file docutils literal notranslate"><span class="pre">app.log</span></code>,
  498. <code class="file docutils literal notranslate"><span class="pre">app.log.1</span></code>, <code class="file docutils literal notranslate"><span class="pre">app.log.2</span></code>, up to <code class="file docutils literal notranslate"><span class="pre">app.log.5</span></code>. The file being
  499. written to is always <code class="file docutils literal notranslate"><span class="pre">app.log</span></code>. When this file is filled, it is closed
  500. and renamed to <code class="file docutils literal notranslate"><span class="pre">app.log.1</span></code>, and if files <code class="file docutils literal notranslate"><span class="pre">app.log.1</span></code>,
  501. <code class="file docutils literal notranslate"><span class="pre">app.log.2</span></code>, etc. exist, then they are renamed to <code class="file docutils literal notranslate"><span class="pre">app.log.2</span></code>,
  502. <code class="file docutils literal notranslate"><span class="pre">app.log.3</span></code> etc. respectively.</p>
  503. <div class="versionchanged">
  504. <p><span class="versionmodified changed">Changed in version 3.6: </span>As well as string values, <a class="reference internal" href="pathlib.html#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">Path</span></code></a> objects are also accepted
  505. for the <em>filename</em> argument.</p>
  506. </div>
  507. <div class="versionchanged">
  508. <p><span class="versionmodified changed">Changed in version 3.9: </span>The <em>errors</em> parameter was added.</p>
  509. </div>
  510. <dl class="py method">
  511. <dt class="sig sig-object py" id="logging.handlers.RotatingFileHandler.doRollover">
  512. <span class="sig-name descname"><span class="pre">doRollover</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.RotatingFileHandler.doRollover" title="Link to this definition">¶</a></dt>
  513. <dd><p>Does a rollover, as described above.</p>
  514. </dd></dl>
  515. <dl class="py method">
  516. <dt class="sig sig-object py" id="logging.handlers.RotatingFileHandler.emit">
  517. <span class="sig-name descname"><span class="pre">emit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.RotatingFileHandler.emit" title="Link to this definition">¶</a></dt>
  518. <dd><p>Outputs the record to the file, catering for rollover as described
  519. previously.</p>
  520. </dd></dl>
  521. </dd></dl>
  522. </section>
  523. <section id="timedrotatingfilehandler">
  524. <span id="timed-rotating-file-handler"></span><h2>TimedRotatingFileHandler<a class="headerlink" href="#timedrotatingfilehandler" title="Link to this heading">¶</a></h2>
  525. <p>The <a class="reference internal" href="#logging.handlers.TimedRotatingFileHandler" title="logging.handlers.TimedRotatingFileHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">TimedRotatingFileHandler</span></code></a> class, located in the
  526. <a class="reference internal" href="#module-logging.handlers" title="logging.handlers: Handlers for the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code></a> module, supports rotation of disk log files at certain
  527. timed intervals.</p>
  528. <dl class="py class">
  529. <dt class="sig sig-object py" id="logging.handlers.TimedRotatingFileHandler">
  530. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.handlers.</span></span><span class="sig-name descname"><span class="pre">TimedRotatingFileHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">when</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'h'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">interval</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">backupCount</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">encoding</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">delay</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">utc</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">atTime</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">errors</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.TimedRotatingFileHandler" title="Link to this definition">¶</a></dt>
  531. <dd><p>Returns a new instance of the <a class="reference internal" href="#logging.handlers.TimedRotatingFileHandler" title="logging.handlers.TimedRotatingFileHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">TimedRotatingFileHandler</span></code></a> class. The
  532. specified file is opened and used as the stream for logging. On rotating it also
  533. sets the filename suffix. Rotating happens based on the product of <em>when</em> and
  534. <em>interval</em>.</p>
  535. <p>You can use the <em>when</em> to specify the type of <em>interval</em>. The list of possible
  536. values is below. Note that they are not case sensitive.</p>
  537. <table class="docutils align-default">
  538. <thead>
  539. <tr class="row-odd"><th class="head"><p>Value</p></th>
  540. <th class="head"><p>Type of interval</p></th>
  541. <th class="head"><p>If/how <em>atTime</em> is used</p></th>
  542. </tr>
  543. </thead>
  544. <tbody>
  545. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'S'</span></code></p></td>
  546. <td><p>Seconds</p></td>
  547. <td><p>Ignored</p></td>
  548. </tr>
  549. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'M'</span></code></p></td>
  550. <td><p>Minutes</p></td>
  551. <td><p>Ignored</p></td>
  552. </tr>
  553. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'H'</span></code></p></td>
  554. <td><p>Hours</p></td>
  555. <td><p>Ignored</p></td>
  556. </tr>
  557. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'D'</span></code></p></td>
  558. <td><p>Days</p></td>
  559. <td><p>Ignored</p></td>
  560. </tr>
  561. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">'W0'-'W6'</span></code></p></td>
  562. <td><p>Weekday (0=Monday)</p></td>
  563. <td><p>Used to compute initial
  564. rollover time</p></td>
  565. </tr>
  566. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">'midnight'</span></code></p></td>
  567. <td><p>Roll over at midnight, if
  568. <em>atTime</em> not specified,
  569. else at time <em>atTime</em></p></td>
  570. <td><p>Used to compute initial
  571. rollover time</p></td>
  572. </tr>
  573. </tbody>
  574. </table>
  575. <p>When using weekday-based rotation, specify ‘W0’ for Monday, ‘W1’ for
  576. Tuesday, and so on up to ‘W6’ for Sunday. In this case, the value passed for
  577. <em>interval</em> isn’t used.</p>
  578. <p>The system will save old log files by appending extensions to the filename.
  579. The extensions are date-and-time based, using the strftime format
  580. <code class="docutils literal notranslate"><span class="pre">%Y-%m-%d_%H-%M-%S</span></code> or a leading portion thereof, depending on the
  581. rollover interval.</p>
  582. <p>When computing the next rollover time for the first time (when the handler
  583. is created), the last modification time of an existing log file, or else
  584. the current time, is used to compute when the next rotation will occur.</p>
  585. <p>If the <em>utc</em> argument is true, times in UTC will be used; otherwise
  586. local time is used.</p>
  587. <p>If <em>backupCount</em> is nonzero, at most <em>backupCount</em> files
  588. will be kept, and if more would be created when rollover occurs, the oldest
  589. one is deleted. The deletion logic uses the interval to determine which
  590. files to delete, so changing the interval may leave old files lying around.</p>
  591. <p>If <em>delay</em> is true, then file opening is deferred until the first call to
  592. <a class="reference internal" href="#logging.handlers.TimedRotatingFileHandler.emit" title="logging.handlers.TimedRotatingFileHandler.emit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">emit()</span></code></a>.</p>
  593. <p>If <em>atTime</em> is not <code class="docutils literal notranslate"><span class="pre">None</span></code>, it must be a <code class="docutils literal notranslate"><span class="pre">datetime.time</span></code> instance which
  594. specifies the time of day when rollover occurs, for the cases where rollover
  595. is set to happen “at midnight” or “on a particular weekday”. Note that in
  596. these cases, the <em>atTime</em> value is effectively used to compute the <em>initial</em>
  597. rollover, and subsequent rollovers would be calculated via the normal
  598. interval calculation.</p>
  599. <p>If <em>errors</em> is specified, it’s used to determine how encoding errors are
  600. handled.</p>
  601. <div class="admonition note">
  602. <p class="admonition-title">Note</p>
  603. <p>Calculation of the initial rollover time is done when the handler
  604. is initialised. Calculation of subsequent rollover times is done only
  605. when rollover occurs, and rollover occurs only when emitting output. If
  606. this is not kept in mind, it might lead to some confusion. For example,
  607. if an interval of “every minute” is set, that does not mean you will
  608. always see log files with times (in the filename) separated by a minute;
  609. if, during application execution, logging output is generated more
  610. frequently than once a minute, <em>then</em> you can expect to see log files
  611. with times separated by a minute. If, on the other hand, logging messages
  612. are only output once every five minutes (say), then there will be gaps in
  613. the file times corresponding to the minutes where no output (and hence no
  614. rollover) occurred.</p>
  615. </div>
  616. <div class="versionchanged">
  617. <p><span class="versionmodified changed">Changed in version 3.4: </span><em>atTime</em> parameter was added.</p>
  618. </div>
  619. <div class="versionchanged">
  620. <p><span class="versionmodified changed">Changed in version 3.6: </span>As well as string values, <a class="reference internal" href="pathlib.html#pathlib.Path" title="pathlib.Path"><code class="xref py py-class docutils literal notranslate"><span class="pre">Path</span></code></a> objects are also accepted
  621. for the <em>filename</em> argument.</p>
  622. </div>
  623. <div class="versionchanged">
  624. <p><span class="versionmodified changed">Changed in version 3.9: </span>The <em>errors</em> parameter was added.</p>
  625. </div>
  626. <dl class="py method">
  627. <dt class="sig sig-object py" id="logging.handlers.TimedRotatingFileHandler.doRollover">
  628. <span class="sig-name descname"><span class="pre">doRollover</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.TimedRotatingFileHandler.doRollover" title="Link to this definition">¶</a></dt>
  629. <dd><p>Does a rollover, as described above.</p>
  630. </dd></dl>
  631. <dl class="py method">
  632. <dt class="sig sig-object py" id="logging.handlers.TimedRotatingFileHandler.emit">
  633. <span class="sig-name descname"><span class="pre">emit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.TimedRotatingFileHandler.emit" title="Link to this definition">¶</a></dt>
  634. <dd><p>Outputs the record to the file, catering for rollover as described above.</p>
  635. </dd></dl>
  636. <dl class="py method">
  637. <dt class="sig sig-object py" id="logging.handlers.TimedRotatingFileHandler.getFilesToDelete">
  638. <span class="sig-name descname"><span class="pre">getFilesToDelete</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.TimedRotatingFileHandler.getFilesToDelete" title="Link to this definition">¶</a></dt>
  639. <dd><p>Returns a list of filenames which should be deleted as part of rollover. These
  640. are the absolute paths of the oldest backup log files written by the handler.</p>
  641. </dd></dl>
  642. </dd></dl>
  643. </section>
  644. <section id="sockethandler">
  645. <span id="socket-handler"></span><h2>SocketHandler<a class="headerlink" href="#sockethandler" title="Link to this heading">¶</a></h2>
  646. <p>The <a class="reference internal" href="#logging.handlers.SocketHandler" title="logging.handlers.SocketHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SocketHandler</span></code></a> class, located in the <a class="reference internal" href="#module-logging.handlers" title="logging.handlers: Handlers for the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code></a> module,
  647. sends logging output to a network socket. The base class uses a TCP socket.</p>
  648. <dl class="py class">
  649. <dt class="sig sig-object py" id="logging.handlers.SocketHandler">
  650. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.handlers.</span></span><span class="sig-name descname"><span class="pre">SocketHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">host</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">port</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.SocketHandler" title="Link to this definition">¶</a></dt>
  651. <dd><p>Returns a new instance of the <a class="reference internal" href="#logging.handlers.SocketHandler" title="logging.handlers.SocketHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SocketHandler</span></code></a> class intended to
  652. communicate with a remote machine whose address is given by <em>host</em> and <em>port</em>.</p>
  653. <div class="versionchanged">
  654. <p><span class="versionmodified changed">Changed in version 3.4: </span>If <code class="docutils literal notranslate"><span class="pre">port</span></code> is specified as <code class="docutils literal notranslate"><span class="pre">None</span></code>, a Unix domain socket is created
  655. using the value in <code class="docutils literal notranslate"><span class="pre">host</span></code> - otherwise, a TCP socket is created.</p>
  656. </div>
  657. <dl class="py method">
  658. <dt class="sig sig-object py" id="logging.handlers.SocketHandler.close">
  659. <span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.SocketHandler.close" title="Link to this definition">¶</a></dt>
  660. <dd><p>Closes the socket.</p>
  661. </dd></dl>
  662. <dl class="py method">
  663. <dt class="sig sig-object py" id="logging.handlers.SocketHandler.emit">
  664. <span class="sig-name descname"><span class="pre">emit</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.SocketHandler.emit" title="Link to this definition">¶</a></dt>
  665. <dd><p>Pickles the record’s attribute dictionary and writes it to the socket in
  666. binary format. If there is an error with the socket, silently drops the
  667. packet. If the connection was previously lost, re-establishes the
  668. connection. To unpickle the record at the receiving end into a
  669. <a class="reference internal" href="logging.html#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a>, use the <a class="reference internal" href="logging.html#logging.makeLogRecord" title="logging.makeLogRecord"><code class="xref py py-func docutils literal notranslate"><span class="pre">makeLogRecord()</span></code></a>
  670. function.</p>
  671. </dd></dl>
  672. <dl class="py method">
  673. <dt class="sig sig-object py" id="logging.handlers.SocketHandler.handleError">
  674. <span class="sig-name descname"><span class="pre">handleError</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.SocketHandler.handleError" title="Link to this definition">¶</a></dt>
  675. <dd><p>Handles an error which has occurred during <a class="reference internal" href="#logging.handlers.SocketHandler.emit" title="logging.handlers.SocketHandler.emit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">emit()</span></code></a>. The most likely
  676. cause is a lost connection. Closes the socket so that we can retry on the
  677. next event.</p>
  678. </dd></dl>
  679. <dl class="py method">
  680. <dt class="sig sig-object py" id="logging.handlers.SocketHandler.makeSocket">
  681. <span class="sig-name descname"><span class="pre">makeSocket</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.SocketHandler.makeSocket" title="Link to this definition">¶</a></dt>
  682. <dd><p>This is a factory method which allows subclasses to define the precise
  683. type of socket they want. The default implementation creates a TCP socket
  684. (<a class="reference internal" href="socket.html#socket.SOCK_STREAM" title="socket.SOCK_STREAM"><code class="xref py py-const docutils literal notranslate"><span class="pre">socket.SOCK_STREAM</span></code></a>).</p>
  685. </dd></dl>
  686. <dl class="py method">
  687. <dt class="sig sig-object py" id="logging.handlers.SocketHandler.makePickle">
  688. <span class="sig-name descname"><span class="pre">makePickle</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.SocketHandler.makePickle" title="Link to this definition">¶</a></dt>
  689. <dd><p>Pickles the record’s attribute dictionary in binary format with a length
  690. prefix, and returns it ready for transmission across the socket. The
  691. details of this operation are equivalent to:</p>
  692. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">data</span> <span class="o">=</span> <span class="n">pickle</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">record_attr_dict</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
  693. <span class="n">datalen</span> <span class="o">=</span> <span class="n">struct</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="s1">&#39;&gt;L&#39;</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">))</span>
  694. <span class="k">return</span> <span class="n">datalen</span> <span class="o">+</span> <span class="n">data</span>
  695. </pre></div>
  696. </div>
  697. <p>Note that pickles aren’t completely secure. If you are concerned about
  698. security, you may want to override this method to implement a more secure
  699. mechanism. For example, you can sign pickles using HMAC and then verify
  700. them on the receiving end, or alternatively you can disable unpickling of
  701. global objects on the receiving end.</p>
  702. </dd></dl>
  703. <dl class="py method">
  704. <dt class="sig sig-object py" id="logging.handlers.SocketHandler.send">
  705. <span class="sig-name descname"><span class="pre">send</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">packet</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.SocketHandler.send" title="Link to this definition">¶</a></dt>
  706. <dd><p>Send a pickled byte-string <em>packet</em> to the socket. The format of the sent
  707. byte-string is as described in the documentation for
  708. <a class="reference internal" href="#logging.handlers.SocketHandler.makePickle" title="logging.handlers.SocketHandler.makePickle"><code class="xref py py-meth docutils literal notranslate"><span class="pre">makePickle()</span></code></a>.</p>
  709. <p>This function allows for partial sends, which can happen when the network
  710. is busy.</p>
  711. </dd></dl>
  712. <dl class="py method">
  713. <dt class="sig sig-object py" id="logging.handlers.SocketHandler.createSocket">
  714. <span class="sig-name descname"><span class="pre">createSocket</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.SocketHandler.createSocket" title="Link to this definition">¶</a></dt>
  715. <dd><p>Tries to create a socket; on failure, uses an exponential back-off
  716. algorithm. On initial failure, the handler will drop the message it was
  717. trying to send. When subsequent messages are handled by the same
  718. instance, it will not try connecting until some time has passed. The
  719. default parameters are such that the initial delay is one second, and if
  720. after that delay the connection still can’t be made, the handler will
  721. double the delay each time up to a maximum of 30 seconds.</p>
  722. <p>This behaviour is controlled by the following handler attributes:</p>
  723. <ul class="simple">
  724. <li><p><code class="docutils literal notranslate"><span class="pre">retryStart</span></code> (initial delay, defaulting to 1.0 seconds).</p></li>
  725. <li><p><code class="docutils literal notranslate"><span class="pre">retryFactor</span></code> (multiplier, defaulting to 2.0).</p></li>
  726. <li><p><code class="docutils literal notranslate"><span class="pre">retryMax</span></code> (maximum delay, defaulting to 30.0 seconds).</p></li>
  727. </ul>
  728. <p>This means that if the remote listener starts up <em>after</em> the handler has
  729. been used, you could lose messages (since the handler won’t even attempt
  730. a connection until the delay has elapsed, but just silently drop messages
  731. during the delay period).</p>
  732. </dd></dl>
  733. </dd></dl>
  734. </section>
  735. <section id="datagramhandler">
  736. <span id="datagram-handler"></span><h2>DatagramHandler<a class="headerlink" href="#datagramhandler" title="Link to this heading">¶</a></h2>
  737. <p>The <a class="reference internal" href="#logging.handlers.DatagramHandler" title="logging.handlers.DatagramHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">DatagramHandler</span></code></a> class, located in the <a class="reference internal" href="#module-logging.handlers" title="logging.handlers: Handlers for the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code></a>
  738. module, inherits from <a class="reference internal" href="#logging.handlers.SocketHandler" title="logging.handlers.SocketHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SocketHandler</span></code></a> to support sending logging messages
  739. over UDP sockets.</p>
  740. <dl class="py class">
  741. <dt class="sig sig-object py" id="logging.handlers.DatagramHandler">
  742. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.handlers.</span></span><span class="sig-name descname"><span class="pre">DatagramHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">host</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">port</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.DatagramHandler" title="Link to this definition">¶</a></dt>
  743. <dd><p>Returns a new instance of the <a class="reference internal" href="#logging.handlers.DatagramHandler" title="logging.handlers.DatagramHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">DatagramHandler</span></code></a> class intended to
  744. communicate with a remote machine whose address is given by <em>host</em> and <em>port</em>.</p>
  745. <div class="admonition note">
  746. <p class="admonition-title">Note</p>
  747. <p>As UDP is not a streaming protocol, there is no persistent connection
  748. between an instance of this handler and <em>host</em>. For this reason, when using a
  749. network socket, a DNS lookup might have to be made each time an event is
  750. logged, which can introduce some latency into the system. If this affects you,
  751. you can do a lookup yourself and initialize this handler using the looked-up IP
  752. address rather than the hostname.</p>
  753. </div>
  754. <div class="versionchanged">
  755. <p><span class="versionmodified changed">Changed in version 3.4: </span>If <code class="docutils literal notranslate"><span class="pre">port</span></code> is specified as <code class="docutils literal notranslate"><span class="pre">None</span></code>, a Unix domain socket is created
  756. using the value in <code class="docutils literal notranslate"><span class="pre">host</span></code> - otherwise, a UDP socket is created.</p>
  757. </div>
  758. <dl class="py method">
  759. <dt class="sig sig-object py" id="logging.handlers.DatagramHandler.emit">
  760. <span class="sig-name descname"><span class="pre">emit</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.DatagramHandler.emit" title="Link to this definition">¶</a></dt>
  761. <dd><p>Pickles the record’s attribute dictionary and writes it to the socket in
  762. binary format. If there is an error with the socket, silently drops the
  763. packet. To unpickle the record at the receiving end into a
  764. <a class="reference internal" href="logging.html#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a>, use the <a class="reference internal" href="logging.html#logging.makeLogRecord" title="logging.makeLogRecord"><code class="xref py py-func docutils literal notranslate"><span class="pre">makeLogRecord()</span></code></a>
  765. function.</p>
  766. </dd></dl>
  767. <dl class="py method">
  768. <dt class="sig sig-object py" id="logging.handlers.DatagramHandler.makeSocket">
  769. <span class="sig-name descname"><span class="pre">makeSocket</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.DatagramHandler.makeSocket" title="Link to this definition">¶</a></dt>
  770. <dd><p>The factory method of <a class="reference internal" href="#logging.handlers.SocketHandler" title="logging.handlers.SocketHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SocketHandler</span></code></a> is here overridden to create
  771. a UDP socket (<a class="reference internal" href="socket.html#socket.SOCK_DGRAM" title="socket.SOCK_DGRAM"><code class="xref py py-const docutils literal notranslate"><span class="pre">socket.SOCK_DGRAM</span></code></a>).</p>
  772. </dd></dl>
  773. <dl class="py method">
  774. <dt class="sig sig-object py" id="logging.handlers.DatagramHandler.send">
  775. <span class="sig-name descname"><span class="pre">send</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">s</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.DatagramHandler.send" title="Link to this definition">¶</a></dt>
  776. <dd><p>Send a pickled byte-string to a socket. The format of the sent byte-string
  777. is as described in the documentation for <a class="reference internal" href="#logging.handlers.SocketHandler.makePickle" title="logging.handlers.SocketHandler.makePickle"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SocketHandler.makePickle()</span></code></a>.</p>
  778. </dd></dl>
  779. </dd></dl>
  780. </section>
  781. <section id="sysloghandler">
  782. <span id="syslog-handler"></span><h2>SysLogHandler<a class="headerlink" href="#sysloghandler" title="Link to this heading">¶</a></h2>
  783. <p>The <a class="reference internal" href="#logging.handlers.SysLogHandler" title="logging.handlers.SysLogHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SysLogHandler</span></code></a> class, located in the <a class="reference internal" href="#module-logging.handlers" title="logging.handlers: Handlers for the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code></a> module,
  784. supports sending logging messages to a remote or local Unix syslog.</p>
  785. <dl class="py class">
  786. <dt class="sig sig-object py" id="logging.handlers.SysLogHandler">
  787. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.handlers.</span></span><span class="sig-name descname"><span class="pre">SysLogHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">address</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">('localhost',</span> <span class="pre">SYSLOG_UDP_PORT)</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">facility</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">LOG_USER</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">socktype</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">socket.SOCK_DGRAM</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.SysLogHandler" title="Link to this definition">¶</a></dt>
  788. <dd><p>Returns a new instance of the <a class="reference internal" href="#logging.handlers.SysLogHandler" title="logging.handlers.SysLogHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SysLogHandler</span></code></a> class intended to
  789. communicate with a remote Unix machine whose address is given by <em>address</em> in
  790. the form of a <code class="docutils literal notranslate"><span class="pre">(host,</span> <span class="pre">port)</span></code> tuple. If <em>address</em> is not specified,
  791. <code class="docutils literal notranslate"><span class="pre">('localhost',</span> <span class="pre">514)</span></code> is used. The address is used to open a socket. An
  792. alternative to providing a <code class="docutils literal notranslate"><span class="pre">(host,</span> <span class="pre">port)</span></code> tuple is providing an address as a
  793. string, for example ‘/dev/log’. In this case, a Unix domain socket is used to
  794. send the message to the syslog. If <em>facility</em> is not specified,
  795. <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_USER</span></code> is used. The type of socket opened depends on the
  796. <em>socktype</em> argument, which defaults to <a class="reference internal" href="socket.html#socket.SOCK_DGRAM" title="socket.SOCK_DGRAM"><code class="xref py py-const docutils literal notranslate"><span class="pre">socket.SOCK_DGRAM</span></code></a> and thus
  797. opens a UDP socket. To open a TCP socket (for use with the newer syslog
  798. daemons such as rsyslog), specify a value of <a class="reference internal" href="socket.html#socket.SOCK_STREAM" title="socket.SOCK_STREAM"><code class="xref py py-const docutils literal notranslate"><span class="pre">socket.SOCK_STREAM</span></code></a>.</p>
  799. <p>Note that if your server is not listening on UDP port 514,
  800. <a class="reference internal" href="#logging.handlers.SysLogHandler" title="logging.handlers.SysLogHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SysLogHandler</span></code></a> may appear not to work. In that case, check what
  801. address you should be using for a domain socket - it’s system dependent.
  802. For example, on Linux it’s usually ‘/dev/log’ but on OS/X it’s
  803. ‘/var/run/syslog’. You’ll need to check your platform and use the
  804. appropriate address (you may need to do this check at runtime if your
  805. application needs to run on several platforms). On Windows, you pretty
  806. much have to use the UDP option.</p>
  807. <div class="admonition note">
  808. <p class="admonition-title">Note</p>
  809. <p>On macOS 12.x (Monterey), Apple has changed the behaviour of their
  810. syslog daemon - it no longer listens on a domain socket. Therefore, you cannot
  811. expect <a class="reference internal" href="#logging.handlers.SysLogHandler" title="logging.handlers.SysLogHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SysLogHandler</span></code></a> to work on this system.</p>
  812. <p>See <a class="reference external" href="https://github.com/python/cpython/issues/91070">gh-91070</a> for more information.</p>
  813. </div>
  814. <div class="versionchanged">
  815. <p><span class="versionmodified changed">Changed in version 3.2: </span><em>socktype</em> was added.</p>
  816. </div>
  817. <dl class="py method">
  818. <dt class="sig sig-object py" id="logging.handlers.SysLogHandler.close">
  819. <span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.SysLogHandler.close" title="Link to this definition">¶</a></dt>
  820. <dd><p>Closes the socket to the remote host.</p>
  821. </dd></dl>
  822. <dl class="py method">
  823. <dt class="sig sig-object py" id="logging.handlers.SysLogHandler.createSocket">
  824. <span class="sig-name descname"><span class="pre">createSocket</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.SysLogHandler.createSocket" title="Link to this definition">¶</a></dt>
  825. <dd><p>Tries to create a socket and, if it’s not a datagram socket, connect it
  826. to the other end. This method is called during handler initialization,
  827. but it’s not regarded as an error if the other end isn’t listening at
  828. this point - the method will be called again when emitting an event, if
  829. there is no socket at that point.</p>
  830. <div class="versionadded">
  831. <p><span class="versionmodified added">New in version 3.11.</span></p>
  832. </div>
  833. </dd></dl>
  834. <dl class="py method">
  835. <dt class="sig sig-object py" id="logging.handlers.SysLogHandler.emit">
  836. <span class="sig-name descname"><span class="pre">emit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.SysLogHandler.emit" title="Link to this definition">¶</a></dt>
  837. <dd><p>The record is formatted, and then sent to the syslog server. If exception
  838. information is present, it is <em>not</em> sent to the server.</p>
  839. <div class="versionchanged">
  840. <p><span class="versionmodified changed">Changed in version 3.2.1: </span>(See: <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12168">bpo-12168</a>.) In earlier versions, the message sent to the
  841. syslog daemons was always terminated with a NUL byte, because early
  842. versions of these daemons expected a NUL terminated message - even
  843. though it’s not in the relevant specification (<span class="target" id="index-0"></span><a class="rfc reference external" href="https://datatracker.ietf.org/doc/html/rfc5424.html"><strong>RFC 5424</strong></a>). More recent
  844. versions of these daemons don’t expect the NUL byte but strip it off
  845. if it’s there, and even more recent daemons (which adhere more closely
  846. to RFC 5424) pass the NUL byte on as part of the message.</p>
  847. <p>To enable easier handling of syslog messages in the face of all these
  848. differing daemon behaviours, the appending of the NUL byte has been
  849. made configurable, through the use of a class-level attribute,
  850. <code class="docutils literal notranslate"><span class="pre">append_nul</span></code>. This defaults to <code class="docutils literal notranslate"><span class="pre">True</span></code> (preserving the existing
  851. behaviour) but can be set to <code class="docutils literal notranslate"><span class="pre">False</span></code> on a <code class="docutils literal notranslate"><span class="pre">SysLogHandler</span></code> instance
  852. in order for that instance to <em>not</em> append the NUL terminator.</p>
  853. </div>
  854. <div class="versionchanged">
  855. <p><span class="versionmodified changed">Changed in version 3.3: </span>(See: <a class="reference external" href="https://bugs.python.org/issue?&#64;action=redirect&amp;bpo=12419">bpo-12419</a>.) In earlier versions, there was no facility for
  856. an “ident” or “tag” prefix to identify the source of the message. This
  857. can now be specified using a class-level attribute, defaulting to
  858. <code class="docutils literal notranslate"><span class="pre">&quot;&quot;</span></code> to preserve existing behaviour, but which can be overridden on
  859. a <code class="docutils literal notranslate"><span class="pre">SysLogHandler</span></code> instance in order for that instance to prepend
  860. the ident to every message handled. Note that the provided ident must
  861. be text, not bytes, and is prepended to the message exactly as is.</p>
  862. </div>
  863. </dd></dl>
  864. <dl class="py method">
  865. <dt class="sig sig-object py" id="logging.handlers.SysLogHandler.encodePriority">
  866. <span class="sig-name descname"><span class="pre">encodePriority</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">facility</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">priority</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.SysLogHandler.encodePriority" title="Link to this definition">¶</a></dt>
  867. <dd><p>Encodes the facility and priority into an integer. You can pass in strings
  868. or integers - if strings are passed, internal mapping dictionaries are
  869. used to convert them to integers.</p>
  870. <p>The symbolic <code class="docutils literal notranslate"><span class="pre">LOG_</span></code> values are defined in <a class="reference internal" href="#logging.handlers.SysLogHandler" title="logging.handlers.SysLogHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SysLogHandler</span></code></a> and
  871. mirror the values defined in the <code class="docutils literal notranslate"><span class="pre">sys/syslog.h</span></code> header file.</p>
  872. <p><strong>Priorities</strong></p>
  873. <table class="docutils align-default">
  874. <thead>
  875. <tr class="row-odd"><th class="head"><p>Name (string)</p></th>
  876. <th class="head"><p>Symbolic value</p></th>
  877. </tr>
  878. </thead>
  879. <tbody>
  880. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">alert</span></code></p></td>
  881. <td><p>LOG_ALERT</p></td>
  882. </tr>
  883. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">crit</span></code> or <code class="docutils literal notranslate"><span class="pre">critical</span></code></p></td>
  884. <td><p>LOG_CRIT</p></td>
  885. </tr>
  886. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">debug</span></code></p></td>
  887. <td><p>LOG_DEBUG</p></td>
  888. </tr>
  889. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">emerg</span></code> or <code class="docutils literal notranslate"><span class="pre">panic</span></code></p></td>
  890. <td><p>LOG_EMERG</p></td>
  891. </tr>
  892. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">err</span></code> or <code class="docutils literal notranslate"><span class="pre">error</span></code></p></td>
  893. <td><p>LOG_ERR</p></td>
  894. </tr>
  895. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">info</span></code></p></td>
  896. <td><p>LOG_INFO</p></td>
  897. </tr>
  898. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">notice</span></code></p></td>
  899. <td><p>LOG_NOTICE</p></td>
  900. </tr>
  901. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">warn</span></code> or <code class="docutils literal notranslate"><span class="pre">warning</span></code></p></td>
  902. <td><p>LOG_WARNING</p></td>
  903. </tr>
  904. </tbody>
  905. </table>
  906. <p><strong>Facilities</strong></p>
  907. <table class="docutils align-default">
  908. <thead>
  909. <tr class="row-odd"><th class="head"><p>Name (string)</p></th>
  910. <th class="head"><p>Symbolic value</p></th>
  911. </tr>
  912. </thead>
  913. <tbody>
  914. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">auth</span></code></p></td>
  915. <td><p>LOG_AUTH</p></td>
  916. </tr>
  917. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">authpriv</span></code></p></td>
  918. <td><p>LOG_AUTHPRIV</p></td>
  919. </tr>
  920. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">cron</span></code></p></td>
  921. <td><p>LOG_CRON</p></td>
  922. </tr>
  923. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">daemon</span></code></p></td>
  924. <td><p>LOG_DAEMON</p></td>
  925. </tr>
  926. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">ftp</span></code></p></td>
  927. <td><p>LOG_FTP</p></td>
  928. </tr>
  929. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">kern</span></code></p></td>
  930. <td><p>LOG_KERN</p></td>
  931. </tr>
  932. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">lpr</span></code></p></td>
  933. <td><p>LOG_LPR</p></td>
  934. </tr>
  935. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">mail</span></code></p></td>
  936. <td><p>LOG_MAIL</p></td>
  937. </tr>
  938. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">news</span></code></p></td>
  939. <td><p>LOG_NEWS</p></td>
  940. </tr>
  941. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">syslog</span></code></p></td>
  942. <td><p>LOG_SYSLOG</p></td>
  943. </tr>
  944. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">user</span></code></p></td>
  945. <td><p>LOG_USER</p></td>
  946. </tr>
  947. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">uucp</span></code></p></td>
  948. <td><p>LOG_UUCP</p></td>
  949. </tr>
  950. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">local0</span></code></p></td>
  951. <td><p>LOG_LOCAL0</p></td>
  952. </tr>
  953. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">local1</span></code></p></td>
  954. <td><p>LOG_LOCAL1</p></td>
  955. </tr>
  956. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">local2</span></code></p></td>
  957. <td><p>LOG_LOCAL2</p></td>
  958. </tr>
  959. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">local3</span></code></p></td>
  960. <td><p>LOG_LOCAL3</p></td>
  961. </tr>
  962. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">local4</span></code></p></td>
  963. <td><p>LOG_LOCAL4</p></td>
  964. </tr>
  965. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">local5</span></code></p></td>
  966. <td><p>LOG_LOCAL5</p></td>
  967. </tr>
  968. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">local6</span></code></p></td>
  969. <td><p>LOG_LOCAL6</p></td>
  970. </tr>
  971. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">local7</span></code></p></td>
  972. <td><p>LOG_LOCAL7</p></td>
  973. </tr>
  974. </tbody>
  975. </table>
  976. </dd></dl>
  977. <dl class="py method">
  978. <dt class="sig sig-object py" id="logging.handlers.SysLogHandler.mapPriority">
  979. <span class="sig-name descname"><span class="pre">mapPriority</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">levelname</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.SysLogHandler.mapPriority" title="Link to this definition">¶</a></dt>
  980. <dd><p>Maps a logging level name to a syslog priority name.
  981. You may need to override this if you are using custom levels, or
  982. if the default algorithm is not suitable for your needs. The
  983. default algorithm maps <code class="docutils literal notranslate"><span class="pre">DEBUG</span></code>, <code class="docutils literal notranslate"><span class="pre">INFO</span></code>, <code class="docutils literal notranslate"><span class="pre">WARNING</span></code>, <code class="docutils literal notranslate"><span class="pre">ERROR</span></code> and
  984. <code class="docutils literal notranslate"><span class="pre">CRITICAL</span></code> to the equivalent syslog names, and all other level
  985. names to ‘warning’.</p>
  986. </dd></dl>
  987. </dd></dl>
  988. </section>
  989. <section id="nteventloghandler">
  990. <span id="nt-eventlog-handler"></span><h2>NTEventLogHandler<a class="headerlink" href="#nteventloghandler" title="Link to this heading">¶</a></h2>
  991. <p>The <a class="reference internal" href="#logging.handlers.NTEventLogHandler" title="logging.handlers.NTEventLogHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">NTEventLogHandler</span></code></a> class, located in the <a class="reference internal" href="#module-logging.handlers" title="logging.handlers: Handlers for the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code></a>
  992. module, supports sending logging messages to a local Windows NT, Windows 2000 or
  993. Windows XP event log. Before you can use it, you need Mark Hammond’s Win32
  994. extensions for Python installed.</p>
  995. <dl class="py class">
  996. <dt class="sig sig-object py" id="logging.handlers.NTEventLogHandler">
  997. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.handlers.</span></span><span class="sig-name descname"><span class="pre">NTEventLogHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">appname</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dllname</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">logtype</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'Application'</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.NTEventLogHandler" title="Link to this definition">¶</a></dt>
  998. <dd><p>Returns a new instance of the <a class="reference internal" href="#logging.handlers.NTEventLogHandler" title="logging.handlers.NTEventLogHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">NTEventLogHandler</span></code></a> class. The <em>appname</em> is
  999. used to define the application name as it appears in the event log. An
  1000. appropriate registry entry is created using this name. The <em>dllname</em> should give
  1001. the fully qualified pathname of a .dll or .exe which contains message
  1002. definitions to hold in the log (if not specified, <code class="docutils literal notranslate"><span class="pre">'win32service.pyd'</span></code> is used
  1003. - this is installed with the Win32 extensions and contains some basic
  1004. placeholder message definitions. Note that use of these placeholders will make
  1005. your event logs big, as the entire message source is held in the log. If you
  1006. want slimmer logs, you have to pass in the name of your own .dll or .exe which
  1007. contains the message definitions you want to use in the event log). The
  1008. <em>logtype</em> is one of <code class="docutils literal notranslate"><span class="pre">'Application'</span></code>, <code class="docutils literal notranslate"><span class="pre">'System'</span></code> or <code class="docutils literal notranslate"><span class="pre">'Security'</span></code>, and
  1009. defaults to <code class="docutils literal notranslate"><span class="pre">'Application'</span></code>.</p>
  1010. <dl class="py method">
  1011. <dt class="sig sig-object py" id="logging.handlers.NTEventLogHandler.close">
  1012. <span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.NTEventLogHandler.close" title="Link to this definition">¶</a></dt>
  1013. <dd><p>At this point, you can remove the application name from the registry as a
  1014. source of event log entries. However, if you do this, you will not be able
  1015. to see the events as you intended in the Event Log Viewer - it needs to be
  1016. able to access the registry to get the .dll name. The current version does
  1017. not do this.</p>
  1018. </dd></dl>
  1019. <dl class="py method">
  1020. <dt class="sig sig-object py" id="logging.handlers.NTEventLogHandler.emit">
  1021. <span class="sig-name descname"><span class="pre">emit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.NTEventLogHandler.emit" title="Link to this definition">¶</a></dt>
  1022. <dd><p>Determines the message ID, event category and event type, and then logs
  1023. the message in the NT event log.</p>
  1024. </dd></dl>
  1025. <dl class="py method">
  1026. <dt class="sig sig-object py" id="logging.handlers.NTEventLogHandler.getEventCategory">
  1027. <span class="sig-name descname"><span class="pre">getEventCategory</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.NTEventLogHandler.getEventCategory" title="Link to this definition">¶</a></dt>
  1028. <dd><p>Returns the event category for the record. Override this if you want to
  1029. specify your own categories. This version returns 0.</p>
  1030. </dd></dl>
  1031. <dl class="py method">
  1032. <dt class="sig sig-object py" id="logging.handlers.NTEventLogHandler.getEventType">
  1033. <span class="sig-name descname"><span class="pre">getEventType</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.NTEventLogHandler.getEventType" title="Link to this definition">¶</a></dt>
  1034. <dd><p>Returns the event type for the record. Override this if you want to
  1035. specify your own types. This version does a mapping using the handler’s
  1036. typemap attribute, which is set up in <code class="xref py py-meth docutils literal notranslate"><span class="pre">__init__()</span></code> to a dictionary
  1037. which contains mappings for <code class="xref py py-const docutils literal notranslate"><span class="pre">DEBUG</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">INFO</span></code>,
  1038. <code class="xref py py-const docutils literal notranslate"><span class="pre">WARNING</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">ERROR</span></code> and <code class="xref py py-const docutils literal notranslate"><span class="pre">CRITICAL</span></code>. If you are using
  1039. your own levels, you will either need to override this method or place a
  1040. suitable dictionary in the handler’s <em>typemap</em> attribute.</p>
  1041. </dd></dl>
  1042. <dl class="py method">
  1043. <dt class="sig sig-object py" id="logging.handlers.NTEventLogHandler.getMessageID">
  1044. <span class="sig-name descname"><span class="pre">getMessageID</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.NTEventLogHandler.getMessageID" title="Link to this definition">¶</a></dt>
  1045. <dd><p>Returns the message ID for the record. If you are using your own messages,
  1046. you could do this by having the <em>msg</em> passed to the logger being an ID
  1047. rather than a format string. Then, in here, you could use a dictionary
  1048. lookup to get the message ID. This version returns 1, which is the base
  1049. message ID in <code class="file docutils literal notranslate"><span class="pre">win32service.pyd</span></code>.</p>
  1050. </dd></dl>
  1051. </dd></dl>
  1052. </section>
  1053. <section id="smtphandler">
  1054. <span id="smtp-handler"></span><h2>SMTPHandler<a class="headerlink" href="#smtphandler" title="Link to this heading">¶</a></h2>
  1055. <p>The <a class="reference internal" href="#logging.handlers.SMTPHandler" title="logging.handlers.SMTPHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPHandler</span></code></a> class, located in the <a class="reference internal" href="#module-logging.handlers" title="logging.handlers: Handlers for the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code></a> module,
  1056. supports sending logging messages to an email address via SMTP.</p>
  1057. <dl class="py class">
  1058. <dt class="sig sig-object py" id="logging.handlers.SMTPHandler">
  1059. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.handlers.</span></span><span class="sig-name descname"><span class="pre">SMTPHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mailhost</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fromaddr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">toaddrs</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">subject</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">credentials</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">secure</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">timeout</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1.0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.SMTPHandler" title="Link to this definition">¶</a></dt>
  1060. <dd><p>Returns a new instance of the <a class="reference internal" href="#logging.handlers.SMTPHandler" title="logging.handlers.SMTPHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPHandler</span></code></a> class. The instance is
  1061. initialized with the from and to addresses and subject line of the email. The
  1062. <em>toaddrs</em> should be a list of strings. To specify a non-standard SMTP port, use
  1063. the (host, port) tuple format for the <em>mailhost</em> argument. If you use a string,
  1064. the standard SMTP port is used. If your SMTP server requires authentication, you
  1065. can specify a (username, password) tuple for the <em>credentials</em> argument.</p>
  1066. <p>To specify the use of a secure protocol (TLS), pass in a tuple to the
  1067. <em>secure</em> argument. This will only be used when authentication credentials are
  1068. supplied. The tuple should be either an empty tuple, or a single-value tuple
  1069. with the name of a keyfile, or a 2-value tuple with the names of the keyfile
  1070. and certificate file. (This tuple is passed to the
  1071. <a class="reference internal" href="smtplib.html#smtplib.SMTP.starttls" title="smtplib.SMTP.starttls"><code class="xref py py-meth docutils literal notranslate"><span class="pre">smtplib.SMTP.starttls()</span></code></a> method.)</p>
  1072. <p>A timeout can be specified for communication with the SMTP server using the
  1073. <em>timeout</em> argument.</p>
  1074. <div class="versionchanged">
  1075. <p><span class="versionmodified changed">Changed in version 3.3: </span>Added the <em>timeout</em> parameter.</p>
  1076. </div>
  1077. <dl class="py method">
  1078. <dt class="sig sig-object py" id="logging.handlers.SMTPHandler.emit">
  1079. <span class="sig-name descname"><span class="pre">emit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.SMTPHandler.emit" title="Link to this definition">¶</a></dt>
  1080. <dd><p>Formats the record and sends it to the specified addressees.</p>
  1081. </dd></dl>
  1082. <dl class="py method">
  1083. <dt class="sig sig-object py" id="logging.handlers.SMTPHandler.getSubject">
  1084. <span class="sig-name descname"><span class="pre">getSubject</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.SMTPHandler.getSubject" title="Link to this definition">¶</a></dt>
  1085. <dd><p>If you want to specify a subject line which is record-dependent, override
  1086. this method.</p>
  1087. </dd></dl>
  1088. </dd></dl>
  1089. </section>
  1090. <section id="memoryhandler">
  1091. <span id="memory-handler"></span><h2>MemoryHandler<a class="headerlink" href="#memoryhandler" title="Link to this heading">¶</a></h2>
  1092. <p>The <a class="reference internal" href="#logging.handlers.MemoryHandler" title="logging.handlers.MemoryHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">MemoryHandler</span></code></a> class, located in the <a class="reference internal" href="#module-logging.handlers" title="logging.handlers: Handlers for the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code></a> module,
  1093. supports buffering of logging records in memory, periodically flushing them to a
  1094. <em class="dfn">target</em> handler. Flushing occurs whenever the buffer is full, or when an
  1095. event of a certain severity or greater is seen.</p>
  1096. <p><a class="reference internal" href="#logging.handlers.MemoryHandler" title="logging.handlers.MemoryHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">MemoryHandler</span></code></a> is a subclass of the more general
  1097. <a class="reference internal" href="#logging.handlers.BufferingHandler" title="logging.handlers.BufferingHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BufferingHandler</span></code></a>, which is an abstract class. This buffers logging
  1098. records in memory. Whenever each record is added to the buffer, a check is made
  1099. by calling <code class="xref py py-meth docutils literal notranslate"><span class="pre">shouldFlush()</span></code> to see if the buffer should be flushed. If it
  1100. should, then <code class="xref py py-meth docutils literal notranslate"><span class="pre">flush()</span></code> is expected to do the flushing.</p>
  1101. <dl class="py class">
  1102. <dt class="sig sig-object py" id="logging.handlers.BufferingHandler">
  1103. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.handlers.</span></span><span class="sig-name descname"><span class="pre">BufferingHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">capacity</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.BufferingHandler" title="Link to this definition">¶</a></dt>
  1104. <dd><p>Initializes the handler with a buffer of the specified capacity. Here,
  1105. <em>capacity</em> means the number of logging records buffered.</p>
  1106. <dl class="py method">
  1107. <dt class="sig sig-object py" id="logging.handlers.BufferingHandler.emit">
  1108. <span class="sig-name descname"><span class="pre">emit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.BufferingHandler.emit" title="Link to this definition">¶</a></dt>
  1109. <dd><p>Append the record to the buffer. If <a class="reference internal" href="#logging.handlers.BufferingHandler.shouldFlush" title="logging.handlers.BufferingHandler.shouldFlush"><code class="xref py py-meth docutils literal notranslate"><span class="pre">shouldFlush()</span></code></a> returns true,
  1110. call <a class="reference internal" href="#logging.handlers.BufferingHandler.flush" title="logging.handlers.BufferingHandler.flush"><code class="xref py py-meth docutils literal notranslate"><span class="pre">flush()</span></code></a> to process the buffer.</p>
  1111. </dd></dl>
  1112. <dl class="py method">
  1113. <dt class="sig sig-object py" id="logging.handlers.BufferingHandler.flush">
  1114. <span class="sig-name descname"><span class="pre">flush</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.BufferingHandler.flush" title="Link to this definition">¶</a></dt>
  1115. <dd><p>For a <a class="reference internal" href="#logging.handlers.BufferingHandler" title="logging.handlers.BufferingHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BufferingHandler</span></code></a> instance, flushing means that it sets the
  1116. buffer to an empty list. This method can be overwritten to implement more useful
  1117. flushing behavior.</p>
  1118. </dd></dl>
  1119. <dl class="py method">
  1120. <dt class="sig sig-object py" id="logging.handlers.BufferingHandler.shouldFlush">
  1121. <span class="sig-name descname"><span class="pre">shouldFlush</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.BufferingHandler.shouldFlush" title="Link to this definition">¶</a></dt>
  1122. <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the buffer is up to capacity. This method can be
  1123. overridden to implement custom flushing strategies.</p>
  1124. </dd></dl>
  1125. </dd></dl>
  1126. <dl class="py class">
  1127. <dt class="sig sig-object py" id="logging.handlers.MemoryHandler">
  1128. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.handlers.</span></span><span class="sig-name descname"><span class="pre">MemoryHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">capacity</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">flushLevel</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">ERROR</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">target</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">flushOnClose</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.MemoryHandler" title="Link to this definition">¶</a></dt>
  1129. <dd><p>Returns a new instance of the <a class="reference internal" href="#logging.handlers.MemoryHandler" title="logging.handlers.MemoryHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">MemoryHandler</span></code></a> class. The instance is
  1130. initialized with a buffer size of <em>capacity</em> (number of records buffered).
  1131. If <em>flushLevel</em> is not specified, <code class="xref py py-const docutils literal notranslate"><span class="pre">ERROR</span></code> is used. If no <em>target</em> is
  1132. specified, the target will need to be set using <a class="reference internal" href="#logging.handlers.MemoryHandler.setTarget" title="logging.handlers.MemoryHandler.setTarget"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setTarget()</span></code></a> before this
  1133. handler does anything useful. If <em>flushOnClose</em> is specified as <code class="docutils literal notranslate"><span class="pre">False</span></code>,
  1134. then the buffer is <em>not</em> flushed when the handler is closed. If not specified
  1135. or specified as <code class="docutils literal notranslate"><span class="pre">True</span></code>, the previous behaviour of flushing the buffer will
  1136. occur when the handler is closed.</p>
  1137. <div class="versionchanged">
  1138. <p><span class="versionmodified changed">Changed in version 3.6: </span>The <em>flushOnClose</em> parameter was added.</p>
  1139. </div>
  1140. <dl class="py method">
  1141. <dt class="sig sig-object py" id="logging.handlers.MemoryHandler.close">
  1142. <span class="sig-name descname"><span class="pre">close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.MemoryHandler.close" title="Link to this definition">¶</a></dt>
  1143. <dd><p>Calls <a class="reference internal" href="#logging.handlers.MemoryHandler.flush" title="logging.handlers.MemoryHandler.flush"><code class="xref py py-meth docutils literal notranslate"><span class="pre">flush()</span></code></a>, sets the target to <code class="docutils literal notranslate"><span class="pre">None</span></code> and clears the
  1144. buffer.</p>
  1145. </dd></dl>
  1146. <dl class="py method">
  1147. <dt class="sig sig-object py" id="logging.handlers.MemoryHandler.flush">
  1148. <span class="sig-name descname"><span class="pre">flush</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.MemoryHandler.flush" title="Link to this definition">¶</a></dt>
  1149. <dd><p>For a <a class="reference internal" href="#logging.handlers.MemoryHandler" title="logging.handlers.MemoryHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">MemoryHandler</span></code></a> instance, flushing means just sending the buffered
  1150. records to the target, if there is one. The buffer is also cleared when
  1151. buffered records are sent to the target. Override if you want different behavior.</p>
  1152. </dd></dl>
  1153. <dl class="py method">
  1154. <dt class="sig sig-object py" id="logging.handlers.MemoryHandler.setTarget">
  1155. <span class="sig-name descname"><span class="pre">setTarget</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">target</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.MemoryHandler.setTarget" title="Link to this definition">¶</a></dt>
  1156. <dd><p>Sets the target handler for this handler.</p>
  1157. </dd></dl>
  1158. <dl class="py method">
  1159. <dt class="sig sig-object py" id="logging.handlers.MemoryHandler.shouldFlush">
  1160. <span class="sig-name descname"><span class="pre">shouldFlush</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.MemoryHandler.shouldFlush" title="Link to this definition">¶</a></dt>
  1161. <dd><p>Checks for buffer full or a record at the <em>flushLevel</em> or higher.</p>
  1162. </dd></dl>
  1163. </dd></dl>
  1164. </section>
  1165. <section id="httphandler">
  1166. <span id="http-handler"></span><h2>HTTPHandler<a class="headerlink" href="#httphandler" title="Link to this heading">¶</a></h2>
  1167. <p>The <a class="reference internal" href="#logging.handlers.HTTPHandler" title="logging.handlers.HTTPHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPHandler</span></code></a> class, located in the <a class="reference internal" href="#module-logging.handlers" title="logging.handlers: Handlers for the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code></a> module,
  1168. supports sending logging messages to a web server, using either <code class="docutils literal notranslate"><span class="pre">GET</span></code> or
  1169. <code class="docutils literal notranslate"><span class="pre">POST</span></code> semantics.</p>
  1170. <dl class="py class">
  1171. <dt class="sig sig-object py" id="logging.handlers.HTTPHandler">
  1172. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.handlers.</span></span><span class="sig-name descname"><span class="pre">HTTPHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">host</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">url</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">method</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'GET'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">secure</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">credentials</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">context</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.HTTPHandler" title="Link to this definition">¶</a></dt>
  1173. <dd><p>Returns a new instance of the <a class="reference internal" href="#logging.handlers.HTTPHandler" title="logging.handlers.HTTPHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPHandler</span></code></a> class. The <em>host</em> can be
  1174. of the form <code class="docutils literal notranslate"><span class="pre">host:port</span></code>, should you need to use a specific port number. If
  1175. no <em>method</em> is specified, <code class="docutils literal notranslate"><span class="pre">GET</span></code> is used. If <em>secure</em> is true, a HTTPS
  1176. connection will be used. The <em>context</em> parameter may be set to a
  1177. <a class="reference internal" href="ssl.html#ssl.SSLContext" title="ssl.SSLContext"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a> instance to configure the SSL settings used for the
  1178. HTTPS connection. If <em>credentials</em> is specified, it should be a 2-tuple
  1179. consisting of userid and password, which will be placed in a HTTP
  1180. ‘Authorization’ header using Basic authentication. If you specify
  1181. credentials, you should also specify secure=True so that your userid and
  1182. password are not passed in cleartext across the wire.</p>
  1183. <div class="versionchanged">
  1184. <p><span class="versionmodified changed">Changed in version 3.5: </span>The <em>context</em> parameter was added.</p>
  1185. </div>
  1186. <dl class="py method">
  1187. <dt class="sig sig-object py" id="logging.handlers.HTTPHandler.mapLogRecord">
  1188. <span class="sig-name descname"><span class="pre">mapLogRecord</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.HTTPHandler.mapLogRecord" title="Link to this definition">¶</a></dt>
  1189. <dd><p>Provides a dictionary, based on <code class="docutils literal notranslate"><span class="pre">record</span></code>, which is to be URL-encoded
  1190. and sent to the web server. The default implementation just returns
  1191. <code class="docutils literal notranslate"><span class="pre">record.__dict__</span></code>. This method can be overridden if e.g. only a
  1192. subset of <a class="reference internal" href="logging.html#logging.LogRecord" title="logging.LogRecord"><code class="xref py py-class docutils literal notranslate"><span class="pre">LogRecord</span></code></a> is to be sent to the web server, or
  1193. if more specific customization of what’s sent to the server is required.</p>
  1194. </dd></dl>
  1195. <dl class="py method">
  1196. <dt class="sig sig-object py" id="logging.handlers.HTTPHandler.emit">
  1197. <span class="sig-name descname"><span class="pre">emit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.HTTPHandler.emit" title="Link to this definition">¶</a></dt>
  1198. <dd><p>Sends the record to the web server as a URL-encoded dictionary. The
  1199. <a class="reference internal" href="#logging.handlers.HTTPHandler.mapLogRecord" title="logging.handlers.HTTPHandler.mapLogRecord"><code class="xref py py-meth docutils literal notranslate"><span class="pre">mapLogRecord()</span></code></a> method is used to convert the record to the
  1200. dictionary to be sent.</p>
  1201. </dd></dl>
  1202. <div class="admonition note">
  1203. <p class="admonition-title">Note</p>
  1204. <p>Since preparing a record for sending it to a web server is not
  1205. the same as a generic formatting operation, using
  1206. <a class="reference internal" href="logging.html#logging.Handler.setFormatter" title="logging.Handler.setFormatter"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setFormatter()</span></code></a> to specify a
  1207. <a class="reference internal" href="logging.html#logging.Formatter" title="logging.Formatter"><code class="xref py py-class docutils literal notranslate"><span class="pre">Formatter</span></code></a> for a <a class="reference internal" href="#logging.handlers.HTTPHandler" title="logging.handlers.HTTPHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">HTTPHandler</span></code></a> has no effect.
  1208. Instead of calling <a class="reference internal" href="logging.html#logging.Handler.format" title="logging.Handler.format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">format()</span></code></a>, this handler calls
  1209. <a class="reference internal" href="#logging.handlers.HTTPHandler.mapLogRecord" title="logging.handlers.HTTPHandler.mapLogRecord"><code class="xref py py-meth docutils literal notranslate"><span class="pre">mapLogRecord()</span></code></a> and then <a class="reference internal" href="urllib.parse.html#urllib.parse.urlencode" title="urllib.parse.urlencode"><code class="xref py py-func docutils literal notranslate"><span class="pre">urllib.parse.urlencode()</span></code></a> to encode the
  1210. dictionary in a form suitable for sending to a web server.</p>
  1211. </div>
  1212. </dd></dl>
  1213. </section>
  1214. <section id="queuehandler">
  1215. <span id="queue-handler"></span><h2>QueueHandler<a class="headerlink" href="#queuehandler" title="Link to this heading">¶</a></h2>
  1216. <div class="versionadded">
  1217. <p><span class="versionmodified added">New in version 3.2.</span></p>
  1218. </div>
  1219. <p>The <a class="reference internal" href="#logging.handlers.QueueHandler" title="logging.handlers.QueueHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">QueueHandler</span></code></a> class, located in the <a class="reference internal" href="#module-logging.handlers" title="logging.handlers: Handlers for the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code></a> module,
  1220. supports sending logging messages to a queue, such as those implemented in the
  1221. <a class="reference internal" href="queue.html#module-queue" title="queue: A synchronized queue class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">queue</span></code></a> or <a class="reference internal" href="multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a> modules.</p>
  1222. <p>Along with the <a class="reference internal" href="#logging.handlers.QueueListener" title="logging.handlers.QueueListener"><code class="xref py py-class docutils literal notranslate"><span class="pre">QueueListener</span></code></a> class, <a class="reference internal" href="#logging.handlers.QueueHandler" title="logging.handlers.QueueHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">QueueHandler</span></code></a> can be used
  1223. to let handlers do their work on a separate thread from the one which does the
  1224. logging. This is important in web applications and also other service
  1225. applications where threads servicing clients need to respond as quickly as
  1226. possible, while any potentially slow operations (such as sending an email via
  1227. <a class="reference internal" href="#logging.handlers.SMTPHandler" title="logging.handlers.SMTPHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPHandler</span></code></a>) are done on a separate thread.</p>
  1228. <dl class="py class">
  1229. <dt class="sig sig-object py" id="logging.handlers.QueueHandler">
  1230. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.handlers.</span></span><span class="sig-name descname"><span class="pre">QueueHandler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">queue</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.QueueHandler" title="Link to this definition">¶</a></dt>
  1231. <dd><p>Returns a new instance of the <a class="reference internal" href="#logging.handlers.QueueHandler" title="logging.handlers.QueueHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">QueueHandler</span></code></a> class. The instance is
  1232. initialized with the queue to send messages to. The <em>queue</em> can be any
  1233. queue-like object; it’s used as-is by the <a class="reference internal" href="#logging.handlers.QueueHandler.enqueue" title="logging.handlers.QueueHandler.enqueue"><code class="xref py py-meth docutils literal notranslate"><span class="pre">enqueue()</span></code></a> method, which
  1234. needs to know how to send messages to it. The queue is not <em>required</em> to
  1235. have the task tracking API, which means that you can use
  1236. <a class="reference internal" href="queue.html#queue.SimpleQueue" title="queue.SimpleQueue"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleQueue</span></code></a> instances for <em>queue</em>.</p>
  1237. <div class="admonition note">
  1238. <p class="admonition-title">Note</p>
  1239. <p>If you are using <a class="reference internal" href="multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a>, you should avoid using
  1240. <a class="reference internal" href="queue.html#queue.SimpleQueue" title="queue.SimpleQueue"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleQueue</span></code></a> and instead use <a class="reference internal" href="multiprocessing.html#multiprocessing.Queue" title="multiprocessing.Queue"><code class="xref py py-class docutils literal notranslate"><span class="pre">multiprocessing.Queue</span></code></a>.</p>
  1241. </div>
  1242. <dl class="py method">
  1243. <dt class="sig sig-object py" id="logging.handlers.QueueHandler.emit">
  1244. <span class="sig-name descname"><span class="pre">emit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.QueueHandler.emit" title="Link to this definition">¶</a></dt>
  1245. <dd><p>Enqueues the result of preparing the LogRecord. Should an exception
  1246. occur (e.g. because a bounded queue has filled up), the
  1247. <a class="reference internal" href="logging.html#logging.Handler.handleError" title="logging.Handler.handleError"><code class="xref py py-meth docutils literal notranslate"><span class="pre">handleError()</span></code></a> method is called to handle the
  1248. error. This can result in the record silently being dropped (if
  1249. <a class="reference internal" href="logging.html#logging.raiseExceptions" title="logging.raiseExceptions"><code class="xref py py-data docutils literal notranslate"><span class="pre">logging.raiseExceptions</span></code></a> is <code class="docutils literal notranslate"><span class="pre">False</span></code>) or a message printed to
  1250. <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code> (if <a class="reference internal" href="logging.html#logging.raiseExceptions" title="logging.raiseExceptions"><code class="xref py py-data docutils literal notranslate"><span class="pre">logging.raiseExceptions</span></code></a> is <code class="docutils literal notranslate"><span class="pre">True</span></code>).</p>
  1251. </dd></dl>
  1252. <dl class="py method">
  1253. <dt class="sig sig-object py" id="logging.handlers.QueueHandler.prepare">
  1254. <span class="sig-name descname"><span class="pre">prepare</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.QueueHandler.prepare" title="Link to this definition">¶</a></dt>
  1255. <dd><p>Prepares a record for queuing. The object returned by this
  1256. method is enqueued.</p>
  1257. <p>The base implementation formats the record to merge the message,
  1258. arguments, exception and stack information, if present. It also removes
  1259. unpickleable items from the record in-place. Specifically, it overwrites
  1260. the record’s <code class="xref py py-attr docutils literal notranslate"><span class="pre">msg</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">message</span></code> attributes with the merged
  1261. message (obtained by calling the handler’s <a class="reference internal" href="functions.html#format" title="format"><code class="xref py py-meth docutils literal notranslate"><span class="pre">format()</span></code></a> method), and
  1262. sets the <code class="xref py py-attr docutils literal notranslate"><span class="pre">args</span></code>, <code class="xref py py-attr docutils literal notranslate"><span class="pre">exc_info</span></code> and <code class="xref py py-attr docutils literal notranslate"><span class="pre">exc_text</span></code> attributes
  1263. to <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
  1264. <p>You might want to override this method if you want to convert
  1265. the record to a dict or JSON string, or send a modified copy
  1266. of the record while leaving the original intact.</p>
  1267. <div class="admonition note">
  1268. <p class="admonition-title">Note</p>
  1269. <p>The base implementation formats the message with arguments, sets
  1270. the <code class="docutils literal notranslate"><span class="pre">message</span></code> and <code class="docutils literal notranslate"><span class="pre">msg</span></code> attributes to the formatted message and
  1271. sets the <code class="docutils literal notranslate"><span class="pre">args</span></code> and <code class="docutils literal notranslate"><span class="pre">exc_text</span></code> attributes to <code class="docutils literal notranslate"><span class="pre">None</span></code> to allow
  1272. pickling and to prevent further attempts at formatting. This means
  1273. that a handler on the <a class="reference internal" href="#logging.handlers.QueueListener" title="logging.handlers.QueueListener"><code class="xref py py-class docutils literal notranslate"><span class="pre">QueueListener</span></code></a> side won’t have the
  1274. information to do custom formatting, e.g. of exceptions. You may wish
  1275. to subclass <code class="docutils literal notranslate"><span class="pre">QueueHandler</span></code> and override this method to e.g. avoid
  1276. setting <code class="docutils literal notranslate"><span class="pre">exc_text</span></code> to <code class="docutils literal notranslate"><span class="pre">None</span></code>. Note that the <code class="docutils literal notranslate"><span class="pre">message</span></code> / <code class="docutils literal notranslate"><span class="pre">msg</span></code>
  1277. / <code class="docutils literal notranslate"><span class="pre">args</span></code> changes are related to ensuring the record is pickleable,
  1278. and you might or might not be able to avoid doing that depending on
  1279. whether your <code class="docutils literal notranslate"><span class="pre">args</span></code> are pickleable. (Note that you may have to
  1280. consider not only your own code but also code in any libraries that
  1281. you use.)</p>
  1282. </div>
  1283. </dd></dl>
  1284. <dl class="py method">
  1285. <dt class="sig sig-object py" id="logging.handlers.QueueHandler.enqueue">
  1286. <span class="sig-name descname"><span class="pre">enqueue</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.QueueHandler.enqueue" title="Link to this definition">¶</a></dt>
  1287. <dd><p>Enqueues the record on the queue using <code class="docutils literal notranslate"><span class="pre">put_nowait()</span></code>; you may
  1288. want to override this if you want to use blocking behaviour, or a
  1289. timeout, or a customized queue implementation.</p>
  1290. </dd></dl>
  1291. <dl class="py attribute">
  1292. <dt class="sig sig-object py" id="logging.handlers.QueueHandler.listener">
  1293. <span class="sig-name descname"><span class="pre">listener</span></span><a class="headerlink" href="#logging.handlers.QueueHandler.listener" title="Link to this definition">¶</a></dt>
  1294. <dd><p>When created via configuration using <a class="reference internal" href="logging.config.html#logging.config.dictConfig" title="logging.config.dictConfig"><code class="xref py py-func docutils literal notranslate"><span class="pre">dictConfig()</span></code></a>, this
  1295. attribute will contain a <a class="reference internal" href="#logging.handlers.QueueListener" title="logging.handlers.QueueListener"><code class="xref py py-class docutils literal notranslate"><span class="pre">QueueListener</span></code></a> instance for use with this
  1296. handler. Otherwise, it will be <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
  1297. <div class="versionadded">
  1298. <p><span class="versionmodified added">New in version 3.12.</span></p>
  1299. </div>
  1300. </dd></dl>
  1301. </dd></dl>
  1302. </section>
  1303. <section id="queuelistener">
  1304. <span id="queue-listener"></span><h2>QueueListener<a class="headerlink" href="#queuelistener" title="Link to this heading">¶</a></h2>
  1305. <div class="versionadded">
  1306. <p><span class="versionmodified added">New in version 3.2.</span></p>
  1307. </div>
  1308. <p>The <a class="reference internal" href="#logging.handlers.QueueListener" title="logging.handlers.QueueListener"><code class="xref py py-class docutils literal notranslate"><span class="pre">QueueListener</span></code></a> class, located in the <a class="reference internal" href="#module-logging.handlers" title="logging.handlers: Handlers for the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code></a>
  1309. module, supports receiving logging messages from a queue, such as those
  1310. implemented in the <a class="reference internal" href="queue.html#module-queue" title="queue: A synchronized queue class."><code class="xref py py-mod docutils literal notranslate"><span class="pre">queue</span></code></a> or <a class="reference internal" href="multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a> modules. The
  1311. messages are received from a queue in an internal thread and passed, on
  1312. the same thread, to one or more handlers for processing. While
  1313. <a class="reference internal" href="#logging.handlers.QueueListener" title="logging.handlers.QueueListener"><code class="xref py py-class docutils literal notranslate"><span class="pre">QueueListener</span></code></a> is not itself a handler, it is documented here
  1314. because it works hand-in-hand with <a class="reference internal" href="#logging.handlers.QueueHandler" title="logging.handlers.QueueHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">QueueHandler</span></code></a>.</p>
  1315. <p>Along with the <a class="reference internal" href="#logging.handlers.QueueHandler" title="logging.handlers.QueueHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">QueueHandler</span></code></a> class, <a class="reference internal" href="#logging.handlers.QueueListener" title="logging.handlers.QueueListener"><code class="xref py py-class docutils literal notranslate"><span class="pre">QueueListener</span></code></a> can be used
  1316. to let handlers do their work on a separate thread from the one which does the
  1317. logging. This is important in web applications and also other service
  1318. applications where threads servicing clients need to respond as quickly as
  1319. possible, while any potentially slow operations (such as sending an email via
  1320. <a class="reference internal" href="#logging.handlers.SMTPHandler" title="logging.handlers.SMTPHandler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SMTPHandler</span></code></a>) are done on a separate thread.</p>
  1321. <dl class="py class">
  1322. <dt class="sig sig-object py" id="logging.handlers.QueueListener">
  1323. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">logging.handlers.</span></span><span class="sig-name descname"><span class="pre">QueueListener</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">queue</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">handlers</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">respect_handler_level</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.QueueListener" title="Link to this definition">¶</a></dt>
  1324. <dd><p>Returns a new instance of the <a class="reference internal" href="#logging.handlers.QueueListener" title="logging.handlers.QueueListener"><code class="xref py py-class docutils literal notranslate"><span class="pre">QueueListener</span></code></a> class. The instance is
  1325. initialized with the queue to send messages to and a list of handlers which
  1326. will handle entries placed on the queue. The queue can be any queue-like
  1327. object; it’s passed as-is to the <a class="reference internal" href="#logging.handlers.QueueListener.dequeue" title="logging.handlers.QueueListener.dequeue"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dequeue()</span></code></a> method, which needs
  1328. to know how to get messages from it. The queue is not <em>required</em> to have the
  1329. task tracking API (though it’s used if available), which means that you can
  1330. use <a class="reference internal" href="queue.html#queue.SimpleQueue" title="queue.SimpleQueue"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleQueue</span></code></a> instances for <em>queue</em>.</p>
  1331. <div class="admonition note">
  1332. <p class="admonition-title">Note</p>
  1333. <p>If you are using <a class="reference internal" href="multiprocessing.html#module-multiprocessing" title="multiprocessing: Process-based parallelism."><code class="xref py py-mod docutils literal notranslate"><span class="pre">multiprocessing</span></code></a>, you should avoid using
  1334. <a class="reference internal" href="queue.html#queue.SimpleQueue" title="queue.SimpleQueue"><code class="xref py py-class docutils literal notranslate"><span class="pre">SimpleQueue</span></code></a> and instead use <a class="reference internal" href="multiprocessing.html#multiprocessing.Queue" title="multiprocessing.Queue"><code class="xref py py-class docutils literal notranslate"><span class="pre">multiprocessing.Queue</span></code></a>.</p>
  1335. </div>
  1336. <p>If <code class="docutils literal notranslate"><span class="pre">respect_handler_level</span></code> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, a handler’s level is respected
  1337. (compared with the level for the message) when deciding whether to pass
  1338. messages to that handler; otherwise, the behaviour is as in previous Python
  1339. versions - to always pass each message to each handler.</p>
  1340. <div class="versionchanged">
  1341. <p><span class="versionmodified changed">Changed in version 3.5: </span>The <code class="docutils literal notranslate"><span class="pre">respect_handler_level</span></code> argument was added.</p>
  1342. </div>
  1343. <dl class="py method">
  1344. <dt class="sig sig-object py" id="logging.handlers.QueueListener.dequeue">
  1345. <span class="sig-name descname"><span class="pre">dequeue</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">block</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.QueueListener.dequeue" title="Link to this definition">¶</a></dt>
  1346. <dd><p>Dequeues a record and return it, optionally blocking.</p>
  1347. <p>The base implementation uses <code class="docutils literal notranslate"><span class="pre">get()</span></code>. You may want to override this
  1348. method if you want to use timeouts or work with custom queue
  1349. implementations.</p>
  1350. </dd></dl>
  1351. <dl class="py method">
  1352. <dt class="sig sig-object py" id="logging.handlers.QueueListener.prepare">
  1353. <span class="sig-name descname"><span class="pre">prepare</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.QueueListener.prepare" title="Link to this definition">¶</a></dt>
  1354. <dd><p>Prepare a record for handling.</p>
  1355. <p>This implementation just returns the passed-in record. You may want to
  1356. override this method if you need to do any custom marshalling or
  1357. manipulation of the record before passing it to the handlers.</p>
  1358. </dd></dl>
  1359. <dl class="py method">
  1360. <dt class="sig sig-object py" id="logging.handlers.QueueListener.handle">
  1361. <span class="sig-name descname"><span class="pre">handle</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.QueueListener.handle" title="Link to this definition">¶</a></dt>
  1362. <dd><p>Handle a record.</p>
  1363. <p>This just loops through the handlers offering them the record
  1364. to handle. The actual object passed to the handlers is that which
  1365. is returned from <a class="reference internal" href="#logging.handlers.QueueListener.prepare" title="logging.handlers.QueueListener.prepare"><code class="xref py py-meth docutils literal notranslate"><span class="pre">prepare()</span></code></a>.</p>
  1366. </dd></dl>
  1367. <dl class="py method">
  1368. <dt class="sig sig-object py" id="logging.handlers.QueueListener.start">
  1369. <span class="sig-name descname"><span class="pre">start</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.QueueListener.start" title="Link to this definition">¶</a></dt>
  1370. <dd><p>Starts the listener.</p>
  1371. <p>This starts up a background thread to monitor the queue for
  1372. LogRecords to process.</p>
  1373. </dd></dl>
  1374. <dl class="py method">
  1375. <dt class="sig sig-object py" id="logging.handlers.QueueListener.stop">
  1376. <span class="sig-name descname"><span class="pre">stop</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.QueueListener.stop" title="Link to this definition">¶</a></dt>
  1377. <dd><p>Stops the listener.</p>
  1378. <p>This asks the thread to terminate, and then waits for it to do so.
  1379. Note that if you don’t call this before your application exits, there
  1380. may be some records still left on the queue, which won’t be processed.</p>
  1381. </dd></dl>
  1382. <dl class="py method">
  1383. <dt class="sig sig-object py" id="logging.handlers.QueueListener.enqueue_sentinel">
  1384. <span class="sig-name descname"><span class="pre">enqueue_sentinel</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#logging.handlers.QueueListener.enqueue_sentinel" title="Link to this definition">¶</a></dt>
  1385. <dd><p>Writes a sentinel to the queue to tell the listener to quit. This
  1386. implementation uses <code class="docutils literal notranslate"><span class="pre">put_nowait()</span></code>. You may want to override this
  1387. method if you want to use timeouts or work with custom queue
  1388. implementations.</p>
  1389. <div class="versionadded">
  1390. <p><span class="versionmodified added">New in version 3.3.</span></p>
  1391. </div>
  1392. </dd></dl>
  1393. </dd></dl>
  1394. <div class="admonition seealso">
  1395. <p class="admonition-title">See also</p>
  1396. <dl class="simple">
  1397. <dt>Module <a class="reference internal" href="logging.html#module-logging" title="logging: Flexible event logging system for applications."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a></dt><dd><p>API reference for the logging module.</p>
  1398. </dd>
  1399. <dt>Module <a class="reference internal" href="logging.config.html#module-logging.config" title="logging.config: Configuration of the logging module."><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.config</span></code></a></dt><dd><p>Configuration API for the logging module.</p>
  1400. </dd>
  1401. </dl>
  1402. </div>
  1403. </section>
  1404. </section>
  1405. <div class="clearer"></div>
  1406. </div>
  1407. </div>
  1408. </div>
  1409. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  1410. <div class="sphinxsidebarwrapper">
  1411. <div>
  1412. <h3><a href="../contents.html">Table of Contents</a></h3>
  1413. <ul>
  1414. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code> — Logging handlers</a><ul>
  1415. <li><a class="reference internal" href="#streamhandler">StreamHandler</a></li>
  1416. <li><a class="reference internal" href="#filehandler">FileHandler</a></li>
  1417. <li><a class="reference internal" href="#nullhandler">NullHandler</a></li>
  1418. <li><a class="reference internal" href="#watchedfilehandler">WatchedFileHandler</a></li>
  1419. <li><a class="reference internal" href="#baserotatinghandler">BaseRotatingHandler</a></li>
  1420. <li><a class="reference internal" href="#rotatingfilehandler">RotatingFileHandler</a></li>
  1421. <li><a class="reference internal" href="#timedrotatingfilehandler">TimedRotatingFileHandler</a></li>
  1422. <li><a class="reference internal" href="#sockethandler">SocketHandler</a></li>
  1423. <li><a class="reference internal" href="#datagramhandler">DatagramHandler</a></li>
  1424. <li><a class="reference internal" href="#sysloghandler">SysLogHandler</a></li>
  1425. <li><a class="reference internal" href="#nteventloghandler">NTEventLogHandler</a></li>
  1426. <li><a class="reference internal" href="#smtphandler">SMTPHandler</a></li>
  1427. <li><a class="reference internal" href="#memoryhandler">MemoryHandler</a></li>
  1428. <li><a class="reference internal" href="#httphandler">HTTPHandler</a></li>
  1429. <li><a class="reference internal" href="#queuehandler">QueueHandler</a></li>
  1430. <li><a class="reference internal" href="#queuelistener">QueueListener</a></li>
  1431. </ul>
  1432. </li>
  1433. </ul>
  1434. </div>
  1435. <div>
  1436. <h4>Previous topic</h4>
  1437. <p class="topless"><a href="logging.config.html"
  1438. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.config</span></code> — Logging configuration</a></p>
  1439. </div>
  1440. <div>
  1441. <h4>Next topic</h4>
  1442. <p class="topless"><a href="getpass.html"
  1443. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">getpass</span></code> — Portable password input</a></p>
  1444. </div>
  1445. <div role="note" aria-label="source link">
  1446. <h3>This Page</h3>
  1447. <ul class="this-page-menu">
  1448. <li><a href="../bugs.html">Report a Bug</a></li>
  1449. <li>
  1450. <a href="https://github.com/python/cpython/blob/main/Doc/library/logging.handlers.rst"
  1451. rel="nofollow">Show Source
  1452. </a>
  1453. </li>
  1454. </ul>
  1455. </div>
  1456. </div>
  1457. <div id="sidebarbutton" title="Collapse sidebar">
  1458. <span>«</span>
  1459. </div>
  1460. </div>
  1461. <div class="clearer"></div>
  1462. </div>
  1463. <div class="related" role="navigation" aria-label="related navigation">
  1464. <h3>Navigation</h3>
  1465. <ul>
  1466. <li class="right" style="margin-right: 10px">
  1467. <a href="../genindex.html" title="General Index"
  1468. >index</a></li>
  1469. <li class="right" >
  1470. <a href="../py-modindex.html" title="Python Module Index"
  1471. >modules</a> |</li>
  1472. <li class="right" >
  1473. <a href="getpass.html" title="getpass — Portable password input"
  1474. >next</a> |</li>
  1475. <li class="right" >
  1476. <a href="logging.config.html" title="logging.config — Logging configuration"
  1477. >previous</a> |</li>
  1478. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  1479. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  1480. <li class="switchers">
  1481. <div class="language_switcher_placeholder"></div>
  1482. <div class="version_switcher_placeholder"></div>
  1483. </li>
  1484. <li>
  1485. </li>
  1486. <li id="cpython-language-and-version">
  1487. <a href="../index.html">3.12.3 Documentation</a> &#187;
  1488. </li>
  1489. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  1490. <li class="nav-item nav-item-2"><a href="allos.html" >Generic Operating System Services</a> &#187;</li>
  1491. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging.handlers</span></code> — Logging handlers</a></li>
  1492. <li class="right">
  1493. <div class="inline-search" role="search">
  1494. <form class="inline-search" action="../search.html" method="get">
  1495. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  1496. <input type="submit" value="Go" />
  1497. </form>
  1498. </div>
  1499. |
  1500. </li>
  1501. <li class="right">
  1502. <label class="theme-selector-label">
  1503. Theme
  1504. <select class="theme-selector" oninput="activateTheme(this.value)">
  1505. <option value="auto" selected>Auto</option>
  1506. <option value="light">Light</option>
  1507. <option value="dark">Dark</option>
  1508. </select>
  1509. </label> |</li>
  1510. </ul>
  1511. </div>
  1512. <div class="footer">
  1513. &copy;
  1514. <a href="../copyright.html">
  1515. Copyright
  1516. </a>
  1517. 2001-2024, Python Software Foundation.
  1518. <br />
  1519. This page is licensed under the Python Software Foundation License Version 2.
  1520. <br />
  1521. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  1522. <br />
  1523. See <a href="/license.html">History and License</a> for more information.<br />
  1524. <br />
  1525. The Python Software Foundation is a non-profit corporation.
  1526. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  1527. <br />
  1528. <br />
  1529. Last updated on Apr 09, 2024 (13:47 UTC).
  1530. <a href="/bugs.html">Found a bug</a>?
  1531. <br />
  1532. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  1533. </div>
  1534. </body>
  1535. </html>
上海开阖软件有限公司 沪ICP备12045867号-1