-
Notifications
You must be signed in to change notification settings - Fork 20
/
index.html
1862 lines (1816 loc) · 75.9 KB
/
index.html
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
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?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 xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.12: http://docutils.sourceforge.net/" />
<title>The Log Package</title>
<style type="text/css">
body {
font-family: Verdana, Helvetica, Arial, sans-serif;
font-size: 0.8em;
letter-spacing: 0.01em;
line-height: 1.5em;
text-align: justify;
margin: 0 auto;
width: 48em;
}
a:link, a:visited {
color: #00c;
padding-bottom: 0;
text-decoration: none;
border-bottom: 1px solid #dbd5c5;
}
a:hover {
padding-bottom: 0;
border-bottom: 2px solid #dbd5c5;
}
h1, h2, h3 {
font-family: Georgia, "Times New Roman", Times, serif;
font-weight: normal;
line-height: normal;
}
h1 {
font-size: 2.1em;
letter-spacing: -0.02em;
margin-top: 30px;
text-align: center;
}
h2 {
font-size: 1.6em;
font-style: italic;
margin: 30px 0 10px 0;
}
h3 {
font-size: 1.3em;
font-style: italic;
margin-top: 20px;
}
li {
line-height: 135%;
}
ul, ol {
margin: 0 0 1em 2em;
padding: 0 0 0 1em;
}
hr {
background-color: #ccc;
border: 0px none;
color: #eee;
height: 1px;
margin: 30px 0px;
}
blockquote, pre {
background-color: #f9f9f9;
border: 1px solid #eee;
border-left: 2px solid #ccc;
padding: 1em;
}
blockquote {
color: #666;
line-height: 1.3em;
}
pre {
line-height: normal;
overflow: auto;
}
pre.code-block {
padding-bottom: 0;
}
tt, pre, code, samp, kbd {
color: #333;
font-family: Consolas, 'Lucida Console', monospace;
font-size: 13px;
}
label em {
font-weight: normal;
}
form {
margin: 0;
padding: 0;
}
.code-block .err { border: 1px solid #FF0000 } /* Error */
.code-block .k,.kn { color: #369 } /* Keywords */
.code-block .c,.cm,.cp,.c1 { color: #666; font-style: italic } /* Comments */
.code-block .n { color: #000 } /* Names */
.code-block .p { color: #000 } /* Punctuation */
.code-block .nc,.nf,.nn { color: #333; font-weight: bold } /* Symbol Names */
.code-block .s { color: #933 } /* Literal.String */
.code-block .sd { color: #666 } /* Literal.String.Doc */
</style>
</head>
<body>
<div class="document" id="the-log-package">
<h1 class="title">The Log Package</h1>
<h2 class="subtitle" id="user-documentation">User Documentation</h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Author:</th><td class="field-body">Jon Parise</td>
</tr>
<tr class="field"><th class="field-name">Contact:</th><td class="field-body"><a class="reference external" href="mailto:jon%40php.net">jon<span>@</span>php<span>.</span>net</a></td>
</tr>
</tbody>
</table>
<div class="contents topic" id="contents">
<p class="topic-title first">Contents</p>
<ul class="auto-toc simple">
<li><a class="reference internal" href="#using-log-handlers" id="id25">1 Using Log Handlers</a><ul class="auto-toc">
<li><a class="reference internal" href="#creating-a-log-object" id="id26">1.1 Creating a Log Object</a><ul class="auto-toc">
<li><a class="reference internal" href="#the-factory-method" id="id27">1.1.1 The Factory Method</a></li>
<li><a class="reference internal" href="#the-singleton-method" id="id28">1.1.2 The Singleton Method</a></li>
<li><a class="reference internal" href="#direct-instantiation" id="id29">1.1.3 Direct Instantiation</a></li>
</ul>
</li>
<li><a class="reference internal" href="#configuring-a-handler" id="id30">1.2 Configuring a Handler</a></li>
<li><a class="reference internal" href="#logging-an-event" id="id31">1.3 Logging an Event</a></li>
<li><a class="reference internal" href="#log-levels" id="id32">1.4 Log Levels</a></li>
<li><a class="reference internal" href="#log-level-masks" id="id33">1.5 Log Level Masks</a></li>
<li><a class="reference internal" href="#log-line-format" id="id34">1.6 Log Line Format</a></li>
<li><a class="reference internal" href="#flushing-log-events" id="id35">1.7 Flushing Log Events</a></li>
</ul>
</li>
<li><a class="reference internal" href="#standard-log-handlers" id="id36">2 Standard Log Handlers</a><ul class="auto-toc">
<li><a class="reference internal" href="#the-console-handler" id="id37">2.1 The Console Handler</a><ul class="auto-toc">
<li><a class="reference internal" href="#configuration" id="id38">2.1.1 Configuration</a></li>
<li><a class="reference internal" href="#example" id="id39">2.1.2 Example</a></li>
</ul>
</li>
<li><a class="reference internal" href="#the-display-handler" id="id40">2.2 The Display Handler</a><ul class="auto-toc">
<li><a class="reference internal" href="#id2" id="id41">2.2.1 Configuration</a></li>
<li><a class="reference internal" href="#id3" id="id42">2.2.2 Example</a></li>
</ul>
</li>
<li><a class="reference internal" href="#the-error-log-handler" id="id43">2.3 The Error_Log Handler</a><ul class="auto-toc">
<li><a class="reference internal" href="#id4" id="id44">2.3.1 Configuration</a></li>
<li><a class="reference internal" href="#error-log-types" id="id45">2.3.2 Error_Log Types</a></li>
<li><a class="reference internal" href="#id5" id="id46">2.3.3 Example</a></li>
</ul>
</li>
<li><a class="reference internal" href="#the-file-handler" id="id47">2.4 The File Handler</a><ul class="auto-toc">
<li><a class="reference internal" href="#id6" id="id48">2.4.1 Configuration</a></li>
<li><a class="reference internal" href="#id8" id="id49">2.4.2 Example</a></li>
</ul>
</li>
<li><a class="reference internal" href="#the-firebug-handler" id="id50">2.5 The Firebug Handler</a><ul class="auto-toc">
<li><a class="reference internal" href="#id9" id="id51">2.5.1 Configuration</a></li>
<li><a class="reference internal" href="#id11" id="id52">2.5.2 Example</a></li>
</ul>
</li>
<li><a class="reference internal" href="#the-mail-handler" id="id53">2.6 The Mail Handler</a><ul class="auto-toc">
<li><a class="reference internal" href="#id12" id="id54">2.6.1 Configuration</a></li>
<li><a class="reference internal" href="#id14" id="id55">2.6.2 Example</a></li>
</ul>
</li>
<li><a class="reference internal" href="#the-mdb2-handler" id="id56">2.7 The MDB2 Handler</a><ul class="auto-toc">
<li><a class="reference internal" href="#id15" id="id57">2.7.1 Configuration</a></li>
</ul>
</li>
<li><a class="reference internal" href="#the-null-handler" id="id58">2.8 The Null Handler</a><ul class="auto-toc">
<li><a class="reference internal" href="#id16" id="id59">2.8.1 Example</a></li>
</ul>
</li>
<li><a class="reference internal" href="#the-sql-db-handler" id="id60">2.9 The SQL (DB) Handler</a><ul class="auto-toc">
<li><a class="reference internal" href="#the-log-table" id="id61">2.9.1 The Log Table</a></li>
<li><a class="reference internal" href="#id17" id="id62">2.9.2 Configuration</a></li>
<li><a class="reference internal" href="#examples" id="id63">2.9.3 Examples</a></li>
</ul>
</li>
<li><a class="reference internal" href="#the-sqlite-handler" id="id64">2.10 The Sqlite Handler</a><ul class="auto-toc">
<li><a class="reference internal" href="#id18" id="id65">2.10.1 Configuration</a></li>
<li><a class="reference internal" href="#id19" id="id66">2.10.2 Examples</a></li>
</ul>
</li>
<li><a class="reference internal" href="#the-syslog-handler" id="id67">2.11 The Syslog Handler</a><ul class="auto-toc">
<li><a class="reference internal" href="#id20" id="id68">2.11.1 Configuration</a></li>
<li><a class="reference internal" href="#facilities" id="id69">2.11.2 Facilities</a></li>
<li><a class="reference internal" href="#id21" id="id70">2.11.3 Example</a></li>
</ul>
</li>
<li><a class="reference internal" href="#the-window-handler" id="id71">2.12 The Window Handler</a><ul class="auto-toc">
<li><a class="reference internal" href="#id22" id="id72">2.12.1 Configuration</a></li>
<li><a class="reference internal" href="#id23" id="id73">2.12.2 Example</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#composite-handlers" id="id74">3 Composite Handlers</a></li>
<li><a class="reference internal" href="#log-observers" id="id75">4 Log Observers</a></li>
<li><a class="reference internal" href="#logging-from-standard-error-handlers" id="id76">5 Logging From Standard Error Handlers</a><ul class="auto-toc">
<li><a class="reference internal" href="#logging-php-errors" id="id77">5.1 Logging PHP Errors</a></li>
<li><a class="reference internal" href="#logging-php-assertions" id="id78">5.2 Logging PHP Assertions</a></li>
<li><a class="reference internal" href="#logging-php-exceptions" id="id79">5.3 Logging PHP Exceptions</a></li>
<li><a class="reference internal" href="#logging-pear-errors" id="id80">5.4 Logging PEAR Errors</a></li>
</ul>
</li>
<li><a class="reference internal" href="#custom-handlers" id="id81">6 Custom Handlers</a><ul class="auto-toc">
<li><a class="reference internal" href="#using-a-custom-handler" id="id82">6.1 Using a Custom Handler</a><ul class="auto-toc">
<li><a class="reference internal" href="#method-1-handler-in-the-standard-location" id="id83">6.1.1 Method 1: Handler in the Standard Location</a></li>
<li><a class="reference internal" href="#method-2-handler-in-a-custom-location" id="id84">6.1.2 Method 2: Handler in a Custom Location</a></li>
</ul>
</li>
<li><a class="reference internal" href="#writing-new-handlers" id="id85">6.2 Writing New Handlers</a></li>
<li><a class="reference internal" href="#extending-existing-handlers" id="id86">6.3 Extending Existing Handlers</a></li>
<li><a class="reference internal" href="#handler-methods" id="id87">6.4 Handler Methods</a><ul class="auto-toc">
<li><a class="reference internal" href="#bool-open" id="id88">6.4.1 bool open()</a></li>
<li><a class="reference internal" href="#bool-close" id="id89">6.4.2 bool close()</a></li>
<li><a class="reference internal" href="#bool-flush" id="id90">6.4.3 bool flush()</a></li>
<li><a class="reference internal" href="#bool-log-message-priority-null" id="id91">6.4.4 bool log($message, $priority = null)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#utility-methods" id="id92">6.5 Utility Methods</a><ul class="auto-toc">
<li><a class="reference internal" href="#string-extractmessage-message" id="id93">6.5.1 string _extractMessage($message)</a></li>
<li><a class="reference internal" href="#string-format-format-timestamp-priority-message" id="id94">6.5.2 string _format($format, $timestamp, $priority, $message)</a></li>
<li><a class="reference internal" href="#bool-ismasked-priority" id="id95">6.5.3 bool _isMasked($priority)</a></li>
<li><a class="reference internal" href="#void-announce-event" id="id96">6.5.4 void _announce($event)</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="using-log-handlers">
<h2>1 Using Log Handlers</h2>
<p>The Log package is implemented as a framework that supports the notion of
backend-specific log handlers. The base logging object (defined by the <a class="reference external" href="http://cvs.php.net/viewvc.cgi/pear/Log/Log.php">Log
class</a>) is primarily an abstract interface to the currently configured
handler.</p>
<p>A wide variety of handlers are distributed with the Log package, and, should
none of them fit your application's needs, it's easy to <a class="reference internal" href="#custom-handlers">write your own</a>.</p>
<div class="section" id="creating-a-log-object">
<h3>1.1 Creating a Log Object</h3>
<p>There are three ways to create Log objects:</p>
<blockquote>
<ul class="simple">
<li>Using the <tt class="docutils literal"><span class="pre">Log::factory()</span></tt> method</li>
<li>Using the <tt class="docutils literal"><span class="pre">Log::singleton()</span></tt> method</li>
<li>Direct instantiation</li>
</ul>
</blockquote>
<div class="section" id="the-factory-method">
<h4>1.1.1 The Factory Method</h4>
<p>The <tt class="docutils literal"><span class="pre">Log::factory()</span></tt> method implements the <a class="reference external" href="http://wikipedia.org/wiki/Factory_method_pattern">Factory Pattern</a>. It allows
for the parameterized construction of concrete Log instances at runtime. The
first parameter to the <tt class="docutils literal"><span class="pre">Log::factory()</span></tt> method indicates the name of the
concrete handler to create. The rest of the parameters will be passed on to
the handler's constructor (see <a class="reference internal" href="#configuring-a-handler">Configuring a Handler</a> below).</p>
<p>The new <tt class="docutils literal">Log</tt> instance is returned by reference.</p>
<pre class="literal-block">
require_once 'Log.php';
$console = Log::factory('console', '', 'TEST');
$console->log('Logging to the console.');
$file = Log::factory('file', 'out.log', 'TEST');
$file->log('Logging to out.log.');
</pre>
</div>
<div class="section" id="the-singleton-method">
<h4>1.1.2 The Singleton Method</h4>
<p>The <tt class="docutils literal"><span class="pre">Log::singleton()</span></tt> method implements the <a class="reference external" href="http://wikipedia.org/wiki/Singleton_pattern">Singleton Pattern</a>. The
singleton pattern ensures that only a single instance of a given log type and
configuration is ever created. This has two benefits: first, it prevents
duplicate <tt class="docutils literal">Log</tt> instances from being constructed, and, second, it gives all
of your code access to the same <tt class="docutils literal">Log</tt> instance. The latter is especially
important when logging to files because only a single file handler will need
to be managed.</p>
<p>The <tt class="docutils literal"><span class="pre">Log::singleton()</span></tt> method's parameters match the <tt class="docutils literal"><span class="pre">Log::factory()</span></tt>
method. The new <tt class="docutils literal">Log</tt> instance is returned by reference.</p>
<pre class="literal-block">
require_once 'Log.php';
/* Same construction parameters */
$a = Log::singleton('console', '', 'TEST');
$b = Log::singleton('console', '', 'TEST');
if ($a === $b) {
echo '$a and $b point to the same Log instance.' . "\n";
}
/* Different construction parameters */
$c = Log::singleton('console', '', 'TEST1');
$d = Log::singleton('console', '', 'TEST2');
if ($c !== $d) {
echo '$c and $d point to different Log instances.' . "\n";
}
</pre>
</div>
<div class="section" id="direct-instantiation">
<h4>1.1.3 Direct Instantiation</h4>
<p>It is also possible to directly instantiate concrete <tt class="docutils literal">Log</tt> handler
instances. However, this method is <strong>not recommended</strong> because it creates a
tighter coupling between your application code and the Log package than is
necessary. Use of <a class="reference internal" href="#the-factory-method">the factory method</a> or <a class="reference internal" href="#the-singleton-method">the singleton method</a> is
preferred.</p>
</div>
</div>
<div class="section" id="configuring-a-handler">
<h3>1.2 Configuring a Handler</h3>
<p>A log handler's configuration is determined by the arguments used in its
construction. Here's an overview of those parameters:</p>
<pre class="literal-block">
/* Using the factory method ... */
Log::factory($handler, $name, $ident, $conf, $maxLevel);
/* Using the singleton method ... */
Log::singleton($handler, $name, $ident, $conf, $maxLevel);
/* Using direct instantiation ... */
new Log_handler($name, $ident, $conf, $maxLevel);
</pre>
<table border="1" class="docutils">
<colgroup>
<col width="21%" />
<col width="15%" />
<col width="64%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Parameter</th>
<th class="head">Type</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><tt class="docutils literal">$handler</tt></td>
<td>String</td>
<td>The type of Log handler to construct. This
parameter is only available when <a class="reference internal" href="#the-factory-method">the factory
method</a> or <a class="reference internal" href="#the-singleton-method">the singleton method</a> are used.</td>
</tr>
<tr><td><tt class="docutils literal">$name</tt></td>
<td>String</td>
<td>The name of the log resource to which the
events will be logged. The use of this value
is determined by the handler's implementation.
It defaults to an empty string.</td>
</tr>
<tr><td><tt class="docutils literal">$ident</tt></td>
<td>String</td>
<td>An identification string that will be included
in all log events logged by this handler.
This value defaults to an empty string and can
be changed at runtime using the <tt class="docutils literal">setIdent()</tt>
method.</td>
</tr>
<tr><td><tt class="docutils literal">$conf</tt></td>
<td>Array</td>
<td>Associative array of key-value pairs that are
used to specify any handler-specific settings.</td>
</tr>
<tr><td><tt class="docutils literal">$level</tt></td>
<td>Integer</td>
<td>Log messages up to and including this level.
This value defaults to <tt class="docutils literal">PEAR_LOG_DEBUG</tt>.
See <a class="reference internal" href="#log-levels">Log Levels</a> and <a class="reference internal" href="#log-level-masks">Log Level Masks</a>.</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="logging-an-event">
<h3>1.3 Logging an Event</h3>
<p>Events are logged using the <tt class="docutils literal">log()</tt> method:</p>
<pre class="literal-block">
$logger->log('Message', PEAR_LOG_NOTICE);
</pre>
<p>The first argument contains the log event's message. Even though the event is
always logged as a string, it is possible to pass an object to the <tt class="docutils literal">log()</tt>
method. If the object implements a <tt class="docutils literal">getString()</tt> method, a <tt class="docutils literal">toString()</tt>
method or Zend Engine 2's special <tt class="docutils literal">__toString()</tt> casting method, it will be
used to determine the object's string representation. Otherwise, the
<a class="reference external" href="http://www.php.net/serialize">serialized</a> form of the object will be logged.</p>
<p>The second, optional argument specifies the log event's priority. See the
<a class="reference internal" href="#log-levels">Log Levels</a> table for the complete list of priorities. The default priority
is PEAR_LOG_INFO.</p>
<p>The <tt class="docutils literal">log()</tt> method will return <tt class="docutils literal">true</tt> if the event was successfully
logged.</p>
<p>"Shortcut" methods are also available for logging an event at a specific log
level. See the <a class="reference internal" href="#log-levels">Log Levels</a> table for the complete list.</p>
</div>
<div class="section" id="log-levels">
<h3>1.4 Log Levels</h3>
<p>This table is ordered by highest priority (<tt class="docutils literal">PEAR_LOG_EMERG</tt>) to lowest
priority (<tt class="docutils literal">PEAR_LOG_DEBUG</tt>).</p>
<table border="1" class="docutils">
<colgroup>
<col width="32%" />
<col width="21%" />
<col width="48%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Level</th>
<th class="head">Shortcut</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><tt class="docutils literal">PEAR_LOG_EMERG</tt></td>
<td><tt class="docutils literal">emerg()</tt></td>
<td>System is unusable</td>
</tr>
<tr><td><tt class="docutils literal">PEAR_LOG_ALERT</tt></td>
<td><tt class="docutils literal">alert()</tt></td>
<td>Immediate action required</td>
</tr>
<tr><td><tt class="docutils literal">PEAR_LOG_CRIT</tt></td>
<td><tt class="docutils literal">crit()</tt></td>
<td>Critical conditions</td>
</tr>
<tr><td><tt class="docutils literal">PEAR_LOG_ERR</tt></td>
<td><tt class="docutils literal">err()</tt></td>
<td>Error conditions</td>
</tr>
<tr><td><tt class="docutils literal">PEAR_LOG_WARNING</tt></td>
<td><tt class="docutils literal">warning()</tt></td>
<td>Warning conditions</td>
</tr>
<tr><td><tt class="docutils literal">PEAR_LOG_NOTICE</tt></td>
<td><tt class="docutils literal">notice()</tt></td>
<td>Normal but significant</td>
</tr>
<tr><td><tt class="docutils literal">PEAR_LOG_INFO</tt></td>
<td><tt class="docutils literal">info()</tt></td>
<td>Informational</td>
</tr>
<tr><td><tt class="docutils literal">PEAR_LOG_DEBUG</tt></td>
<td><tt class="docutils literal">debug()</tt></td>
<td>Debug-level messages</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="log-level-masks">
<h3>1.5 Log Level Masks</h3>
<p>Defining a log level mask allows you to include and/or exclude specific levels
of events from being logged. The <tt class="docutils literal">$level</tt> construction parameter (see
<a class="reference internal" href="#configuring-a-handler">Configuring a Handler</a>) uses this mechanism to exclude log events below a
certain priority, and it's possible to define more complex masks once the Log
object has been constructed.</p>
<p>Each priority has a specific mask associated with it. To compute a priority's
mask, use the static <tt class="docutils literal"><span class="pre">Log::MASK()</span></tt> method:</p>
<pre class="literal-block">
$mask = Log::MASK(PEAR_LOG_INFO);
</pre>
<p>To compute the mask for all priorities up to, and including, a certain level,
use the <tt class="docutils literal"><span class="pre">Log::MAX()</span></tt> static method:</p>
<pre class="literal-block">
$mask = Log::MAX(PEAR_LOG_INFO);
</pre>
<p>To compute the mask for all priorities greater than or equal to a certain
level, use the <tt class="docutils literal"><span class="pre">Log::MIN()</span></tt> static method:</p>
<pre class="literal-block">
$mask = Log::MIN(PEAR_LOG_INFO);
</pre>
<p>The apply the mask, use the <tt class="docutils literal">setMask()</tt> method:</p>
<pre class="literal-block">
$logger->setMask($mask);
</pre>
<p>Masks can be be combined using bitwise operations. To restrict logging to
only those events marked as <tt class="docutils literal">PEAR_LOG_NOTICE</tt> or <tt class="docutils literal">PEAR_LOG_DEBUG</tt>:</p>
<pre class="literal-block">
$mask = Log::MASK(PEAR_LOG_NOTICE) | Log::MASK(PEAR_LOG_DEBUG);
$logger->setMask($mask);
</pre>
<p>For convenience, two special masks are predefined: <tt class="docutils literal">PEAR_LOG_NONE</tt> and
<tt class="docutils literal">PEAR_LOG_ALL</tt>. <tt class="docutils literal">PEAR_LOG_ALL</tt> is especially useful for excluding only
specific priorities:</p>
<pre class="literal-block">
$mask = PEAR_LOG_ALL ^ Log::MASK(PEAR_LOG_NOTICE);
$logger->setMask($mask);
</pre>
<p>It is also possible to retrieve and modify a Log object's existing mask:</p>
<pre class="literal-block">
$mask = $logger->getMask() | Log::MASK(PEAR_LOG_INFO);
$logger->setMask($mask);
</pre>
</div>
<div class="section" id="log-line-format">
<h3>1.6 Log Line Format</h3>
<p>Most log handlers support configurable line formats. The following is a list
of special tokens that will be expanded at runtime with contextual information
related to the log event. Each token has an alternate shorthand notation, as
well.</p>
<table border="1" class="docutils">
<colgroup>
<col width="25%" />
<col width="15%" />
<col width="60%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Token</th>
<th class="head">Alternate</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><tt class="docutils literal">%{timestamp}</tt></td>
<td><tt class="docutils literal">%1$s</tt></td>
<td>Timestamp. This is often configurable.</td>
</tr>
<tr><td><tt class="docutils literal">%{ident}</tt></td>
<td><tt class="docutils literal">%2$s</tt></td>
<td>The log handler's identification string.</td>
</tr>
<tr><td><tt class="docutils literal">%{priority}</tt></td>
<td><tt class="docutils literal">%3$s</tt></td>
<td>The log event's priority.</td>
</tr>
<tr><td><tt class="docutils literal">%{message}</tt></td>
<td><tt class="docutils literal">%4$s</tt></td>
<td>The log event's message text.</td>
</tr>
<tr><td><tt class="docutils literal">%{file}</tt></td>
<td><tt class="docutils literal">%5$s</tt></td>
<td>The full filename of the logging file.</td>
</tr>
<tr><td><tt class="docutils literal">%{line}</tt></td>
<td><tt class="docutils literal">%6$s</tt></td>
<td>The line number on which the event occured.</td>
</tr>
<tr><td><tt class="docutils literal">%{function}</tt></td>
<td><tt class="docutils literal">%7$s</tt></td>
<td>The function from which the event occurred.</td>
</tr>
<tr><td><tt class="docutils literal">%{class}</tt></td>
<td><tt class="docutils literal">%8$s</tt></td>
<td>The class in which the event occurred.</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="flushing-log-events">
<h3>1.7 Flushing Log Events</h3>
<p>Some log handlers (such as <a class="reference internal" href="#the-console-handler">the console handler</a>) support explicit
"buffering". When buffering is enabled, log events won't actually be written
to the output stream until the handler is closed. Other handlers (such as
<a class="reference internal" href="#the-file-handler">the file handler</a>) support implicit buffering because they use the operating
system's IO routines, which may buffer the output.</p>
<p>It's possible to force these handlers to flush their output, however, by
calling their <tt class="docutils literal">flush()</tt> method:</p>
<pre class="literal-block">
$conf = array('buffering' => true);
$logger = Log::singleton('console', '', 'test', $conf);
for ($i = 0; $i < 10; $i++) {
$logger->log('This event will be buffered.');
}
/* Flush all of the buffered log events. */
$logger->flush();
for ($i = 0; $i < 10; $i++) {
$logger->log('This event will be buffered.');
}
/* Implicitly flush the buffered events on close. */
$logger->close();
</pre>
<p>At this time, the <tt class="docutils literal">flush()</tt> method is only implemented by <a class="reference internal" href="#the-console-handler">the console
handler</a>, <a class="reference internal" href="#the-file-handler">the file handler</a>, <a class="reference internal" href="#the-firebug-handler">the Firebug handler</a>, and <a class="reference internal" href="#the-mail-handler">the mail
handler</a>.</p>
</div>
</div>
<div class="section" id="standard-log-handlers">
<h2>2 Standard Log Handlers</h2>
<div class="section" id="the-console-handler">
<h3>2.1 The Console Handler</h3>
<p>The Console handler outputs log events directly to the console. It supports
output buffering and configurable string formats.</p>
<div class="section" id="configuration">
<h4>2.1.1 Configuration</h4>
<table border="1" class="docutils">
<colgroup>
<col width="26%" />
<col width="15%" />
<col width="21%" />
<col width="38%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Parameter</th>
<th class="head">Type</th>
<th class="head">Default</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><tt class="docutils literal">stream</tt></td>
<td>File</td>
<td><a class="reference external" href="http://www.php.net/wrappers.php">STDOUT</a></td>
<td>The output stream to use.</td>
</tr>
<tr><td><tt class="docutils literal">buffering</tt></td>
<td>Boolean</td>
<td>False</td>
<td>Should the output be
buffered until shutdown?</td>
</tr>
<tr><td><tt class="docutils literal">lineFormat</tt></td>
<td>String</td>
<td><tt class="docutils literal">%1$s %2$s
[%3$s] %4$s</tt></td>
<td><a class="reference internal" href="#log-line-format">Log line format</a>
specification.</td>
</tr>
<tr><td><tt class="docutils literal">timeFormat</tt></td>
<td>String</td>
<td><tt class="docutils literal">%b %d
<span class="pre">%H:%M:%S</span></tt></td>
<td>Time stamp format
(for <a class="reference external" href="http://www.php.net/strftime">strftime</a>).</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="example">
<h4>2.1.2 Example</h4>
<pre class="literal-block">
$logger = Log::singleton('console', '', 'ident');
for ($i = 0; $i < 10; $i++) {
$logger->log("Log entry $i");
}
</pre>
</div>
</div>
<div class="section" id="the-display-handler">
<h3>2.2 The Display Handler</h3>
<p>The Display handler simply prints the log events back to the browser. It
respects the <tt class="docutils literal">error_prepend_string</tt> and <tt class="docutils literal">error_append_string</tt> <a class="reference external" href="http://www.php.net/errorfunc">error
handling values</a> and is useful when <a class="reference internal" href="#logging-from-standard-error-handlers">logging from standard error handlers</a>.</p>
<div class="section" id="id2">
<h4>2.2.1 Configuration</h4>
<table border="1" class="docutils">
<colgroup>
<col width="26%" />
<col width="15%" />
<col width="21%" />
<col width="38%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Parameter</th>
<th class="head">Type</th>
<th class="head">Default</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><tt class="docutils literal">lineFormat</tt></td>
<td>String</td>
<td><tt class="docutils literal"><span class="pre"><b>%3$s</b>:</span>
%4$s</tt></td>
<td><a class="reference internal" href="#log-line-format">Log line format</a>
specification.</td>
</tr>
<tr><td><tt class="docutils literal">timeFormat</tt></td>
<td>String</td>
<td><tt class="docutils literal">%b %d
<span class="pre">%H:%M:%S</span></tt></td>
<td>Time stamp format
(for <a class="reference external" href="http://www.php.net/strftime">strftime</a>).</td>
</tr>
<tr><td><tt class="docutils literal">error_prepend</tt></td>
<td>String</td>
<td>PHP INI value</td>
<td>This string will be
prepended to the line
format.</td>
</tr>
<tr><td><tt class="docutils literal">error_append</tt></td>
<td>String</td>
<td>PHP INI value</td>
<td>This string will be
appended to the line
format.</td>
</tr>
<tr><td><tt class="docutils literal">linebreak</tt></td>
<td>String</td>
<td><tt class="docutils literal"><br <span class="pre">/>\n</span></tt></td>
<td>This string is used to
represent a line break.</td>
</tr>
<tr><td><tt class="docutils literal">rawText</tt></td>
<td>Boolean</td>
<td>False</td>
<td>Should message text be
passed directly to the log
system? Otherwise, it
will be converted to an
HTML-safe representation.</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="id3">
<h4>2.2.2 Example</h4>
<pre class="literal-block">
$conf = array('error_prepend' => '<font color="#ff0000"><tt>',
'error_append' => '</tt></font>');
$logger = Log::singleton('display', '', '', $conf, PEAR_LOG_DEBUG);
for ($i = 0; $i < 10; $i++) {
$logger->log("Log entry $i");
}
</pre>
</div>
</div>
<div class="section" id="the-error-log-handler">
<h3>2.3 The Error_Log Handler</h3>
<p>The Error_Log handler sends log events to PHP's <a class="reference external" href="http://www.php.net/error_log">error_log()</a> function.</p>
<div class="section" id="id4">
<h4>2.3.1 Configuration</h4>
<table border="1" class="docutils">
<colgroup>
<col width="26%" />
<col width="15%" />
<col width="21%" />
<col width="38%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Parameter</th>
<th class="head">Type</th>
<th class="head">Default</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><tt class="docutils literal">destination</tt></td>
<td>String</td>
<td>'' <cite>(empty)</cite></td>
<td>Optional destination value
for <a class="reference external" href="http://www.php.net/error_log">error_log()</a>. See
<a class="reference internal" href="#error-log-types">Error_Log Types</a> for
more details.</td>
</tr>
<tr><td><tt class="docutils literal">extra_headers</tt></td>
<td>String</td>
<td>'' <cite>(empty)</cite></td>
<td>Additional headers to pass
to the <a class="reference external" href="http://www.php.net/mail">mail()</a> function
when the
<tt class="docutils literal">PEAR_LOG_TYPE_MAIL</tt>
type is specified.</td>
</tr>
<tr><td><tt class="docutils literal">lineFormat</tt></td>
<td>String</td>
<td><tt class="docutils literal">%2$s: %4$s</tt></td>
<td><a class="reference internal" href="#log-line-format">Log line format</a>
specification.</td>
</tr>
<tr><td><tt class="docutils literal">timeFormat</tt></td>
<td>String</td>
<td><tt class="docutils literal">%b %d
<span class="pre">%H:%M:%S</span></tt></td>
<td>Time stamp format
(for <a class="reference external" href="http://www.php.net/strftime">strftime</a>).</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="error-log-types">
<h4>2.3.2 Error_Log Types</h4>
<p>All of the available log types are detailed in the <a class="reference external" href="http://www.php.net/error_log">error_log()</a> section of
the PHP manual. For your convenience, the Log package also defines the
following constants that can be used for the <tt class="docutils literal">$name</tt> handler construction
parameter.</p>
<table border="1" class="docutils">
<colgroup>
<col width="36%" />
<col width="64%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Constant</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><tt class="docutils literal">PEAR_LOG_TYPE_SYSTEM</tt></td>
<td>Log events are sent to PHP's system logger,
which uses the operating system's logging
mechanism or a file (depending on the value
of the <a class="reference external" href="http://www.php.net/errorfunc#ini.error-log">error_log configuration directive</a>).</td>
</tr>
<tr><td><tt class="docutils literal">PEAR_LOG_TYPE_MAIL</tt></td>
<td>Log events are sent via email to the address
specified in the <tt class="docutils literal">destination</tt> value.</td>
</tr>
<tr><td><tt class="docutils literal">PEAR_LOG_TYPE_DEBUG</tt></td>
<td>Log events are sent through PHP's debugging
connection. This will only work if
<a class="reference external" href="http://www.php.net/install.configure#install.configure.enable-debugger">remote debugging</a> has been enabled. The
<tt class="docutils literal">destination</tt> value is used to specify the
host name or IP address of the target socket.</td>
</tr>
<tr><td><tt class="docutils literal">PEAR_LOG_TYPE_FILE</tt></td>
<td>Log events will be appended to the file named
by the <tt class="docutils literal">destination</tt> value.</td>
</tr>
<tr><td><tt class="docutils literal">PEAR_LOG_TYPE_SAPI</tt></td>
<td>Log events will be sent directly to the SAPI
logging handler.</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="id5">
<h4>2.3.3 Example</h4>
<pre class="literal-block">
$logger = Log::singleton('error_log', PEAR_LOG_TYPE_SYSTEM, 'ident');
for ($i = 0; $i < 10; $i++) {
$logger->log("Log entry $i");
}
</pre>
</div>
</div>
<div class="section" id="the-file-handler">
<h3>2.4 The File Handler</h3>
<p>The File handler writes log events to a text file using configurable string
formats.</p>
<div class="section" id="id6">
<h4>2.4.1 Configuration</h4>
<table border="1" class="docutils">
<colgroup>
<col width="26%" />
<col width="15%" />
<col width="21%" />
<col width="38%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Parameter</th>
<th class="head">Type</th>
<th class="head">Default</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><tt class="docutils literal">append</tt></td>
<td>Boolean</td>
<td>True</td>
<td>Should new log entries be
append to an existing log
file, or should the a new
log file overwrite an
existing one?</td>
</tr>
<tr><td><tt class="docutils literal">locking</tt></td>
<td>Boolean</td>
<td>False</td>
<td>Should advisory file
locking (using <a class="reference external" href="http://www.php.net/flock">flock</a>) be
used?</td>
</tr>
<tr><td><tt class="docutils literal">mode</tt></td>
<td>Integer</td>
<td>0644</td>
<td>Octal representation of
the log file's permissions
mode.</td>
</tr>
<tr><td><tt class="docutils literal">dirmode</tt></td>
<td>Integer</td>
<td>0755</td>
<td>Octal representation of
the file permission mode
that will be used when
creating directories that
do not already exist.</td>
</tr>
<tr><td><tt class="docutils literal">eol</tt></td>
<td>String</td>
<td>OS default</td>
<td>The end-of-line character
sequence.</td>
</tr>
<tr><td><tt class="docutils literal">lineFormat</tt></td>
<td>String</td>
<td><tt class="docutils literal">%1$s %2$s
[%3$s] %4$s</tt></td>
<td><a class="reference internal" href="#log-line-format">Log line format</a>
specification.</td>
</tr>
<tr><td><tt class="docutils literal">timeFormat</tt></td>
<td>String</td>
<td><tt class="docutils literal">%b %d
<span class="pre">%H:%M:%S</span></tt></td>
<td>Time stamp format
(for <a class="reference external" href="http://www.php.net/strftime">strftime</a>).</td>
</tr>
</tbody>
</table>
<p>The file handler will only attempt to set the <tt class="docutils literal">mode</tt> value if it was
responsible for creating the file.</p>
</div>
<div class="section" id="id8">
<h4>2.4.2 Example</h4>
<pre class="literal-block">
$conf = array('mode' => 0600, 'timeFormat' => '%X %x');
$logger = Log::singleton('file', 'out.log', 'ident', $conf);
for ($i = 0; $i < 10; $i++) {
$logger->log("Log entry $i");
}
</pre>
</div>
</div>
<div class="section" id="the-firebug-handler">
<h3>2.5 The Firebug Handler</h3>
<p>The Firebug handler outputs log events to the <a class="reference external" href="http://www.getfirebug.com/">Firebug</a> console. It supports
output buffering and configurable string formats.</p>
<div class="section" id="id9">
<h4>2.5.1 Configuration</h4>
<table border="1" class="docutils">
<colgroup>
<col width="26%" />
<col width="15%" />
<col width="21%" />
<col width="38%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Parameter</th>
<th class="head">Type</th>
<th class="head">Default</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr><td><tt class="docutils literal">buffering</tt></td>
<td>Boolean</td>
<td>False</td>
<td>Should the output be
buffered until shutdown?</td>
</tr>
<tr><td><tt class="docutils literal">lineFormat</tt></td>
<td>String</td>
<td><tt class="docutils literal">%2$s [%3$s]
%4$s</tt></td>
<td><a class="reference internal" href="#log-line-format">Log line format</a>
specification.</td>
</tr>
<tr><td><tt class="docutils literal">timeFormat</tt></td>
<td>String</td>
<td><tt class="docutils literal">%b %d
<span class="pre">%H:%M:%S</span></tt></td>
<td>Time stamp format
(for <a class="reference external" href="http://www.php.net/strftime">strftime</a>).</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="id11">
<h4>2.5.2 Example</h4>
<pre class="literal-block">
$logger = Log::singleton('firebug', '', 'ident');
for ($i = 0; $i < 10; $i++) {
$logger->log("Log entry $i");
}
</pre>
</div>
</div>
<div class="section" id="the-mail-handler">
<h3>2.6 The Mail Handler</h3>
<p>The Mail handler aggregates a session's log events and sends them in the body
of an email message using either the <a class="reference external" href="http://pear.php.net/package/Mail">PEAR Mail</a> package or PHP's native
<a class="reference external" href="http://www.php.net/mail">mail()</a> function.</p>
<p>If an empty <tt class="docutils literal">mailBackend</tt> value is specified, the <a class="reference external" href="http://www.php.net/mail">mail()</a> function will be
used instead of the <a class="reference external" href="http://pear.php.net/package/Mail">PEAR Mail</a> package.</p>
<p>Multiple recipients can be specified by separating their email addresses with
commas in the <tt class="docutils literal">$name</tt> construction parameter.</p>
<div class="section" id="id12">
<h4>2.6.1 Configuration</h4>
<table border="1" class="docutils">
<colgroup>
<col width="26%" />
<col width="15%" />