171 lines
10 KiB
HTML
171 lines
10 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Setting Up Logging</title>
|
|
<!-- end extra head -->
|
|
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
|
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
|
|
<link rel="stylesheet" type="text/css" href="_static/basic.css" />
|
|
<link rel="stylesheet" href="_static/style.css" type="text/css" />
|
|
<link rel="stylesheet" href="_static/codeblocks.css" type="text/css" />
|
|
<link rel="stylesheet" href="_static/icons.css" type="text/css" />
|
|
<script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
|
|
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
|
|
<script src="_static/jquery.js"></script>
|
|
<script src="_static/underscore.js"></script>
|
|
<script src="_static/doctools.js"></script>
|
|
<script src="_static/custom.js"></script>
|
|
<script src="_static/settings.js"></script>
|
|
<script src="_static/copy.js"></script>
|
|
<script src="_static/sidebar.js"></script>
|
|
<link rel="shortcut icon" href="_static/discord_py_logo.ico"/>
|
|
<link rel="index" title="Index" href="genindex.html" />
|
|
<link rel="search" title="Search" href="search.html" />
|
|
</head>
|
|
<body>
|
|
<div class="main-grid">
|
|
<header class="grid-item">
|
|
<nav>
|
|
<a href="index.html" class="main-heading">discord.py</a>
|
|
<a href="https://github.com/Rapptz/discord.py" title="GitHub"><span class="material-icons custom-icons">github</span></a>
|
|
<a href="https://discord.gg/TvqYBrGXEm" title="Discord"><span class="material-icons custom-icons">discord</span></a>
|
|
<a href="faq.html" title="FAQ"><span class="material-icons">help_center</span></a>
|
|
<a onclick="mobileSearch.open();" title="Search" id="open-search" class="mobile-only"><span class="material-icons">search</span></a>
|
|
<a onclick="mobileSearch.close();" title="Close" id="close-search" class="mobile-only" hidden><span class="material-icons">close</span></a>
|
|
</nav>
|
|
<nav class="mobile-only">
|
|
<form role="search" class="search" action="search.html" method="get">
|
|
<div class="search-wrapper">
|
|
<input type="search" name="q" placeholder="Search documentation" />
|
|
<button type="submit">
|
|
<span class="material-icons">search</span>
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</nav>
|
|
</header>
|
|
<div class="sub-header grid-item">
|
|
<label for="documentation_select">View Documentation For</label>
|
|
<select id="documentation_select" onchange="window.location = this.value;">
|
|
<option value="#" selected>discord</option>
|
|
<option value="ext/commands/index.html" >discord.ext.commands</option>
|
|
<option value="ext/tasks/index.html" >discord.ext.tasks</option>
|
|
</select>
|
|
<form role="search" class="search" action="search.html" method="get">
|
|
<div class="search-wrapper">
|
|
<input type="search" name="q" placeholder="Search documentation" />
|
|
<button type="submit">
|
|
<span class="material-icons">search</span>
|
|
</button>
|
|
</div>
|
|
</form>
|
|
<a accesskey="S" class="settings" onclick="settingsModal.open();"><span class="material-icons">settings</span></a>
|
|
</div>
|
|
<aside class="grid-item">
|
|
<span id="settings-toggle" class="settings" onclick="settingsModal.open();">
|
|
<span class="material-icons">settings</span>
|
|
</span>
|
|
<div id="sidebar">
|
|
</div>
|
|
</aside>
|
|
<main class="grid-item" role="main">
|
|
|
|
<div class="versionadded">
|
|
<p><span class="versionmodified added">New in version 0.6.0.</span></p>
|
|
</div>
|
|
<section id="setting-up-logging">
|
|
<span id="logging-setup"></span><h1>Setting Up Logging<a class="headerlink" href="#setting-up-logging" title="Permalink to this headline">¶</a></h1>
|
|
<p><em>discord.py</em> logs errors and debug information via the <a class="reference external" href="https://docs.python.org/3/library/logging.html#module-logging" title="(in Python v3.9)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a> python
|
|
module. It is strongly recommended that the logging module is
|
|
configured, as no errors or warnings will be output if it is not set up.
|
|
Configuration of the <code class="docutils literal notranslate"><span class="pre">logging</span></code> module can be as simple as:</p>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">logging</span>
|
|
|
|
<span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">)</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>Placed at the start of the application. This will output the logs from
|
|
discord as well as other libraries that use the <code class="docutils literal notranslate"><span class="pre">logging</span></code> module
|
|
directly to the console.</p>
|
|
<p>The optional <code class="docutils literal notranslate"><span class="pre">level</span></code> argument specifies what level of events to log
|
|
out and can be any of <code class="docutils literal notranslate"><span class="pre">CRITICAL</span></code>, <code class="docutils literal notranslate"><span class="pre">ERROR</span></code>, <code class="docutils literal notranslate"><span class="pre">WARNING</span></code>, <code class="docutils literal notranslate"><span class="pre">INFO</span></code>, and
|
|
<code class="docutils literal notranslate"><span class="pre">DEBUG</span></code> and if not specified defaults to <code class="docutils literal notranslate"><span class="pre">WARNING</span></code>.</p>
|
|
<p>More advanced setups are possible with the <a class="reference external" href="https://docs.python.org/3/library/logging.html#module-logging" title="(in Python v3.9)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a> module. For
|
|
example to write the logs to a file called <code class="docutils literal notranslate"><span class="pre">discord.log</span></code> instead of
|
|
outputting them to the console the following snippet can be used:</p>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">discord</span>
|
|
<span class="kn">import</span> <span class="nn">logging</span>
|
|
|
|
<span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s1">'discord'</span><span class="p">)</span>
|
|
<span class="n">logger</span><span class="o">.</span><span class="n">setLevel</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">)</span>
|
|
<span class="n">handler</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">FileHandler</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="s1">'discord.log'</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s1">'utf-8'</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">'w'</span><span class="p">)</span>
|
|
<span class="n">handler</span><span class="o">.</span><span class="n">setFormatter</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">Formatter</span><span class="p">(</span><span class="s1">'</span><span class="si">%(asctime)s</span><span class="s1">:</span><span class="si">%(levelname)s</span><span class="s1">:</span><span class="si">%(name)s</span><span class="s1">: </span><span class="si">%(message)s</span><span class="s1">'</span><span class="p">))</span>
|
|
<span class="n">logger</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">handler</span><span class="p">)</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>This is recommended, especially at verbose levels such as <code class="docutils literal notranslate"><span class="pre">INFO</span></code>
|
|
and <code class="docutils literal notranslate"><span class="pre">DEBUG</span></code>, as there are a lot of events logged and it would clog the
|
|
stdout of your program.</p>
|
|
<p>For more information, check the documentation and tutorial of the
|
|
<a class="reference external" href="https://docs.python.org/3/library/logging.html#module-logging" title="(in Python v3.9)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code></a> module.</p>
|
|
</section>
|
|
|
|
|
|
</main>
|
|
<footer class="grid-item">
|
|
© Copyright 2015-present, Rapptz.
|
|
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.2.0.
|
|
</footer>
|
|
</div>
|
|
|
|
<div id="settings" class="modal" onclick="if (event.target == this){ settingsModal.close(); }" hidden>
|
|
<div class="modal-content">
|
|
<span class="close" onclick="settingsModal.close();" title="Close">
|
|
<span class="material-icons">close</span>
|
|
</span>
|
|
<h1>Settings</h1>
|
|
|
|
<h2>Font</h2>
|
|
<div class="setting">
|
|
<h3>Use a serif font:
|
|
<label class="toggle"
|
|
title="Use a serif font? Your system font will be used, falling back to serif.">
|
|
<input type="checkbox" name="useSerifFont" onclick="updateSetting(this);">
|
|
<span class="toggle-slider"></span>
|
|
</label>
|
|
</h3>
|
|
</div>
|
|
|
|
<h2>Theme</h2>
|
|
<div class="setting">
|
|
<h3>
|
|
<label class="toggle" title="Set your theme based on your system preferences">
|
|
<input type="radio" name="setTheme" onclick="updateSetting(this);" value="automatic" checked>
|
|
</label>
|
|
Automatic
|
|
</h3>
|
|
<h3>
|
|
<label class="toggle" title="Set your theme to light theme">
|
|
<input type="radio" name="setTheme" onclick="updateSetting(this);" value="light">
|
|
</label>
|
|
Light
|
|
</h3>
|
|
<h3>
|
|
<label class="toggle" title="Set your theme to dark theme">
|
|
<input type="radio" name="setTheme" onclick="updateSetting(this);" value="dark">
|
|
</label>
|
|
Dark
|
|
</h3>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div id="to-top" onclick="scrollToTop()" hidden>
|
|
<span><span class="material-icons">arrow_upward</span> to top</span>
|
|
</div>
|
|
|
|
</body>
|
|
</html> |