00001 /******************************************************************************* 00002 00003 @file XmlLayout.d 00004 00005 Copyright (c) 2004 Kris Bell 00006 00007 This software is provided 'as-is', without any express or implied 00008 warranty. In no event will the authors be held liable for damages 00009 of any kind arising from the use of this software. 00010 00011 Permission is hereby granted to anyone to use this software for any 00012 purpose, including commercial applications, and to alter it and/or 00013 redistribute it freely, subject to the following restrictions: 00014 00015 1. The origin of this software must not be misrepresented; you must 00016 not claim that you wrote the original software. If you use this 00017 software in a product, an acknowledgment within documentation of 00018 said product would be appreciated but is not required. 00019 00020 2. Altered source versions must be plainly marked as such, and must 00021 not be misrepresented as being the original software. 00022 00023 3. This notice may not be removed or altered from any distribution 00024 of the source. 00025 00026 4. Derivative works are permitted, but they must carry this notice 00027 in full and credit the original source. 00028 00029 00030 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00031 00032 00033 @version Initial version, May 2004 00034 @author Kris 00035 00036 00037 *******************************************************************************/ 00038 00039 module mango.log.XmlLayout; 00040 00041 private import std.c.time, 00042 std.c.stdio; 00043 00044 private import mango.log.Event, 00045 mango.log.Layout; 00046 00047 /******************************************************************************* 00048 00049 A layout with XML output conforming to Log4J specs. 00050 00051 *******************************************************************************/ 00052 00053 public class XmlLayout : Layout 00054 { 00055 /*********************************************************************** 00056 00057 Format message attributes into an output buffer and return 00058 the populated portion. 00059 00060 ***********************************************************************/ 00061 00062 char[] header (Event event) 00063 { 00064 char[20] tmp; 00065 00066 event.append ("<log4j:event logger=\"") 00067 .append (event.getName) 00068 .append ("\" timestamp=\"") 00069 .append (ultoa (tmp, event.getEpochMilliSeconds)) 00070 .append ("\" level=\"") 00071 .append (levelString(event) [0..length-1]) 00072 .append ("\" thread=\"unknown\">\r\n<log4j:message><![CDATA["); 00073 00074 return event.getContent; 00075 } 00076 00077 00078 /*********************************************************************** 00079 00080 Format message attributes into an output buffer and return 00081 the populated portion. 00082 00083 ***********************************************************************/ 00084 00085 char[] footer (Event event) 00086 { 00087 event.scratch.length = 0; 00088 event.append ("]]></log4j:message>\r\n<log4j:properties><log4j:data name=\"application\" value=\"") 00089 .append (event.getHierarchy.getName) 00090 .append ("\"/><log4j:data name=\"hostname\" value=\"") 00091 .append (event.getHierarchy.getAddress) 00092 .append ("\"/></log4j:properties></log4j:event>\r\n"); 00093 00094 return event.getContent; 00095 } 00096 } 00097 00098