Kerala Cyber
Warriors
KCW Uploader V1.1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>36.15. syslog — Unix syslog library routines — Python 2.7.18 documentation</title>
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/language_data.js"></script>
<script type="text/javascript" src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python 2.7.18 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="36.16. commands — Utilities for running commands" href="commands.html" />
<link rel="prev" title="36.14. nis — Interface to Sun’s NIS (Yellow Pages)" href="nis.html" />
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
<link rel="canonical" href="file:///usr/share/doc/python2.7/html/library/syslog.html" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
</head><body>
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
This document is for an old version of Python that is <a href="https://devguide.python.org/devcycle/#end-of-life-branches">no longer supported</a>.
You should install the python3 and python3-doc packages and read the
<a href="file:///usr/share/doc/python3-doc/html/library/syslog.html"> Python documentation for the Python3 version packaged in this release</a>.
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="commands.html" title="36.16. commands — Utilities for running commands"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="nis.html" title="36.14. nis — Interface to Sun’s NIS (Yellow Pages)"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
<a href="../index.html">Python 2.7.18 documentation</a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
<li class="nav-item nav-item-2"><a href="unix.html" accesskey="U">36. Unix Specific Services</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="module-syslog">
<span id="syslog-unix-syslog-library-routines"></span><h1>36.15. <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="Permalink to this headline">¶</a></h1>
<p>This module provides an interface to the Unix <code class="docutils literal notranslate"><span class="pre">syslog</span></code> library routines.
Refer to the Unix manual pages for a detailed description of the <code class="docutils literal notranslate"><span class="pre">syslog</span></code>
facility.</p>
<p>This module wraps the system <code class="docutils literal notranslate"><span class="pre">syslog</span></code> family of routines. A pure Python
library that can speak to a syslog server is available in the
<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>
<p>The module defines the following functions:</p>
<dl class="function">
<dt id="syslog.syslog">
<code class="descclassname">syslog.</code><code class="descname">syslog</code><span class="sig-paren">(</span><em>message</em><span class="sig-paren">)</span><a class="headerlink" href="#syslog.syslog" title="Permalink to this definition">¶</a></dt>
<dt>
<code class="descclassname">syslog.</code><code class="descname">syslog</code><span class="sig-paren">(</span><em>priority</em>, <em>message</em><span class="sig-paren">)</span></dt>
<dd><p>Send the string <em>message</em> to the system logger. A trailing newline is added
if necessary. Each message is tagged with a priority composed of a
<em>facility</em> and a <em>level</em>. The optional <em>priority</em> argument, which defaults
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
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
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>
<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>,
<code class="docutils literal notranslate"><span class="pre">openlog()</span></code> will be called with no arguments.</p>
</dd></dl>
<dl class="function">
<dt id="syslog.openlog">
<code class="descclassname">syslog.</code><code class="descname">openlog</code><span class="sig-paren">(</span><span class="optional">[</span><em>ident</em><span class="optional">[</span>, <em>logoption</em><span class="optional">[</span>, <em>facility</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="Permalink to this definition">¶</a></dt>
<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
<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
if the log is not currently open.</p>
<p>The optional <em>ident</em> keyword argument is a string which is prepended to every
message, and defaults to <code class="docutils literal notranslate"><span class="pre">sys.argv[0]</span></code> with leading path components
stripped. The optional <em>logoption</em> keyword argument (default is 0) is a bit
field – see below for possible values to combine. The optional <em>facility</em>
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
messages which do not have a facility explicitly encoded.</p>
</dd></dl>
<dl class="function">
<dt id="syslog.closelog">
<code class="descclassname">syslog.</code><code class="descname">closelog</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#syslog.closelog" title="Permalink to this definition">¶</a></dt>
<dd><p>Reset the syslog module values and call the system library <code class="docutils literal notranslate"><span class="pre">closelog()</span></code>.</p>
<p>This causes the module to behave as it does when initially imported. For
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
<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
<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>
</dd></dl>
<dl class="function">
<dt id="syslog.setlogmask">
<code class="descclassname">syslog.</code><code class="descname">setlogmask</code><span class="sig-paren">(</span><em>maskpri</em><span class="sig-paren">)</span><a class="headerlink" href="#syslog.setlogmask" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the priority mask to <em>maskpri</em> and return the previous mask value. Calls
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.
The default is to log all priorities. The function <code class="docutils literal notranslate"><span class="pre">LOG_MASK(pri)</span></code>
calculates the mask for the individual priority <em>pri</em>. The function
<code class="docutils literal notranslate"><span class="pre">LOG_UPTO(pri)</span></code> calculates the mask for all priorities up to and including
<em>pri</em>.</p>
</dd></dl>
<p>The module defines the following constants:</p>
<dl class="docutils">
<dt>Priority levels (high to low):</dt>
<dd><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>,
<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>,
<code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_DEBUG</span></code>.</dd>
<dt>Facilities:</dt>
<dd><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>,
<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>,
<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> and <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_LOCAL0</span></code> to
<code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_LOCAL7</span></code>.</dd>
<dt>Log options:</dt>
<dd><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>, <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_NOWAIT</span></code>
and <code class="xref py py-const docutils literal notranslate"><span class="pre">LOG_PERROR</span></code> if defined in <code class="docutils literal notranslate"><span class="pre"><syslog.h></span></code>.</dd>
</dl>
<div class="section" id="examples">
<h2>36.15.1. Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h2>
<div class="section" id="simple-example">
<h3>36.15.1.1. Simple example<a class="headerlink" href="#simple-example" title="Permalink to this headline">¶</a></h3>
<p>A simple set of examples:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">syslog</span>
<span class="n">syslog</span><span class="o">.</span><span class="n">syslog</span><span class="p">(</span><span class="s1">'Processing started'</span><span class="p">)</span>
<span class="k">if</span> <span class="n">error</span><span class="p">:</span>
<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">'Processing started'</span><span class="p">)</span>
</pre></div>
</div>
<p>An example of setting some log options, these would include the process ID in
logged messages, and write the messages to the destination facility used for
mail logging:</p>
<div class="highlight-default 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>
<span class="n">syslog</span><span class="o">.</span><span class="n">syslog</span><span class="p">(</span><span class="s1">'E-mail processing initiated...'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">36.15. <code class="docutils literal notranslate"><span class="pre">syslog</span></code> — Unix syslog library routines</a><ul>
<li><a class="reference internal" href="#examples">36.15.1. Examples</a><ul>
<li><a class="reference internal" href="#simple-example">36.15.1.1. Simple example</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="nis.html"
title="previous chapter">36.14. <code class="docutils literal notranslate"><span class="pre">nis</span></code> — Interface to Sun’s NIS (Yellow Pages)</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="commands.html"
title="next chapter">36.16. <code class="docutils literal notranslate"><span class="pre">commands</span></code> — Utilities for running commands</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/library/syslog.rst.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="commands.html" title="36.16. commands — Utilities for running commands"
>next</a> |</li>
<li class="right" >
<a href="nis.html" title="36.14. nis — Interface to Sun’s NIS (Yellow Pages)"
>previous</a> |</li>
<li><img src="../_static/py.png" alt=""
style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li>
<a href="../index.html">Python 2.7.18 documentation</a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
<li class="nav-item nav-item-2"><a href="unix.html" >36. Unix Specific Services</a> »</li>
</ul>
</div>
<div class="footer">
© <a href="../copyright.html">Copyright</a> 1990-2024, Python Software Foundation.
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
Last updated on November 21, 2024.
<a href="../bugs.html">Found a bug</a>?
<br />
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.8.5.
</div>
</body>
</html>
-=[ KCW uplo4d3r c0ded by cJ_n4p573r ]=-
Ⓒ2017 ҠЄГѦLѦ СүѣЄГ ЩѦГГіѺГՏ