This file is indexed.

/usr/share/doc/python-twisted-web/howto/web-in-60/logging-errors.html is in python-twisted-web 13.2.0-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html  PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head>
<title>Twisted Documentation: Logging Errors</title>
<link href="../stylesheet.css" rel="stylesheet" type="text/css"/>
  </head>

  <body bgcolor="white">
    <h1 class="title">Logging Errors</h1>
    <div class="toc"><ol/></div>
    <div class="content">
<span/>

<p>The <a href="interrupted.html" shape="rect">previous example</a> created a server that
dealt with response errors by aborting response generation, potentially avoiding
pointless work. However, it did this silently for any error. In this example,
we'll modify the previous example so that it logs each failed response.</p>

<p>This example will use the Twisted API for logging errors. As was
mentioned in the <a href="asynchronous-deferred.html" shape="rect">first example
covering Deferreds</a>, errbacks are passed an error. In the previous
example, the <code>_responseFailed</code> errback accepted this error
as a parameter but ignored it. The only way this example will differ
is that this <code>_responseFailed</code> will use that error
parameter to log a message.</p>

<p>This example will require all of the imports required by the previous example
plus one new import:</p>

<pre class="python"><p class="py-linenumber">1
</p><span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">python</span>.<span class="py-src-variable">log</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">err</span>
</pre>

<p>The only other part of the previous example which changes is
the <code>_responseFailed</code> callback, which will now log the
error passed to it:</p>

<pre class="python"><p class="py-linenumber">1
2
3
4
</p>...
    <span class="py-src-keyword">def</span> <span class="py-src-identifier">_responseFailed</span>(<span class="py-src-parameter">self</span>, <span class="py-src-parameter">failure</span>, <span class="py-src-parameter">call</span>):
        <span class="py-src-variable">call</span>.<span class="py-src-variable">cancel</span>()
        <span class="py-src-variable">err</span>(<span class="py-src-variable">failure</span>, <span class="py-src-string">&quot;Async response demo interrupted response&quot;</span>)
</pre>

<p>We're passing two arguments to <code class="API"><a href="http://twistedmatrix.com/documents/13.2.0/api/twisted.python.log.err.html" title="twisted.python.log.err">err</a></code> here. The first is the error which is being
passed in to the callback. This is always an object of type <code class="API"><a href="http://twistedmatrix.com/documents/13.2.0/api/twisted.python.failure.Failure.html" title="twisted.python.failure.Failure">Failure</a></code>, a class which represents an
exception and (sometimes, but not always) a traceback. <code>err</code> will
format this nicely for the log. The second argument is a descriptive string that
tells someone reading the log what the source of the error was.</p>

<p>Here's the full example with the two above modifications:</p>

<pre class="python"><p class="py-linenumber"> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
</p><span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">web</span>.<span class="py-src-variable">resource</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">Resource</span>
<span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">web</span>.<span class="py-src-variable">server</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">NOT_DONE_YET</span>
<span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">internet</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">reactor</span>
<span class="py-src-keyword">from</span> <span class="py-src-variable">twisted</span>.<span class="py-src-variable">python</span>.<span class="py-src-variable">log</span> <span class="py-src-keyword">import</span> <span class="py-src-variable">err</span>

<span class="py-src-keyword">class</span> <span class="py-src-identifier">DelayedResource</span>(<span class="py-src-parameter">Resource</span>):
    <span class="py-src-keyword">def</span> <span class="py-src-identifier">_delayedRender</span>(<span class="py-src-parameter">self</span>, <span class="py-src-parameter">request</span>):
        <span class="py-src-variable">request</span>.<span class="py-src-variable">write</span>(<span class="py-src-string">&quot;&lt;html&gt;&lt;body&gt;Sorry to keep you waiting.&lt;/body&gt;&lt;/html&gt;&quot;</span>)
        <span class="py-src-variable">request</span>.<span class="py-src-variable">finish</span>()

    <span class="py-src-keyword">def</span> <span class="py-src-identifier">_responseFailed</span>(<span class="py-src-parameter">self</span>, <span class="py-src-parameter">failure</span>, <span class="py-src-parameter">call</span>):
        <span class="py-src-variable">call</span>.<span class="py-src-variable">cancel</span>()
        <span class="py-src-variable">err</span>(<span class="py-src-variable">failure</span>, <span class="py-src-string">&quot;Async response demo interrupted response&quot;</span>)

    <span class="py-src-keyword">def</span> <span class="py-src-identifier">render_GET</span>(<span class="py-src-parameter">self</span>, <span class="py-src-parameter">request</span>):
        <span class="py-src-variable">call</span> = <span class="py-src-variable">reactor</span>.<span class="py-src-variable">callLater</span>(<span class="py-src-number">5</span>, <span class="py-src-variable">self</span>.<span class="py-src-variable">_delayedRender</span>, <span class="py-src-variable">request</span>)
        <span class="py-src-variable">request</span>.<span class="py-src-variable">notifyFinish</span>().<span class="py-src-variable">addErrback</span>(<span class="py-src-variable">self</span>.<span class="py-src-variable">_responseFailed</span>, <span class="py-src-variable">call</span>)
        <span class="py-src-keyword">return</span> <span class="py-src-variable">NOT_DONE_YET</span>

<span class="py-src-variable">resource</span> = <span class="py-src-variable">DelayedResource</span>()
</pre>

<p>Run this server as in the <a href="interrupted.html" shape="rect">previous example</a>
and interrupt a request. Unlike the previous example, where the server gave no
indication that this had happened, you'll see a message in the log output with
this version.</p>

</div>

    <p><a href="../index.html">Index</a></p>
    <span class="version">Version: 13.2.0</span>
  </body>
</html>