132
|
1 /*******************************************************************************
|
|
2
|
|
3 copyright: Copyright (c) 2004 Kris Bell. All rights reserved
|
|
4
|
|
5 license: BSD style: $(LICENSE)
|
|
6
|
|
7 version: Initial release: May 2004
|
|
8
|
|
9 author: Kris
|
|
10
|
|
11 *******************************************************************************/
|
|
12
|
|
13 module tango.util.log.Log4Layout;
|
|
14
|
|
15 private import tango.core.Thread;
|
|
16
|
|
17 private import tango.util.log.Event,
|
|
18 tango.util.log.EventLayout;
|
|
19
|
|
20 /*******************************************************************************
|
|
21
|
|
22 A layout with XML output conforming to Log4J specs.
|
|
23
|
|
24 *******************************************************************************/
|
|
25
|
|
26 public class Log4Layout : EventLayout
|
|
27 {
|
|
28 /***********************************************************************
|
|
29
|
|
30 Format message attributes into an output buffer and return
|
|
31 the populated portion.
|
|
32
|
|
33 ***********************************************************************/
|
|
34
|
|
35 char[] header (Event event)
|
|
36 {
|
|
37 char[20] tmp;
|
|
38 char[] threadName;
|
|
39
|
|
40 threadName = Thread.getThis.name;
|
|
41 if (threadName.length is 0)
|
|
42 threadName = "{unknown}";
|
|
43
|
|
44 event.append ("<log4j:event logger=\"")
|
|
45 .append (event.getName)
|
|
46 .append ("\" timestamp=\"")
|
|
47 .append (toMilli (tmp, event.getTime.span))
|
|
48 .append ("\" level=\"")
|
|
49 .append (event.getLevelName [0..length-1])
|
|
50 .append ("\" thread=\"").append(threadName).append("\">\r\n<log4j:message><![CDATA[");
|
|
51
|
|
52 return event.getContent;
|
|
53 }
|
|
54
|
|
55
|
|
56 /***********************************************************************
|
|
57
|
|
58 Format message attributes into an output buffer and return
|
|
59 the populated portion.
|
|
60
|
|
61 ***********************************************************************/
|
|
62
|
|
63 char[] footer (Event event)
|
|
64 {
|
|
65 event.scratch.length = 0;
|
|
66 event.append ("]]></log4j:message>\r\n<log4j:properties><log4j:data name=\"application\" value=\"")
|
|
67 .append (event.getHierarchy.getName)
|
|
68 .append ("\"/><log4j:data name=\"hostname\" value=\"")
|
|
69 .append (event.getHierarchy.getAddress)
|
|
70 .append ("\"/></log4j:properties></log4j:event>\r\n");
|
|
71
|
|
72 return event.getContent;
|
|
73 }
|
|
74 }
|
|
75
|
|
76
|