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.LayoutChainsaw;
14 
15 private import  tango.core.Thread;
16 
17 private import  tango.util.log.Log;
18 
19 /*******************************************************************************
20 
21         A layout with XML output conforming to Log4J specs.
22        
23 *******************************************************************************/
24 
25 public class LayoutChainsaw : Appender.Layout
26 {
27         /***********************************************************************
28                 
29                 Subclasses should implement this method to perform the
30                 formatting of the actual message content.
31 
32         ***********************************************************************/
33 
34         void format (LogEvent event, scope size_t delegate(const(void)[]) dg)
35         {
36                 char[20] tmp;
37                 const(char)[]   threadName;
38                 
39                 threadName = Thread.getThis().name;
40                 if (threadName.length is 0)
41                     threadName = "{unknown}";
42 
43                 dg ("<log4j:event logger=\"");
44                 dg (event.name);
45                 dg ("\" timestamp=\"");
46                 dg (event.toMilli (tmp, event.time.span));
47                 dg ("\" level=\"");
48                 dg (event.levelName);
49                 dg ("\" thread=\"");
50                 dg (threadName);
51                 dg ("\">\r\n<log4j:message><![CDATA[");
52 
53                 dg (event.toString());
54 
55                 dg ("]]></log4j:message>\r\n<log4j:properties><log4j:data name=\"application\" value=\"");
56                 dg (event.host.name);
57                 dg ("\"/><log4j:data name=\"hostname\" value=\"");
58                 dg (event.host.address);
59                 dg ("\"/></log4j:properties></log4j:event>\r\n");
60         }
61 }
62 
63