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.

469 lines
32KB

  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="syslog — Unix syslog library routines" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/syslog.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="This module provides an interface to the Unix syslog library routines. Refer to the Unix manual pages for a detailed description of the syslog facility. Availability: Unix, not Emscripten, not WASI..." />
  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="This module provides an interface to the Unix syslog library routines. Refer to the Unix manual pages for a detailed description of the syslog facility. Availability: Unix, not Emscripten, not WASI..." />
  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>syslog — Unix syslog library routines &#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="Modules command-line interface (CLI)" href="cmdline.html" />
  33. <link rel="prev" title="resource — Resource usage information" href="resource.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/syslog.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">syslog</span></code> — Unix syslog library routines</a><ul>
  86. <li><a class="reference internal" href="#examples">Examples</a><ul>
  87. <li><a class="reference internal" href="#simple-example">Simple example</a></li>
  88. </ul>
  89. </li>
  90. </ul>
  91. </li>
  92. </ul>
  93. </div>
  94. <div>
  95. <h4>Previous topic</h4>
  96. <p class="topless"><a href="resource.html"
  97. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">resource</span></code> — Resource usage information</a></p>
  98. </div>
  99. <div>
  100. <h4>Next topic</h4>
  101. <p class="topless"><a href="cmdline.html"
  102. title="next chapter">Modules command-line interface (CLI)</a></p>
  103. </div>
  104. <div role="note" aria-label="source link">
  105. <h3>This Page</h3>
  106. <ul class="this-page-menu">
  107. <li><a href="../bugs.html">Report a Bug</a></li>
  108. <li>
  109. <a href="https://github.com/python/cpython/blob/main/Doc/library/syslog.rst"
  110. rel="nofollow">Show Source
  111. </a>
  112. </li>
  113. </ul>
  114. </div>
  115. </nav>
  116. </div>
  117. </div>
  118. <div class="related" role="navigation" aria-label="related navigation">
  119. <h3>Navigation</h3>
  120. <ul>
  121. <li class="right" style="margin-right: 10px">
  122. <a href="../genindex.html" title="General Index"
  123. accesskey="I">index</a></li>
  124. <li class="right" >
  125. <a href="../py-modindex.html" title="Python Module Index"
  126. >modules</a> |</li>
  127. <li class="right" >
  128. <a href="cmdline.html" title="Modules command-line interface (CLI)"
  129. accesskey="N">next</a> |</li>
  130. <li class="right" >
  131. <a href="resource.html" title="resource — Resource usage information"
  132. accesskey="P">previous</a> |</li>
  133. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  134. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  135. <li class="switchers">
  136. <div class="language_switcher_placeholder"></div>
  137. <div class="version_switcher_placeholder"></div>
  138. </li>
  139. <li>
  140. </li>
  141. <li id="cpython-language-and-version">
  142. <a href="../index.html">3.12.3 Documentation</a> &#187;
  143. </li>
  144. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  145. <li class="nav-item nav-item-2"><a href="unix.html" accesskey="U">Unix Specific Services</a> &#187;</li>
  146. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">syslog</span></code> — Unix syslog library routines</a></li>
  147. <li class="right">
  148. <div class="inline-search" role="search">
  149. <form class="inline-search" action="../search.html" method="get">
  150. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  151. <input type="submit" value="Go" />
  152. </form>
  153. </div>
  154. |
  155. </li>
  156. <li class="right">
  157. <label class="theme-selector-label">
  158. Theme
  159. <select class="theme-selector" oninput="activateTheme(this.value)">
  160. <option value="auto" selected>Auto</option>
  161. <option value="light">Light</option>
  162. <option value="dark">Dark</option>
  163. </select>
  164. </label> |</li>
  165. </ul>
  166. </div>
  167. <div class="document">
  168. <div class="documentwrapper">
  169. <div class="bodywrapper">
  170. <div class="body" role="main">
  171. <section id="module-syslog">
  172. <span id="syslog-unix-syslog-library-routines"></span><h1><a class="reference internal" href="#module-syslog" title="syslog: An interface to the Unix syslog library routines. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">syslog</span></code></a> — Unix syslog library routines<a class="headerlink" href="#module-syslog" title="Link to this heading">¶</a></h1>
  173. <hr class="docutils" />
  174. <p>This module provides an interface to the Unix <code class="docutils literal notranslate"><span class="pre">syslog</span></code> library routines.
  175. Refer to the Unix manual pages for a detailed description of the <code class="docutils literal notranslate"><span class="pre">syslog</span></code>
  176. facility.</p>
  177. <div class="availability docutils container">
  178. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix, not Emscripten, not WASI.</p>
  179. </div>
  180. <p>This module wraps the system <code class="docutils literal notranslate"><span class="pre">syslog</span></code> family of routines. A pure Python
  181. library that can speak to a syslog server is available in the
  182. <a class="reference internal" href="logging.handlers.html#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 as <code class="xref py py-class docutils literal notranslate"><span class="pre">SysLogHandler</span></code>.</p>
  183. <p>The module defines the following functions:</p>
  184. <dl class="py function">
  185. <dt class="sig sig-object py" id="syslog.syslog">
  186. <span class="sig-prename descclassname"><span class="pre">syslog.</span></span><span class="sig-name descname"><span class="pre">syslog</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">message</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#syslog.syslog" title="Link to this definition">¶</a></dt>
  187. <dt class="sig sig-object py">
  188. <span class="sig-prename descclassname"><span class="pre">syslog.</span></span><span class="sig-name descname"><span class="pre">syslog</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">priority</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">message</span></span></em><span class="sig-paren">)</span></dt>
  189. <dd><p>Send the string <em>message</em> to the system logger. A trailing newline is added
  190. if necessary. Each message is tagged with a priority composed of a
  191. <em>facility</em> and a <em>level</em>. The optional <em>priority</em> argument, which defaults
  192. to <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_INFO</span></code>, determines the message priority. If the facility is
  193. not encoded in <em>priority</em> using logical-or (<code class="docutils literal notranslate"><span class="pre">LOG_INFO</span> <span class="pre">|</span> <span class="pre">LOG_USER</span></code>), the
  194. value given in the <a class="reference internal" href="#syslog.openlog" title="syslog.openlog"><code class="xref py py-func docutils literal notranslate"><span class="pre">openlog()</span></code></a> call is used.</p>
  195. <p>If <a class="reference internal" href="#syslog.openlog" title="syslog.openlog"><code class="xref py py-func docutils literal notranslate"><span class="pre">openlog()</span></code></a> has not been called prior to the call to <a class="reference internal" href="#module-syslog" title="syslog: An interface to the Unix syslog library routines. (Unix)"><code class="xref py py-func docutils literal notranslate"><span class="pre">syslog()</span></code></a>,
  196. <a class="reference internal" href="#syslog.openlog" title="syslog.openlog"><code class="xref py py-func docutils literal notranslate"><span class="pre">openlog()</span></code></a> will be called with no arguments.</p>
  197. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">syslog.syslog</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">priority</span></code>, <code class="docutils literal notranslate"><span class="pre">message</span></code>.</p>
  198. <div class="versionchanged">
  199. <p><span class="versionmodified changed">Changed in version 3.2: </span>In previous versions, <a class="reference internal" href="#syslog.openlog" title="syslog.openlog"><code class="xref py py-func docutils literal notranslate"><span class="pre">openlog()</span></code></a> would not be called automatically if
  200. it wasn’t called prior to the call to <a class="reference internal" href="#module-syslog" title="syslog: An interface to the Unix syslog library routines. (Unix)"><code class="xref py py-func docutils literal notranslate"><span class="pre">syslog()</span></code></a>, deferring to the syslog
  201. implementation to call <code class="docutils literal notranslate"><span class="pre">openlog()</span></code>.</p>
  202. </div>
  203. <div class="versionchanged">
  204. <p><span class="versionmodified changed">Changed in version 3.12: </span>This function is restricted in subinterpreters.
  205. (Only code that runs in multiple interpreters is affected and
  206. the restriction is not relevant for most users.)
  207. <a class="reference internal" href="#syslog.openlog" title="syslog.openlog"><code class="xref py py-func docutils literal notranslate"><span class="pre">openlog()</span></code></a> must be called in the main interpreter before <a class="reference internal" href="#module-syslog" title="syslog: An interface to the Unix syslog library routines. (Unix)"><code class="xref py py-func docutils literal notranslate"><span class="pre">syslog()</span></code></a> may be used
  208. in a subinterpreter. Otherwise it will raise <a class="reference internal" href="exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a>.</p>
  209. </div>
  210. </dd></dl>
  211. <dl class="py function">
  212. <dt class="sig sig-object py" id="syslog.openlog">
  213. <span class="sig-prename descclassname"><span class="pre">syslog.</span></span><span class="sig-name descname"><span class="pre">openlog</span></span><span class="sig-paren">(</span><span class="optional">[</span><em class="sig-param"><span class="n"><span class="pre">ident</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">logoption</span></span></em><span class="optional">[</span>, <em class="sig-param"><span class="n"><span class="pre">facility</span></span></em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#syslog.openlog" title="Link to this definition">¶</a></dt>
  214. <dd><p>Logging options of subsequent <a class="reference internal" href="#module-syslog" title="syslog: An interface to the Unix syslog library routines. (Unix)"><code class="xref py py-func docutils literal notranslate"><span class="pre">syslog()</span></code></a> calls can be set by calling
  215. <a class="reference internal" href="#syslog.openlog" title="syslog.openlog"><code class="xref py py-func docutils literal notranslate"><span class="pre">openlog()</span></code></a>. <a class="reference internal" href="#module-syslog" title="syslog: An interface to the Unix syslog library routines. (Unix)"><code class="xref py py-func docutils literal notranslate"><span class="pre">syslog()</span></code></a> will call <a class="reference internal" href="#syslog.openlog" title="syslog.openlog"><code class="xref py py-func docutils literal notranslate"><span class="pre">openlog()</span></code></a> with no arguments
  216. if the log is not currently open.</p>
  217. <p>The optional <em>ident</em> keyword argument is a string which is prepended to every
  218. message, and defaults to <code class="docutils literal notranslate"><span class="pre">sys.argv[0]</span></code> with leading path components
  219. stripped. The optional <em>logoption</em> keyword argument (default is 0) is a bit
  220. field – see below for possible values to combine. The optional <em>facility</em>
  221. keyword argument (default is <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_USER</span></code>) sets the default facility for
  222. messages which do not have a facility explicitly encoded.</p>
  223. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">syslog.openlog</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">ident</span></code>, <code class="docutils literal notranslate"><span class="pre">logoption</span></code>, <code class="docutils literal notranslate"><span class="pre">facility</span></code>.</p>
  224. <div class="versionchanged">
  225. <p><span class="versionmodified changed">Changed in version 3.2: </span>In previous versions, keyword arguments were not allowed, and <em>ident</em> was
  226. required.</p>
  227. </div>
  228. <div class="versionchanged">
  229. <p><span class="versionmodified changed">Changed in version 3.12: </span>This function is restricted in subinterpreters.
  230. (Only code that runs in multiple interpreters is affected and
  231. the restriction is not relevant for most users.)
  232. This may only be called in the main interpreter.
  233. It will raise <a class="reference internal" href="exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> if called in a subinterpreter.</p>
  234. </div>
  235. </dd></dl>
  236. <dl class="py function">
  237. <dt class="sig sig-object py" id="syslog.closelog">
  238. <span class="sig-prename descclassname"><span class="pre">syslog.</span></span><span class="sig-name descname"><span class="pre">closelog</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#syslog.closelog" title="Link to this definition">¶</a></dt>
  239. <dd><p>Reset the syslog module values and call the system library <code class="docutils literal notranslate"><span class="pre">closelog()</span></code>.</p>
  240. <p>This causes the module to behave as it does when initially imported. For
  241. example, <a class="reference internal" href="#syslog.openlog" title="syslog.openlog"><code class="xref py py-func docutils literal notranslate"><span class="pre">openlog()</span></code></a> will be called on the first <a class="reference internal" href="#module-syslog" title="syslog: An interface to the Unix syslog library routines. (Unix)"><code class="xref py py-func docutils literal notranslate"><span class="pre">syslog()</span></code></a> call (if
  242. <a class="reference internal" href="#syslog.openlog" title="syslog.openlog"><code class="xref py py-func docutils literal notranslate"><span class="pre">openlog()</span></code></a> hasn’t already been called), and <em>ident</em> and other
  243. <a class="reference internal" href="#syslog.openlog" title="syslog.openlog"><code class="xref py py-func docutils literal notranslate"><span class="pre">openlog()</span></code></a> parameters are reset to defaults.</p>
  244. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">syslog.closelog</span></code> with no arguments.</p>
  245. <div class="versionchanged">
  246. <p><span class="versionmodified changed">Changed in version 3.12: </span>This function is restricted in subinterpreters.
  247. (Only code that runs in multiple interpreters is affected and
  248. the restriction is not relevant for most users.)
  249. This may only be called in the main interpreter.
  250. It will raise <a class="reference internal" href="exceptions.html#RuntimeError" title="RuntimeError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">RuntimeError</span></code></a> if called in a subinterpreter.</p>
  251. </div>
  252. </dd></dl>
  253. <dl class="py function">
  254. <dt class="sig sig-object py" id="syslog.setlogmask">
  255. <span class="sig-prename descclassname"><span class="pre">syslog.</span></span><span class="sig-name descname"><span class="pre">setlogmask</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">maskpri</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#syslog.setlogmask" title="Link to this definition">¶</a></dt>
  256. <dd><p>Set the priority mask to <em>maskpri</em> and return the previous mask value. Calls
  257. to <a class="reference internal" href="#module-syslog" title="syslog: An interface to the Unix syslog library routines. (Unix)"><code class="xref py py-func docutils literal notranslate"><span class="pre">syslog()</span></code></a> with a priority level not set in <em>maskpri</em> are ignored.
  258. The default is to log all priorities. The function <code class="docutils literal notranslate"><span class="pre">LOG_MASK(pri)</span></code>
  259. calculates the mask for the individual priority <em>pri</em>. The function
  260. <code class="docutils literal notranslate"><span class="pre">LOG_UPTO(pri)</span></code> calculates the mask for all priorities up to and including
  261. <em>pri</em>.</p>
  262. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">syslog.setlogmask</span></code> with argument <code class="docutils literal notranslate"><span class="pre">maskpri</span></code>.</p>
  263. </dd></dl>
  264. <p>The module defines the following constants:</p>
  265. <dl class="simple">
  266. <dt>Priority levels (high to low):</dt><dd><p><code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_EMERG</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_ALERT</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_CRIT</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_ERR</span></code>,
  267. <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_WARNING</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_NOTICE</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_INFO</span></code>,
  268. <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_DEBUG</span></code>.</p>
  269. </dd>
  270. <dt>Facilities:</dt><dd><p><code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_KERN</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_USER</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_MAIL</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_DAEMON</span></code>,
  271. <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_AUTH</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_LPR</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_NEWS</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_UUCP</span></code>,
  272. <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_CRON</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_SYSLOG</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_LOCAL0</span></code> to
  273. <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_LOCAL7</span></code>, and, if defined in <code class="docutils literal notranslate"><span class="pre">&lt;syslog.h&gt;</span></code>,
  274. <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_AUTHPRIV</span></code>.</p>
  275. </dd>
  276. <dt>Log options:</dt><dd><p><code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_PID</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_CONS</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_NDELAY</span></code>, and, if defined
  277. in <code class="docutils literal notranslate"><span class="pre">&lt;syslog.h&gt;</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_ODELAY</span></code>, <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_NOWAIT</span></code>, and
  278. <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_PERROR</span></code>.</p>
  279. </dd>
  280. </dl>
  281. <section id="examples">
  282. <h2>Examples<a class="headerlink" href="#examples" title="Link to this heading">¶</a></h2>
  283. <section id="simple-example">
  284. <h3>Simple example<a class="headerlink" href="#simple-example" title="Link to this heading">¶</a></h3>
  285. <p>A simple set of examples:</p>
  286. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">syslog</span>
  287. <span class="n">syslog</span><span class="o">.</span><span class="n">syslog</span><span class="p">(</span><span class="s1">&#39;Processing started&#39;</span><span class="p">)</span>
  288. <span class="k">if</span> <span class="n">error</span><span class="p">:</span>
  289. <span class="n">syslog</span><span class="o">.</span><span class="n">syslog</span><span class="p">(</span><span class="n">syslog</span><span class="o">.</span><span class="n">LOG_ERR</span><span class="p">,</span> <span class="s1">&#39;Processing started&#39;</span><span class="p">)</span>
  290. </pre></div>
  291. </div>
  292. <p>An example of setting some log options, these would include the process ID in
  293. logged messages, and write the messages to the destination facility used for
  294. mail logging:</p>
  295. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">syslog</span><span class="o">.</span><span class="n">openlog</span><span class="p">(</span><span class="n">logoption</span><span class="o">=</span><span class="n">syslog</span><span class="o">.</span><span class="n">LOG_PID</span><span class="p">,</span> <span class="n">facility</span><span class="o">=</span><span class="n">syslog</span><span class="o">.</span><span class="n">LOG_MAIL</span><span class="p">)</span>
  296. <span class="n">syslog</span><span class="o">.</span><span class="n">syslog</span><span class="p">(</span><span class="s1">&#39;E-mail processing initiated...&#39;</span><span class="p">)</span>
  297. </pre></div>
  298. </div>
  299. </section>
  300. </section>
  301. </section>
  302. <div class="clearer"></div>
  303. </div>
  304. </div>
  305. </div>
  306. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  307. <div class="sphinxsidebarwrapper">
  308. <div>
  309. <h3><a href="../contents.html">Table of Contents</a></h3>
  310. <ul>
  311. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">syslog</span></code> — Unix syslog library routines</a><ul>
  312. <li><a class="reference internal" href="#examples">Examples</a><ul>
  313. <li><a class="reference internal" href="#simple-example">Simple example</a></li>
  314. </ul>
  315. </li>
  316. </ul>
  317. </li>
  318. </ul>
  319. </div>
  320. <div>
  321. <h4>Previous topic</h4>
  322. <p class="topless"><a href="resource.html"
  323. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">resource</span></code> — Resource usage information</a></p>
  324. </div>
  325. <div>
  326. <h4>Next topic</h4>
  327. <p class="topless"><a href="cmdline.html"
  328. title="next chapter">Modules command-line interface (CLI)</a></p>
  329. </div>
  330. <div role="note" aria-label="source link">
  331. <h3>This Page</h3>
  332. <ul class="this-page-menu">
  333. <li><a href="../bugs.html">Report a Bug</a></li>
  334. <li>
  335. <a href="https://github.com/python/cpython/blob/main/Doc/library/syslog.rst"
  336. rel="nofollow">Show Source
  337. </a>
  338. </li>
  339. </ul>
  340. </div>
  341. </div>
  342. <div id="sidebarbutton" title="Collapse sidebar">
  343. <span>«</span>
  344. </div>
  345. </div>
  346. <div class="clearer"></div>
  347. </div>
  348. <div class="related" role="navigation" aria-label="related navigation">
  349. <h3>Navigation</h3>
  350. <ul>
  351. <li class="right" style="margin-right: 10px">
  352. <a href="../genindex.html" title="General Index"
  353. >index</a></li>
  354. <li class="right" >
  355. <a href="../py-modindex.html" title="Python Module Index"
  356. >modules</a> |</li>
  357. <li class="right" >
  358. <a href="cmdline.html" title="Modules command-line interface (CLI)"
  359. >next</a> |</li>
  360. <li class="right" >
  361. <a href="resource.html" title="resource — Resource usage information"
  362. >previous</a> |</li>
  363. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  364. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  365. <li class="switchers">
  366. <div class="language_switcher_placeholder"></div>
  367. <div class="version_switcher_placeholder"></div>
  368. </li>
  369. <li>
  370. </li>
  371. <li id="cpython-language-and-version">
  372. <a href="../index.html">3.12.3 Documentation</a> &#187;
  373. </li>
  374. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  375. <li class="nav-item nav-item-2"><a href="unix.html" >Unix Specific Services</a> &#187;</li>
  376. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">syslog</span></code> — Unix syslog library routines</a></li>
  377. <li class="right">
  378. <div class="inline-search" role="search">
  379. <form class="inline-search" action="../search.html" method="get">
  380. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  381. <input type="submit" value="Go" />
  382. </form>
  383. </div>
  384. |
  385. </li>
  386. <li class="right">
  387. <label class="theme-selector-label">
  388. Theme
  389. <select class="theme-selector" oninput="activateTheme(this.value)">
  390. <option value="auto" selected>Auto</option>
  391. <option value="light">Light</option>
  392. <option value="dark">Dark</option>
  393. </select>
  394. </label> |</li>
  395. </ul>
  396. </div>
  397. <div class="footer">
  398. &copy;
  399. <a href="../copyright.html">
  400. Copyright
  401. </a>
  402. 2001-2024, Python Software Foundation.
  403. <br />
  404. This page is licensed under the Python Software Foundation License Version 2.
  405. <br />
  406. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  407. <br />
  408. See <a href="/license.html">History and License</a> for more information.<br />
  409. <br />
  410. The Python Software Foundation is a non-profit corporation.
  411. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  412. <br />
  413. <br />
  414. Last updated on Apr 09, 2024 (13:47 UTC).
  415. <a href="/bugs.html">Found a bug</a>?
  416. <br />
  417. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  418. </div>
  419. </body>
  420. </html>
上海开阖软件有限公司 沪ICP备12045867号-1