This file is indexed.

/usr/share/doc/libapache2-mod-perl2-doc/docs/2.0/api/Apache2/Log.html is in libapache2-mod-perl2-doc 2.0.8+httpd24-r1449661-6ubuntu2.

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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>

<body style="background-color: white">



<ul id="index">
  <li><a href="#NAME">NAME</a></li>
  <li><a href="#Synopsis">Synopsis</a></li>
  <li><a href="#Description">Description</a></li>
  <li><a href="#Constants">Constants</a>
    <ul>
      <li><a href="#LogLevel-Constants">LogLevel Constants</a>
        <ul>
          <li><a href="#Apache2::Const::LOG_EMERG">Apache2::Const::LOG_EMERG</a></li>
          <li><a href="#Apache2::Const::LOG_ALERT">Apache2::Const::LOG_ALERT</a></li>
          <li><a href="#Apache2::Const::LOG_CRIT">Apache2::Const::LOG_CRIT</a></li>
          <li><a href="#Apache2::Const::LOG_ERR">Apache2::Const::LOG_ERR</a></li>
          <li><a href="#Apache2::Const::LOG_WARNING">Apache2::Const::LOG_WARNING</a></li>
          <li><a href="#Apache2::Const::LOG_NOTICE">Apache2::Const::LOG_NOTICE</a></li>
          <li><a href="#Apache2::Const::LOG_INFO">Apache2::Const::LOG_INFO</a></li>
          <li><a href="#Apache2::Const::LOG_DEBUG">Apache2::Const::LOG_DEBUG</a></li>
        </ul>
      </li>
      <li><a href="#Other-Constants">Other Constants</a>
        <ul>
          <li><a href="#Apache2::Const::LOG_LEVELMASK">Apache2::Const::LOG_LEVELMASK</a></li>
          <li><a href="#Apache2::Const::LOG_TOCLIENT">Apache2::Const::LOG_TOCLIENT</a></li>
          <li><a href="#Apache2::Const::LOG_STARTUP">Apache2::Const::LOG_STARTUP</a></li>
        </ul>
      </li>
    </ul>
  </li>
  <li><a href="#Server-Logging-Methods">Server Logging Methods</a>
    <ul>
      <li><a href="#s-log">$s-&gt;log</a></li>
      <li><a href="#s-log_error">$s-&gt;log_error</a></li>
      <li><a href="#s-log_serror">$s-&gt;log_serror</a></li>
      <li><a href="#s-warn">$s-&gt;warn</a></li>
    </ul>
  </li>
  <li><a href="#Request-Logging-Methods">Request Logging Methods</a>
    <ul>
      <li><a href="#r-log">$r-&gt;log</a></li>
      <li><a href="#r-log_error">$r-&gt;log_error</a></li>
      <li><a href="#r-log_reason">$r-&gt;log_reason</a></li>
      <li><a href="#r-log_rerror">$r-&gt;log_rerror</a></li>
      <li><a href="#r-warn">$r-&gt;warn</a></li>
    </ul>
  </li>
  <li><a href="#Other-Logging-Methods">Other Logging Methods</a>
    <ul>
      <li><a href="#LogLevel-Methods">LogLevel Methods</a></li>
      <li><a href="#alert">alert</a></li>
      <li><a href="#crit">crit</a></li>
      <li><a href="#debug">debug</a></li>
      <li><a href="#emerg">emerg</a></li>
      <li><a href="#error">error</a></li>
      <li><a href="#info">info</a></li>
      <li><a href="#notice">notice</a></li>
      <li><a href="#warn">warn</a></li>
    </ul>
  </li>
  <li><a href="#General-Functions">General Functions</a>
    <ul>
      <li><a href="#LOG_MARK">LOG_MARK</a></li>
    </ul>
  </li>
  <li><a href="#Virtual-Hosts">Virtual Hosts</a></li>
  <li><a href="#Unsupported-API">Unsupported API</a>
    <ul>
      <li><a href="#log_pid">log_pid</a></li>
    </ul>
  </li>
  <li><a href="#See-Also">See Also</a></li>
  <li><a href="#Copyright">Copyright</a></li>
  <li><a href="#Authors">Authors</a></li>
</ul>

<h1 id="NAME">NAME</h1>

<p>Apache2::Log - Perl API for Apache Logging Methods</p>

<h1 id="Synopsis">Synopsis</h1>

<pre><code>  # in startup.pl
  #--------------
  use Apache2::Log;
  
  use Apache2::Const -compile =&gt; qw(OK :log);
  use APR::Const    -compile =&gt; qw(:error SUCCESS);
  
  my $s = Apache2::ServerUtil-&gt;server;
  
  $s-&gt;log_error(&quot;server: log_error&quot;);
  $s-&gt;log_serror(__FILE__, __LINE__, Apache2::Const::LOG_ERR,
                 APR::Const::SUCCESS, &quot;log_serror logging at err level&quot;);
  $s-&gt;log_serror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_DEBUG,
                 APR::Const::ENOTIME, &quot;debug print&quot;);
  Apache2::ServerRec-&gt;log_error(&quot;routine warning&quot;);
  
  Apache2::ServerRec::warn(&quot;routine warning&quot;);

  # in a handler
  #-------------
  package Foo;
  
  use strict;
  use warnings FATAL =&gt; &#39;all&#39;;
  
  use Apache2::Log;
  
  use Apache2::Const -compile =&gt; qw(OK :log);
  use APR::Const    -compile =&gt; qw(:error SUCCESS);
  
  sub handler {
      my $r = shift;
      $r-&gt;log_error(&quot;request: log_error&quot;);
  
      my $rlog = $r-&gt;log;
      for my $level qw(emerg alert crit error warn notice info debug) {
          no strict &#39;refs&#39;;
          $rlog-&gt;$level($package, &quot;request: $level log level&quot;);
      }
  
      # can use server methods as well
      my $s = $r-&gt;server;
      $s-&gt;log_error(&quot;server: log_error&quot;);
  
      $r-&gt;log_rerror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_DEBUG,
                     APR::Const::ENOTIME, &quot;in debug&quot;);
  
      $s-&gt;log_serror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_INFO,
                     APR::Const::SUCCESS, &quot;server info&quot;);
  
      $s-&gt;log_serror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_ERR,
                     APR::Const::ENOTIME, &quot;fatal error&quot;);
  
      $r-&gt;log_reason(&quot;fatal error&quot;);
      $r-&gt;warn(&#39;routine request warning&#39;);
      $s-&gt;warn(&#39;routine server warning&#39;);
  
      return Apache2::Const::OK;
  }
  1;

  # in a registry script
  # httpd.conf: PerlOptions +GlobalRequest
  use Apache2::ServerRec qw(warn); # override warn locally
  print &quot;Content-type: text/plain\n\n&quot;;
  warn &quot;my warning&quot;;</code></pre>

<h1 id="Description">Description</h1>

<p><code>Apache2::Log</code> provides the Perl API for Apache logging methods.</p>

<p>Depending on the the current <code>LogLevel</code> setting, only logging with the same log level or higher will be loaded. For example if the current <code>LogLevel</code> is set to <i>warning</i>, only messages with log level of the level <i>warning</i> or higher (<i>err</i>, <i>crit</i>, <i>elert</i> and <i>emerg</i>) will be logged. Therefore this:</p>

<pre><code>  $r-&gt;log_rerror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_WARNING,
                 APR::Const::ENOTIME, &quot;warning!&quot;);</code></pre>

<p>will log the message, but this one won&#39;t:</p>

<pre><code>  $r-&gt;log_rerror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_INFO,
                 APR::Const::ENOTIME, &quot;just an info&quot;);</code></pre>

<p>It will be logged only if the server log level is set to <i>info</i> or <i>debug</i>. <code>LogLevel</code> is set in the configuration file, but can be changed using the <code><a>$s-&gt;loglevel()</a></code> method.</p>

<p>The filename and the line number of the caller are logged only if <code>Apache2::Const::LOG_DEBUG</code> is used (because that&#39;s how Apache 2.0 logging mechanism works).</p>

<p>Note: On Win32 Apache attempts to lock all writes to a file whenever it&#39;s opened for append (which is the case with logging functions), as Unix has this behavior built-in, while Win32 does not. Therefore <code>Apache2::Log</code> functions could be slower than Perl&#39;s print()/warn().</p>

<h1 id="Constants">Constants</h1>

<p>Log level constants can be compiled all at once:</p>

<pre><code>  use Apache2::Const -compile =&gt; qw(:log);</code></pre>

<p>or individually:</p>

<pre><code>  use Apache2::Const -compile =&gt; qw(LOG_DEBUG LOG_INFO);</code></pre>

<h2 id="LogLevel-Constants">LogLevel Constants</h2>

<p>The following constants (sorted from the most severe level to the least severe) are used in logging methods to specify the log level at which the message should be logged:</p>

<h3 id="Apache2::Const::LOG_EMERG"><code>Apache2::Const::LOG_EMERG</code></h3>

<h3 id="Apache2::Const::LOG_ALERT"><code>Apache2::Const::LOG_ALERT</code></h3>

<h3 id="Apache2::Const::LOG_CRIT"><code>Apache2::Const::LOG_CRIT</code></h3>

<h3 id="Apache2::Const::LOG_ERR"><code>Apache2::Const::LOG_ERR</code></h3>

<h3 id="Apache2::Const::LOG_WARNING"><code>Apache2::Const::LOG_WARNING</code></h3>

<h3 id="Apache2::Const::LOG_NOTICE"><code>Apache2::Const::LOG_NOTICE</code></h3>

<h3 id="Apache2::Const::LOG_INFO"><code>Apache2::Const::LOG_INFO</code></h3>

<h3 id="Apache2::Const::LOG_DEBUG"><code>Apache2::Const::LOG_DEBUG</code></h3>

<h2 id="Other-Constants">Other Constants</h2>

<p>Make sure to compile the APR status constants before using them. For example to compile <code>APR::Const::SUCCESS</code> and all the APR error status constants do:</p>

<pre><code>  use APR::Const    -compile =&gt; qw(:error SUCCESS);</code></pre>

<p>Here is the rest of the logging related constants:</p>

<h3 id="Apache2::Const::LOG_LEVELMASK"><code>Apache2::Const::LOG_LEVELMASK</code></h3>

<p>used to mask off the level value, to make sure that the log level&#39;s value is within the proper bits range. e.g.:</p>

<pre><code>  $loglevel &amp;= LOG_LEVELMASK;</code></pre>

<h3 id="Apache2::Const::LOG_TOCLIENT"><code>Apache2::Const::LOG_TOCLIENT</code></h3>

<p>used to give content handlers the option of including the error text in the <code>ErrorDocument</code> sent back to the client. When <code>Apache2::Const::LOG_TOCLIENT</code> is passed to <code>log_rerror()</code> the error message will be saved in the <code>$r</code>&#39;s notes table, keyed to the string <i>&quot;error-notes&quot;</i>, if and only if the severity level of the message is <code>Apache2::Const::LOG_WARNING</code> or greater and there are no other <i>&quot;error-notes&quot;</i> entry already set in the request record&#39;s notes table. Once the <i>&quot;error-notes&quot;</i> entry is set, it is up to the error handler to determine whether this text should be sent back to the client. For example:</p>

<pre><code>  use Apache2::Const -compile =&gt; qw(:log);
  use APR::Const    -compile =&gt; qw(ENOTIME);
  $r-&gt;log_rerror(Apache2::Log::LOG_MARK,
                 Apache2::Const::LOG_ERR|Apache2::Const::LOG_TOCLIENT,
                 APR::Const::ENOTIME,
                 &quot;request log_rerror&quot;);</code></pre>

<p>now the log message can be retrieved via:</p>

<pre><code>  $r-&gt;notes-&gt;get(&quot;error-notes&quot;);</code></pre>

<p>Remember that client-generated text streams sent back to the client <b>MUST</b> be escaped to prevent CSS attacks.</p>

<h3 id="Apache2::Const::LOG_STARTUP"><code>Apache2::Const::LOG_STARTUP</code></h3>

<p>is useful for startup message where no timestamps, logging level is wanted. For example:</p>

<pre><code>  use Apache2::Const -compile =&gt; qw(:log);
  use APR::Const    -compile =&gt; qw(SUCCESS);
  $s-&gt;log_serror(Apache2::Log::LOG_MARK,
                 Apache2::Const::LOG_INFO,
                 APR::Const::SUCCESS,
                 &quot;This log message comes with a header&quot;);</code></pre>

<p>will print:</p>

<pre><code>  [Wed May 14 16:47:09 2003] [info] This log message comes with a header</code></pre>

<p>whereas, when <code>Apache2::Const::LOG_STARTUP</code> is binary ORed as in:</p>

<pre><code>  use Apache2::Const -compile =&gt; qw(:log);
  use APR::Const    -compile =&gt; qw(SUCCESS);
  $s-&gt;log_serror(Apache2::Log::LOG_MARK,
                 Apache2::Const::LOG_INFO|Apache2::Const::LOG_STARTUP,
                 APR::Const::SUCCESS,
                 &quot;This log message comes with no header&quot;);</code></pre>

<p>then the logging will be:</p>

<pre><code>  This log message comes with no header</code></pre>

<h1 id="Server-Logging-Methods">Server Logging Methods</h1>

<h2 id="s-log"><code>$s-&gt;log</code></h2>

<p>get a log handle which can be used to <a href="#LogLevel_Methods">log messages of different levels</a>.</p>

<pre><code>  my $slog = $s-&gt;log;</code></pre>

<dl>

<dt id="obj:-s-Apache2::ServerRec-object">obj: <code>$s</code> ( <code><a>Apache2::ServerRec object</a></code> )</dt>
<dd>

</dd>
<dt id="ret:-slog-Apache2::Log::Server-object">ret: <code>$slog</code> ( <code>Apache2::Log::Server</code> object )</dt>
<dd>

<p><code>Apache2::Log::Server</code> object to be used with <a href="#LogLevel_Methods">LogLevel methods</a>.</p>

</dd>
<dt id="since:-2.0.00">since: 2.0.00</dt>
<dd>

</dd>
</dl>

<h2 id="s-log_error"><code>$s-&gt;log_error</code></h2>

<p>just logs the supplied message to <i>error_log</i></p>

<pre><code>  $s-&gt;log_error(@message);</code></pre>

<dl>

<dt id="obj:-s-Apache2::ServerRec-object1">obj: <code>$s</code> ( <code><a>Apache2::ServerRec object</a></code> )</dt>
<dd>

</dd>
<dt id="arg1:-message-strings-ARRAY">arg1: <code>@message</code> ( strings ARRAY )</dt>
<dd>

<p>what to log</p>

</dd>
<dt id="ret:-no-return-value">ret: no return value</dt>
<dd>

</dd>
<dt id="since:-2.0.001">since: 2.0.00</dt>
<dd>

</dd>
</dl>

<p>For example:</p>

<pre><code>  $s-&gt;log_error(&quot;running low on memory&quot;);</code></pre>

<h2 id="s-log_serror"><code>$s-&gt;log_serror</code></h2>

<p>This function provides a fine control of when the message is logged, gives an access to built-in status codes.</p>

<pre><code>  $s-&gt;log_serror($file, $line, $level, $status, @message);</code></pre>

<dl>

<dt id="obj:-s-Apache2::ServerRec-object2">obj: <code>$s</code> ( <code><a>Apache2::ServerRec object</a></code> )</dt>
<dd>

</dd>
<dt id="arg1:-file-string">arg1: <code>$file</code> ( string )</dt>
<dd>

<p>The file in which this function is called</p>

</dd>
<dt id="arg2:-line-number">arg2: <code>$line</code> ( number )</dt>
<dd>

<p>The line number on which this function is called</p>

</dd>
<dt id="arg3:-level-Apache2::LOG_-constant">arg3: <code>$level</code> ( <code><a href="#LogLevel_Constants">Apache2::LOG_* constant</a></code> )</dt>
<dd>

<p>The level of this error message</p>

</dd>
<dt id="arg4:-status-APR::Const-status-constant">arg4: <code>$status</code> ( <code><a>APR::Const status constant</a></code> )</dt>
<dd>

<p>The status code from the last command (similar to $! in perl), usually <code><a>APR::Const constant</a></code> or coming from an <a>exception object</a>.</p>

</dd>
<dt id="arg5:-message-strings-ARRAY">arg5: <code>@message</code> ( strings ARRAY )</dt>
<dd>

<p>The log message(s)</p>

</dd>
<dt id="ret:-no-return-value1">ret: no return value</dt>
<dd>

</dd>
<dt id="since:-2.0.002">since: 2.0.00</dt>
<dd>

</dd>
</dl>

<p>For example:</p>

<pre><code>  use Apache2::Const -compile =&gt; qw(:log);
  use APR::Const    -compile =&gt; qw(ENOTIME SUCCESS);
  $s-&gt;log_serror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_ERR,
                 APR::Const::SUCCESS, &quot;log_serror logging at err level&quot;);
  
  $s-&gt;log_serror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_DEBUG,
                 APR::Const::ENOTIME, &quot;debug print&quot;);</code></pre>

<h2 id="s-warn"><code>$s-&gt;warn</code></h2>

<pre><code>  $s-&gt;warn(@warnings);</code></pre>

<p>is the same as:</p>

<pre><code>  $s-&gt;log_serror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_WARNING,
                 APR::Const::SUCCESS, @warnings)</code></pre>

<dl>

<dt id="obj:-s-Apache2::ServerRec-object3">obj: <code>$s</code> ( <code><a>Apache2::ServerRec object</a></code> )</dt>
<dd>

</dd>
<dt id="arg1:-warnings-strings-ARRAY">arg1: <code>@warnings</code> ( strings ARRAY )</dt>
<dd>

<p>array of warning strings</p>

</dd>
<dt id="ret:-no-return-value2">ret: no return value</dt>
<dd>

</dd>
<dt id="since:-2.0.003">since: 2.0.00</dt>
<dd>

</dd>
</dl>

<p>For example:</p>

<pre><code>  $s-&gt;warn(&#39;routine server warning&#39;);</code></pre>

<h1 id="Request-Logging-Methods">Request Logging Methods</h1>

<h2 id="r-log"><code>$r-&gt;log</code></h2>

<p>get a log handle which can be used to <a href="#LogLevel_Methods">log messages of different levels</a>.</p>

<pre><code>  $rlog = $r-&gt;log;</code></pre>

<dl>

<dt id="obj:-r-Apache2::RequestRec-object">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>

</dd>
<dt id="ret:-rlog-Apache2::Log::Request-object">ret: <code>$rlog</code> ( <code>Apache2::Log::Request</code> object )</dt>
<dd>

<p><code>Apache2::Log::Request</code> object to be used with <a href="#LogLevel_Methods">LogLevel methods</a>.</p>

</dd>
<dt id="since:-2.0.004">since: 2.0.00</dt>
<dd>

</dd>
</dl>

<h2 id="r-log_error"><code>$r-&gt;log_error</code></h2>

<p>just logs the supplied message (similar to <code><a href="#C__s_E_gt_log_error_">$s-&gt;log_error</a></code> ).</p>

<pre><code>  $r-&gt;log_error(@message);</code></pre>

<dl>

<dt id="obj:-r-Apache2::RequestRec-object1">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>

</dd>
<dt id="arg1:-message-strings-ARRAY1">arg1: <code>@message</code> ( strings ARRAY )</dt>
<dd>

<p>what to log</p>

</dd>
<dt id="ret:-no-return-value3">ret: no return value</dt>
<dd>

</dd>
<dt id="since:-2.0.005">since: 2.0.00</dt>
<dd>

</dd>
</dl>

<p>For example:</p>

<pre><code>  $r-&gt;log_error(&quot;the request is about to end&quot;);</code></pre>

<h2 id="r-log_reason"><code>$r-&gt;log_reason</code></h2>

<p>This function provides a convenient way to log errors in a preformatted way:</p>

<pre><code>  $r-&gt;log_reason($message);
  $r-&gt;log_reason($message, $filename);</code></pre>

<dl>

<dt id="obj:-r-Apache2::RequestRec-object2">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>

</dd>
<dt id="arg1:-message-string">arg1: <code>$message</code> ( string )</dt>
<dd>

<p>the message to log</p>

</dd>
<dt id="opt-arg2:-filename-string">opt arg2: <code>$filename</code> ( string )</dt>
<dd>

<p>where to report the error as coming from (e.g. <code>__FILE__</code>)</p>

</dd>
<dt id="ret:-no-return-value4">ret: no return value</dt>
<dd>

</dd>
<dt id="since:-2.0.006">since: 2.0.00</dt>
<dd>

</dd>
</dl>

<p>For example:</p>

<pre><code>  $r-&gt;log_reason(&quot;There is no enough data&quot;);</code></pre>

<p>will generate a log entry similar to the following:</p>

<pre><code>  [Fri Sep 24 11:58:36 2004] [error] access to /someuri
  failed for 127.0.0.1, reason: There is no enough data.</code></pre>

<h2 id="r-log_rerror"><code>$r-&gt;log_rerror</code></h2>

<p>This function provides a fine control of when the message is logged, gives an access to built-in status codes.</p>

<pre><code>  $r-&gt;log_rerror($file, $line, $level, $status, @message);</code></pre>

<p>arguments are identical to <code><a href="#C__s_E_gt_log_serror_">$s-&gt;log_serror</a></code>.</p>

<dl>

<dt id="since:-2.0.007">since: 2.0.00</dt>
<dd>

</dd>
</dl>

<p>For example:</p>

<pre><code>  use Apache2::Const -compile =&gt; qw(:log);
  use APR::Const    -compile =&gt; qw(ENOTIME SUCCESS);
  $r-&gt;log_rerror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_ERR,
                 APR::Const::SUCCESS, &quot;log_rerror logging at err level&quot;);
  
  $r-&gt;log_rerror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_DEBUG,
                 APR::Const::ENOTIME, &quot;debug print&quot;);</code></pre>

<h2 id="r-warn"><code>$r-&gt;warn</code></h2>

<pre><code>  $r-&gt;warn(@warnings);</code></pre>

<p>is the same as:</p>

<pre><code>  $r-&gt;log_rerror(Apache2::Log::LOG_MARK, Apache2::Const::LOG_WARNING,
                 APR::Const::SUCCESS, @warnings)</code></pre>

<dl>

<dt id="obj:-r-Apache2::RequestRec-object3">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>

</dd>
<dt id="arg1:-warnings-strings-ARRAY1">arg1: <code>@warnings</code> ( strings ARRAY )</dt>
<dd>

<p>array of warning strings</p>

</dd>
<dt id="ret:-no-return-value5">ret: no return value</dt>
<dd>

</dd>
<dt id="since:-2.0.008">since: 2.0.00</dt>
<dd>

</dd>
</dl>

<p>For example:</p>

<pre><code>  $r-&gt;warn(&#39;routine server warning&#39;);</code></pre>

<h1 id="Other-Logging-Methods">Other Logging Methods</h1>

<h2 id="LogLevel-Methods">LogLevel Methods</h2>

<p>after getting the log handle with <code><a href="#C__s_E_gt_log_">$s-&gt;log</a></code> or <code><a href="#C__s_E_gt_log_">$r-&gt;log</a></code>, use one of the following methods (corresponding to the <code>LogLevel</code> levels):</p>

<pre><code>  emerg(), alert(), crit(), error(), warn(), notice(), info(), debug()</code></pre>

<p>to control when messages should be logged:</p>

<pre><code>  $s-&gt;log-&gt;emerg(@message);
  $r-&gt;log-&gt;emerg(@message);</code></pre>

<dl>

<dt id="obj:-slog-server-or-request-log-handle">obj: <code>$slog</code> ( <a href="#C__s_E_gt_log_">server</a> or <a href="#C__s_E_gt_log_">request</a> log handle )</dt>
<dd>

</dd>
<dt id="arg1:-message-strings-ARRAY2">arg1: <code>@message</code> ( strings ARRAY )</dt>
<dd>

</dd>
<dt id="ret:-no-return-value6">ret: no return value</dt>
<dd>

</dd>
<dt id="since:-2.0.009">since: 2.0.00</dt>
<dd>

</dd>
</dl>

<p>For example if the <code>LogLevel</code> is <code>error</code> and the following code is executed:</p>

<pre><code>  my $slog = $s-&gt;log;
  $slog-&gt;debug(&quot;just &quot;, &quot;some debug info&quot;);
  $slog-&gt;warn(@warnings);
  $slog-&gt;crit(&quot;dying&quot;);</code></pre>

<p>only the last command&#39;s logging will be performed. This is because <i>warn</i>, <i>debug</i> and other logging command which are listed right to <i>error</i> will be disabled.</p>

<h2 id="alert"><code>alert</code></h2>

<p>See <a href="#LogLevel_Methods">LogLevel Methods</a>.</p>

<h2 id="crit"><code>crit</code></h2>

<p>See <a href="#LogLevel_Methods">LogLevel Methods</a>.</p>

<h2 id="debug"><code>debug</code></h2>

<p>See <a href="#LogLevel_Methods">LogLevel Methods</a>.</p>

<h2 id="emerg"><code>emerg</code></h2>

<p>See <a href="#LogLevel_Methods">LogLevel Methods</a>.</p>

<h2 id="error"><code>error</code></h2>

<p>See <a href="#LogLevel_Methods">LogLevel Methods</a>.</p>

<h2 id="info"><code>info</code></h2>

<p>See <a href="#LogLevel_Methods">LogLevel Methods</a>.</p>

<h2 id="notice"><code>notice</code></h2>

<p>See <a href="#LogLevel_Methods">LogLevel Methods</a>.</p>

<p>Though Apache treats <code>notice()</code> calls as special. The message is always logged regardless the value of <code>ErrorLog</code>, unless the error log is set to use syslog. (For details see httpd-2.0/server/log.c.)</p>

<h2 id="warn"><code>warn</code></h2>

<p>See <a href="#LogLevel_Methods">LogLevel Methods</a>.</p>

<h1 id="General-Functions">General Functions</h1>

<h2 id="LOG_MARK"><code>LOG_MARK</code></h2>

<p>Though looking like a constant, this is a function, which returns a list of two items: <code>(__FILE__, __LINE__)</code>, i.e. the file and the line where the function was called from.</p>

<pre><code>  my ($file, $line) = Apache2::Log::LOG_MARK();</code></pre>

<dl>

<dt id="ret1:-file-string">ret1: <code>$file</code> ( string )</dt>
<dd>

</dd>
<dt id="ret2:-line-number">ret2: <code>$line</code> ( number )</dt>
<dd>

</dd>
<dt id="since:-2.0.0010">since: 2.0.00</dt>
<dd>

</dd>
</dl>

<p>It&#39;s mostly useful to be passed as the first argument to those logging methods, expecting the filename and the line number as the first arguments (e.g., <code><a href="#C__s_E_gt_log_serror_">$s-&gt;log_serror</a></code> and <code><a href="#C__r_E_gt_log_rerror_">$r-&gt;log_rerror</a></code> ).</p>

<h1 id="Virtual-Hosts">Virtual Hosts</h1>

<p>Code running from within a virtual host needs to be able to log into its <code>ErrorLog</code> file, if different from the main log. Calling any of the logging methods on the <code>$r</code> and <code>$s</code> objects will do the logging correctly.</p>

<p>If the core <code>warn()</code> is called, it&#39;ll be always logged to the main log file. Here is how to make it log into the vhost <i>error_log</i> file. Let&#39;s say that we start with the following code:</p>

<pre><code>  warn &quot;the code is smoking&quot;;</code></pre>

<ol>

<li><p>First, we need to use mod_perl&#39;s logging function, instead of <code>CORE::warn</code></p>

<p>Either replace <code>warn</code> with <code>Apache2::ServerRec::warn</code>:</p>

<pre><code>  use Apache2::Log ();
  Apache2::ServerRec::warn(&quot;the code is smoking&quot;);</code></pre>

<p>or import it into your code:</p>

<pre><code>  use Apache2::ServerRec qw(warn); # override warn locally
  warn &quot;the code is smoking&quot;;</code></pre>

<p>or override <code>CORE::warn</code>:</p>

<pre><code>  use Apache2::Log ();
  *CORE::GLOBAL::warn = \&amp;Apache2::ServerRec::warn;
  warn &quot;the code is smoking&quot;;</code></pre>

<p>Avoid using the latter suggestion, since it&#39;ll affect all the code running on the server, which may break things. Of course you can localize that as well:</p>

<pre><code>  use Apache2::Log ();
  local *CORE::GLOBAL::warn = \&amp;Apache2::ServerRec::warn;
  warn &quot;the code is smoking&quot;;</code></pre>

<p>Chances are that you need to make the internal Perl warnings go into the vhost&#39;s <i>error_log</i> file as well. Here is how to do that:</p>

<pre><code>  use Apache2::Log ();
  local $SIG{__WARN__} = \&amp;Apache2::ServerRec::warn;
  eval q[my $x = &quot;aaa&quot; + 1;]; # this issues a warning</code></pre>

<p>Notice that it&#39;ll override any previous setting you may have had, disabling modules like <code>CGI::Carp</code> which also use <code>$SIG{__WARN__}</code></p>

</li>
<li><p>Next we need to figure out how to get hold of the vhost&#39;s server object.</p>

<p>Inside HTTP request handlers this is possible via <code><a>Apache2-&gt;request</a></code>. Which requires either <code><a>PerlOptions +GlobalRequest</a></code> setting or can be also done at runtime if <code>$r</code> is available:</p>

<pre><code>  use Apache2::RequestUtil ();
  sub handler {
      my $r = shift;
      Apache2::RequestUtil-&gt;request($r);
      ...</code></pre>

<p>Outside HTTP handlers at the moment it is not possible, to get hold of the vhost&#39;s <i>error_log</i> file. This shouldn&#39;t be a problem for the code that runs only under mod_perl, since the always available <code>$s</code> object can invoke a plethora of methods supplied by <code>Apache2::Log</code>. This is only a problem for modules, which are supposed to run outside mod_perl as well.</p>

<p>META: To solve this we think to introduce &#39;PerlOptions +GlobalServer&#39;, a big brother for &#39;PerlOptions +GlobalRequest&#39;, which will be set in modperl_hook_pre_connection.</p>

</li>
</ol>

<h1 id="Unsupported-API">Unsupported API</h1>

<p><code>Apache2::Log</code> also provides auto-generated Perl interface for a few other methods which aren&#39;t tested at the moment and therefore their API is a subject to change. These methods will be finalized later as a need arises. If you want to rely on any of the following methods please contact the <a>the mod_perl development mailing list</a> so we can help each other take the steps necessary to shift the method to an officially supported API.</p>

<h2 id="log_pid"><code>log_pid</code></h2>

<p>META: what is this method good for? it just calls getpid and logs it. In any case it has nothing to do with the logging API. And it uses static variables, it probably shouldn&#39;t be in the Apache public API.</p>

<p>Log the current pid</p>

<pre><code>  Apache2::Log::log_pid($pool, $fname);</code></pre>

<dl>

<dt id="obj:-p-APR::Pool-object">obj: <code>$p</code> ( <code><a>APR::Pool object</a></code> )</dt>
<dd>

<p>The pool to use for logging</p>

</dd>
<dt id="arg1:-fname-file-path">arg1: <code>$fname</code> ( file path )</dt>
<dd>

<p>The name of the file to log to</p>

</dd>
<dt id="ret:-no-return-value7">ret: no return value</dt>
<dd>

</dd>
<dt id="since:-subject-to-change">since: subject to change</dt>
<dd>

</dd>
</dl>

<h1 id="See-Also">See Also</h1>

<p><a>mod_perl 2.0 documentation</a>.</p>

<h1 id="Copyright">Copyright</h1>

<p>mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0.</p>

<h1 id="Authors">Authors</h1>

<p><a>The mod_perl development team and numerous contributors</a>.</p>


</body>

</html>