File: whitepaper.html

package info (click to toggle)
logkit 1.0.1-1
  • links: PTS
  • area: contrib
  • in suites: woody
  • size: 740 kB
  • ctags: 892
  • sloc: java: 4,673; xml: 1,281; makefile: 42; sql: 31
file content (779 lines) | stat: -rw-r--r-- 26,238 bytes parent folder | download
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
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>LogKit Developer Documentation</title>
</head>
<body bgcolor="#ffffff" marginheight="4" marginwidth="4" leftmargin="4" topmargin="4" alink="#023264" vlink="#023264" link="#525D76" text="#000000">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top"><a href="http://jakarta.apache.org/index.html"><img src="images/jakarta-logo.gif" border="0" vspace="0" hspace="0"></a></td><td bgcolor="#ffffff" align="left" valign="top" width="100%"><img src="images/header.gif" align="right" border="0" vspace="0" hspace="0"></td>
</tr>
<tr>
<td colspan="2" height="2" width="100%">
<hr size="1" noshade="">
</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td valign="top" width="1%"></td><td nowrap="1" valign="top" width="14%">
<br>
<font face="arial,helvetica,sanserif">
<br>
<br>
<a href="http://jakarta.apache.org/avalon"><font size="+1" color="#F3510C">Back to Avalon</font></a>
<br>
<br>
<font size="+1" color="#000000">About</font>
<br>
<font size="-1">
<ul>
<li>
<a href="index.html"><font size="-1">Overview</font></a>
</li>
<li>
<a href="features.html"><font size="-1">Features</font></a>
</li>
<li>
<a href="http://jakarta.apache.org/builds/jakarta-avalon/release/logkit/latest"><font size="-1">Download</font></a>
</li>
<li>
<a href="whitepaper.html"><font size="-1">Whitepaper</font></a>
</li>
<li>
<a href="changes.html"><font size="-1">Changes</font></a>
</li>
<li>
<a href="http://jakarta.apache.org/avalon/logkit/api/index.html"><font size="-1">API Docs</font></a>
</li>
</ul>
</font>
<br>
<br>
</font></td><td align="left" valign="top" width="*">
<title>LogKit Developer Documentation</title>
<center>
<table width="80%">
<tr>
<td bgcolor="#F3DD61">
<br>
<center>
<b><font face="arial,helvetica,sanserif" color="#000000">LogKit Developer Documentation</font></b>
</center>
<br>
</td>
</tr>
</table>
</center>
<br>
<font size="-2" face="arial,helvetica,sanserif" color="#000000">
<p>
<a href="mailto:"></a>
</p>
</font><font face="arial,helvetica,sanserif" color="#000000"></font>
<br>
<div align="right">
<table cellspacing="0" cellpadding="2" border="0" width="100%">
<tr>
<td bgcolor="#525D76"><font face="arial,helvetica,sanserif" color="#ffffff" size="+1"><b>Abstract</b></font></td>
</tr>
<tr>
<td><font face="arial,helvetica,sanserif" color="#000000">
<br>
      
<p align="justify">
        Logging is an integral component to any software development project. 
        During the development stages it offers a valuable source of debugging
        information for the developer. During deployment it can provide valuable
        operational data that allows administrators to diagnose problems as they 
        arise. This whitepaper describes the design and implementation of LogKit.
      </p>
    
</font></td>
</tr>
</table>
</div>
<br>
<div align="right">
<table cellspacing="0" cellpadding="2" border="0" width="100%">
<tr>
<td bgcolor="#525D76"><font face="arial,helvetica,sanserif" color="#ffffff" size="+1"><b>Introduction</b></font></td>
</tr>
<tr>
<td><font face="arial,helvetica,sanserif" color="#000000">
<br>

      
<p align="justify">
        LogKit, began life as a facade for a more complex logging toolkit. During
        development it was found that existing toolkits were complex and difficult 
        to use. A malformed logger configuration file could cause the whole system 
        to fail or the logging information to go into the void.
      </p>

      
<p align="justify">
        Over time it was discovered that the facade, while simple to use, inherited 
        many of the faults of the underlying logging toolkit. The logging was slow
        and was impossible to dynamically reconfigure. 
      </p>        
        
      
<p align="justify">
        At this time the whole system was overhauled. Existing logging toolkits
        were surveyed and user feedback was gathered from both developers and 
        administrators. The new toolkit focused on speed, reliability and dynamic
        reconfiguration. It then added, at that time unique features, for filtering
        log events, multiple listeners (aka LogTargets) per category and delayed
        serialization of events.
      </p>

    
</font></td>
</tr>
</table>
</div>
<br>
<div align="right">
<table cellspacing="0" cellpadding="2" border="0" width="100%">
<tr>
<td bgcolor="#525D76"><font face="arial,helvetica,sanserif" color="#ffffff" size="+1"><b>Structure and Elements</b></font></td>
</tr>
<tr>
<td><font face="arial,helvetica,sanserif" color="#000000">
<br>

      
<p align="justify">
        The most basic components of LogKit are the Logger, the LogEvent and the
        LogTarget. The Logger represents the client interface to the logging system.
        The developer interacts with Logger to generate LogEvents. The LogEvents 
        are routed to a LogTarget. The LogTarget decides what to do with the LogEvent,
        usually it is recorded to a file, a database or transmitted over the network.
      </p>
    
</font></td>
</tr>
</table>
</div>
<br>
<div align="right">
<table cellspacing="0" cellpadding="2" border="0" width="100%">
<tr>
<td bgcolor="#525D76"><font face="arial,helvetica,sanserif" color="#ffffff" size="+1"><b>Priorities</b></font></td>
</tr>
<tr>
<td><font face="arial,helvetica,sanserif" color="#000000">
<br>
      
<p align="justify">
        One of the advantages of a logging toolkit is fine grain control over which
        statements get printed. At some times during development you may wish to enable 
        all logging statements and at other times they may wish to disable debug 
        messages. It was from this need that the notion of of Priorities were born.
        A Priority describes the urgency of a LogEvent. Below is a list of priorities
        that are usable within the LogKit system (extracted from the constants of class
        org.apache.log.Priority).
      </p>

      
<ul>
        
<li>
          
<em>DEBUG:</em>
<p align="justify"></p>
          Developer oriented messages, usually used during development of the product.
        </li>
        
<li>
          
<em>INFO:</em>
<p align="justify"></p>
          Useful information messages such as state changes, client 
          connection, user login etc.
        </li>
        
<li>
          
<em>WARN:</em>
<p align="justify"></p>
          A problem or conflict has occurred but it may be recoverable, then 
          again it could be the start of the system failing.
        </li>
        
<li>
          
<em>ERROR:</em>
<p align="justify"></p>
          A problem has occurred but it is not fatal. The system will still function.
        </li>
        
<li>
          
<em>FATAL_ERROR:</em>
<p align="justify"></p>
          Something caused whole system to fail. This indicates that an administrator
          should restart the system and try to fix the problem that caused the failure.
        </li>
      
</ul>

      
<p align="justify">
        The range of priorities is limited by design as past experience has 
        indicated more levels do not offer any significant advantage to the 
        user.
      </p>

      
<p align="justify">
        Each logger instance is associated with a Priority. This allows you to limit
        each logger so that it only displays messages greater than a certain priority.
        So if a DEBUG message occurred and the logger's priority was WARN, the LogEvent
        would be suppressed.
      </p>

      
<p align="justify">
        A user can log at a certain priority by calling a method with matching name and
        the message as a string. For instance to log at debug level you would call
        logger.debug("My Message"). Similar methods exist for info(), warn() and error().
        There is also a set of similarly named methods that take both a message string 
        and an exception.
      </p>

      
<p align="justify">
        Where performance is critical it is often useful to check if a priority is
        enabled before constructing the message. In many cases the construction of
        the message is an expensive string operation and conversion operation. In this
        case it is useful to know before you create the message whether it will be 
        logged. The pattern of the method to check if a priority is enabled is 
        "is<em>Priority</em>Enabled()". An example use case is displayed below.
      </p>


<div align="center">
<table cellspacing="2" cellpadding="2" border="1">
<tr>
<td>
<pre>
if( logger.isDebugEnabled() )
{
  //Construct a message (expensive operation)
  final String message = "Var1 value: " + var1 + "\tVar2 value: " + var2 +
                         "\tVar3 value: " + var3 + ".";
  logger.debug( message );
}
</pre>
</td>
</tr>
</table>
</div>

    
</font></td>
</tr>
</table>
</div>
<br>
<div align="right">
<table cellspacing="0" cellpadding="2" border="0" width="100%">
<tr>
<td bgcolor="#525D76"><font face="arial,helvetica,sanserif" color="#ffffff" size="+1"><b>Categories</b></font></td>
</tr>
<tr>
<td><font face="arial,helvetica,sanserif" color="#000000">
<br>

      
<p align="justify">
        In a complex system it is often not enough to suppress logging based on priority.
        For instance you may wish to log the network subsystem with DEBUG priority while
        the simulator subsystem with WARN priority. To accomplish this LogKit uses a concept
        termed Categories. Categories, often called Channels, Subjects or Facilities, are
        a subdivision of the logging namespace. 
      </p>

      
<p align="justify">
        Each category is a name, made up of name components separated by a ".". So
        a category named "network.interceptor.connected" is made up of three name 
        components "network", "interceptor" and "connected", ordered from left to 
        right. Every logger is associated with a category at creation.
      </p>

      
<p align="justify">
        LogKit takes it one step further and assumes that the namespace is hierarchical.
        The left-most name component is the most generic category while the right-most
        name component is the most specific. So "network.interceptor.connected" is a child
        category of "network.interceptor", which is in turn a child category of "network".
        There is also a root category "" that is hidden inside the org.apache.log.Hierarchy
        class. 
      </p>

      
<p align="justify">
        The main reason for structuring logging namespace in a hierarchical manner is to
        allow inheritance. A logger will inherit it's parent priority if it has not
        been explicitly set. This allows you to set the "network" logger to have INFO 
        priority and unless the "network.interceptor" has had it's priority set it will 
        inherit the INFO priority. 
      </p>

      
<p align="justify">
        Unlike other logging toolkits, there is no performance penalty for having deep 
        hierarchies. Each logger caches a Priority to check against. When a logger
        has it's logger set or unset, it updates the cached version of it's child 
        loggers.
      </p>

    
</font></td>
</tr>
</table>
</div>
<br>
<div align="right">
<table cellspacing="0" cellpadding="2" border="0" width="100%">
<tr>
<td bgcolor="#525D76"><font face="arial,helvetica,sanserif" color="#ffffff" size="+1"><b>Log Targets</b></font></td>
</tr>
<tr>
<td><font face="arial,helvetica,sanserif" color="#000000">
<br>

      
<p align="justify">
        In LogKit, LogTargets are the destination of LogEvents. Decoupling LogEvent 
        generation from handling allows developers to change destinations of LogEvents
        dynamically or via configuration files. Possible destinations include writing
        to a database, a file, an IRC channel, a syslog server, an instant messaging 
        client etc.
      </p>

      
<p align="justify">
        Like Priorities, it is often useful to allow LogTargets to be inherited between 
        loggers. Like Priority inheritance, LogTarget inheritance does not suffer any 
        runtime performance penalty.
      </p>

      
<div align="right">
<table cellspacing="0" cellpadding="2" border="0" width="99%">
<tr>
<td bgcolor="#525D76"><font face="arial,helvetica,sanserif" color="#ffffff" size="+0"><b>Filters</b></font></td>
</tr>
<tr>
<td><font face="arial,helvetica,sanserif" color="#000000">
<br>

        
<p align="justify">
          Filters are a special kind of LogTarget. Instead of writing to an output 
          destination they are used to filter out LogEvents or modify the LogEvents 
          details and pass it on to another LogTarget. 
        </p>

        
<p align="justify">
          This can be a useful feature when you assign multiple LogTargets to a 
          logger. For instance you may add two LogTargets to a logger, one which
          writes LogEvents to a database and one which writes a message to the 
          administrators pager. However you may want to record all messages to 
          the database but only transmit FATAL_ERROR messages to pager. In this 
          case you would use a PriorityFilter to filter out non-FATAL_ERROR messages
          for pager log target.          
        </p>
      
      
</font></td>
</tr>
</table>
</div>
<br>

      
<div align="right">
<table cellspacing="0" cellpadding="2" border="0" width="99%">
<tr>
<td bgcolor="#525D76"><font face="arial,helvetica,sanserif" color="#ffffff" size="+0"><b>AsyncLogTarget</b></font></td>
</tr>
<tr>
<td><font face="arial,helvetica,sanserif" color="#000000">
<br>

        
<p align="justify">
          AsyncLogTarget is another kind of special LogTarget. It takes a log event
          and copies it into a queue so that another thread can actually write the 
          LogEvent to another LogTarget. This is useful if logging to a particular 
          LogTarget is a slow operation (such as a MailLogTarget).
        </p>

        
<p align="justify">
          Below is a snippet of code that creates an AsyncLogTarget to write messages
          in another thread.
        </p>


<div align="center">
<table cellspacing="2" cellpadding="2" border="1">
<tr>
<td>
<pre>
LogTarget mySlowTarget = ...;
AsyncLogTarget asyncTarget = new AsyncLogTarget( mySlowTarget );
Thread thread = new Thread( asyncTarget );
thread.setPriority( Thread.MIN_PRIORITY );
thread.start();

logger.setLogTargets( new LogTarget[] { asyncTarget } );
</pre>
</td>
</tr>
</table>
</div>
      
</font></td>
</tr>
</table>
</div>
<br>

    
</font></td>
</tr>
</table>
</div>
<br>
<div align="right">
<table cellspacing="0" cellpadding="2" border="0" width="100%">
<tr>
<td bgcolor="#525D76"><font face="arial,helvetica,sanserif" color="#ffffff" size="+1"><b>Formatters</b></font></td>
</tr>
<tr>
<td><font face="arial,helvetica,sanserif" color="#000000">
<br>

      
<p align="justify">
        LogTargets that write to a serial or unstructured store (ie filesystem or 
        network based LogTargets) need some method to serialize the LogEvent 
        before writing to the store. The most common way to serialize the LogEvent
        is to use a Formatter. 
      </p>

      
<p align="justify">
        The Formatter interface takes a LogEvent and returns a String object. The
        most commonly use LogEvent is the PatternFormatter. The pattern formatter 
        takes a format specifier that has a similar format to c's printf function.
      </p>

      
<p align="justify">
        The format specifier consists of a string containing raw text combined with 
        pattern elements. Each pattern element has the generalized form 
        "%[+|-]#.#{field:subformat}". The +|- indicates whether the pattern element 
        should be left or right justified (defaults to left justified if unspecified).
        The #.# indicates the minimum and maximum size of output, if unspecified the
        output is neither padded nor truncated. 'field' indicates the field to be 
        written and must be one of "category", "context", "message", "time", 
        "rtime" (time relative to start of application), "throwable" or "priority". 
        This parameter must be supplied and correlates to fields of LogEvent. 
        'subformat' is currently unused except in the case of "context" field. This is 
        further discussed below.
      </p>

      
<p align="justify">
        Following is a number of examples for PatternFormatter's format specifier 
        and actual output.
      </p>


<div align="center">
<table cellspacing="2" cellpadding="2" border="1">
<tr>
<td>
<pre>
format: "%7.7{priority} %5.5{rtime} [%8.8{category}]: %{message}\n%{throwable}"
output: DEBUG   123   [network.]: This is a debug message

format: "%7.7{priority} %5.5{rtime} [%{category}]: %{message}\n"
output: DEBUG   123   [network.interceptor.connected]: This is a debug message
output: DEBUG   123   [network]: This is another debug message

format: "%7.7{priority} %5.5{rtime} [%10.{category}]: %{message}\n"
output: DEBUG   123   [network.interceptor.connected]: This is a debug message
output: DEBUG   123   [network   ]: This is another debug message
</pre>
</td>
</tr>
</table>
</div>

      
<p align="justify">
        There is also ExtendedPatternFormatter that allows two extra fields, namely
        "method" and "thread". The "method" field attempts to determine the method that 
        called the Logger method to generate the LogEvent. The "thread" field displays 
        the name of the current thread.
      </p>

    
</font></td>
</tr>
</table>
</div>
<br>
<div align="right">
<table cellspacing="0" cellpadding="2" border="0" width="100%">
<tr>
<td bgcolor="#525D76"><font face="arial,helvetica,sanserif" color="#ffffff" size="+1"><b>Context</b></font></td>
</tr>
<tr>
<td><font face="arial,helvetica,sanserif" color="#000000">
<br>

      
<p align="justify">
        In many systems you need to include extra information depending in logs that depends
        on information not included in the LogEvent. For instance the Formatters section described
        an ExtendedPatternFormatter that included information such as calling method and calling 
        thread. Other contextual information that you may need to include in log files include
        user executing log statement, the network interface that the client component is listening 
        to (ie 127.0.0.1 vs 192.168.1.1), hostname (especially important on multihomed boxen) or 
        source of LogEvent (useful when writing a centralized log server).
      </p>

      
<p align="justify">
        There are a number of strategies to deal with application specific contextual 
        information. Some logging toolkits encourage extending the Logger, LogEvent and 
        LogTargets while others encourage using application specific LogTargets. The way 
        that LogKit solves this problem is by using a generic ContexMap object. 
      </p>

      
<p align="justify">
        The ContextMap allows the user to store arbitrary objects using a string key. These 
        objects can then be extracted by the LogTargets and used as appropriate. If you were
        using the PatternFormatter you could extract a value from ContextMap by specify the 
        "context" field with it's subformat set to the appropriate key. Some examples are 
        illustrated below.
      </p>


<div align="center">
<table cellspacing="2" cellpadding="2" border="1">
<tr>
<td>
<pre>
format: "%7.7{priority} [%{context:hostname}]: %{message}\n"
output: DEBUG   [helm.realityforge.org]: This is a debug message

format: "%7.7{priority} [%{context:interface}]: %{message}\n"
output: DEBUG   [127.0.0.1]: This is logging about loopback interface
output: DEBUG   [192.168.1.1]: This is logging about internal network interface
output: DEBUG   [203.121.1.2]: This is logging about external network interface

format: "%7.7{priority} [%{context:user}]: %{message}\n"
output: DEBUG   [Barney Rubble]: This is a debug message
</pre>
</td>
</tr>
</table>
</div>

      
<p align="justify">
        
<em>Warning:</em> Older versions of LogKit also incorporated a ContextStack
        that offered hierarchical management of context. It was discovered that this
        design encouraged bad practices and thus use of this feature has been 
        deprecated in favour of using ContextMap. The ContextStack is still accessible
        if users do not specify a subformat or specify the subformat "stack". However
        it is strongly advised that users do not use this feature as it will be 
        removed in a future iteration.
      </p>

      
<p align="justify">
        When using a ContextMap you create the object and populate it using the 
        set(key,value) method. After populating the ContextMap you call the method
        makeReadOnly(). This makes it impossible for hostile code to modify context
        in which logging occurs.
      </p>

      
<p align="justify">
        Then you need to associate the ContextMap with a thread by using 
        ContextMap.bind( myContextMap ). The ContextMap is bound to a thread
        using java.lang.InheritableThreadLocal and thus maps are inherited between 
        threads as specified by InheritableThreadLocal.
      </p>

      
<p align="justify">
        Below is an example of how a user can create and bind a ContextMap.
      </p>


<div align="center">
<table cellspacing="2" cellpadding="2" border="1">
<tr>
<td>
<pre>
final ContextMap context = new ContextMap();
context.set( "user", "Fred Flinstone" );
context.set( "interface", myInterface );
context.set( "hostname", "helm.realityforge.org" );
context.set( "jvmid", myJvmId );
context.makeReadOnly();

//bind new ContextMap to current thread and subthreads
ContextMap.bind( context );
</pre>
</td>
</tr>
</table>
</div>

    
</font></td>
</tr>
</table>
</div>
<br>
<div align="right">
<table cellspacing="0" cellpadding="2" border="0" width="100%">
<tr>
<td bgcolor="#525D76"><font face="arial,helvetica,sanserif" color="#ffffff" size="+1"><b>Examples</b></font></td>
</tr>
<tr>
<td><font face="arial,helvetica,sanserif" color="#000000">
<br>

      
<p align="justify">
        One of the best ways to learn how to use a toolkit is to see an 
        example in action. With that heres some example uses of LogKit. The first
        example is in a simple application while the next example is in a servlet.
        The servlet example demonstrates the usage of filters.
      </p>


<div align="center">
<table cellspacing="2" cellpadding="2" border="1">
<tr>
<td>
<pre>
Logger logger = Hierarchy.getDefaultHierarchy().getLoggerFor("myCategory");
logger.setPriority( Priority.DEBUG );
logger.debug( "This is a debug message" );
</pre>
</td>
</tr>
</table>
</div>


<div align="center">
<table cellspacing="2" cellpadding="2" border="1">
<tr>
<td>
<pre>
//Create a Log filter that writes to servlet Containers log
//If priority greater than ERROR
PriorityFilter filter = new PriorityFilter(Priority.ERROR);
filter.addTarget( new ServletOutputLogTarget(context) );

String logName = getInitParameter("log-name");
if( null == logName ) logName = "myservlet.log";

final String path = context.getRealPath("/") + "/WEB-INF/logs/" + logName ;

//Create a logger to write to a file as specified 
//with servlet init parameters
final String pattern = "%7.7{priority} %5.5{time}   [%8.8{category}] " +
                  "(%{context}): %{message}\\n%{throwable}";
final PatternFormatter formatter = new PatternFormatter( pattern );
final File file = new File( path );

//open file target in append mode
FileTarget target = new FileTarget( file, true, formatter );

//Create logger
myLogger = Hierarchy.getDefaultHierarchy().getLoggerFor("myServlet");

//Set log targets of logger
myLogger.setLogTargets( new LogTarget[] { target, filter } );

String logLevel = getInitParameter("log-priority");
if( null == logLevel ) logLevel = "DEBUG";

//Set log targets parameter based on init parameters
Priority priority = Priority.getPriorityForName( logLevel );
myLogger.setPriority( priority );
</pre>
</td>
</tr>
</table>
</div>

    
</font></td>
</tr>
</table>
</div>
<br>
<div align="right">
<table cellspacing="0" cellpadding="2" border="0" width="100%">
<tr>
<td bgcolor="#525D76"><font face="arial,helvetica,sanserif" color="#ffffff" size="+1"><b>Conclusion</b></font></td>
</tr>
<tr>
<td><font face="arial,helvetica,sanserif" color="#000000">
<br>

      
<p align="justify">
        LogKit is a friendly, easy to use logging toolkit. It is high performing and 
        easily integrated into existing products. By design it does not specify any
        configuration format but instead encourages users to integrate it into their 
        existing products. It also is designed to run in a secure environment by 
        limiting client access to hierarchies. 
      </p>

    
</font></td>
</tr>
</table>
</div>
<br>
</td>
</tr>
</table>
<br>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td>
<hr size="1" noshade="">
</td>
</tr>
<tr>
<td align="center"><font color="#525D76" size="-1" face="arial,helvetica,sanserif"><i>
              Copyright &copy;1999-2001 by the Apache Software Foundation.
              All Rights Reserved.
            </i></font></td>
</tr>
</table>
</body>
</html>