Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

Layout.d

Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003         @file Layout.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.Layout;
00040 
00041 private import mango.log.Event;
00042 
00043 /*******************************************************************************
00044 
00045         Base class for all Layout instances
00046 
00047 *******************************************************************************/
00048 
00049 public class Layout
00050 {
00051         private import mango.log.Logger;
00052 
00053         /***********************************************************************
00054                 
00055                 Subclasses should implement this method to perform the
00056                 formatting of each message header
00057 
00058         ***********************************************************************/
00059 
00060         abstract char[]  header (Event event);
00061 
00062         /***********************************************************************
00063                 
00064                 Subclasses should implement this method to perform the
00065                 formatting of each message footer
00066 
00067         ***********************************************************************/
00068 
00069         char[] footer (Event event)
00070         {
00071                 return "";
00072         }
00073 
00074         /***********************************************************************
00075                 
00076                 Subclasses should implement this method to perform the
00077                 formatting of the actual message content.
00078 
00079         ***********************************************************************/
00080 
00081         char[] content (Event event)
00082         {
00083                 return event.toString;
00084         }
00085 
00086         /***********************************************************************
00087                 
00088                 Convert a time value (in milliseconds) to ascii
00089 
00090         ***********************************************************************/
00091 
00092         final char[] ultoa (char[] s, ulong l)
00093         in {
00094            assert (s.length > 0);
00095            }
00096         body 
00097         {
00098                 int len = s.length;
00099                 do {
00100                    s[--len] = l % 10 + '0';
00101                    l /= 10;
00102                    } while (l && len);
00103                 return s[len..s.length];                
00104         }
00105 }
00106 
00107 
00108 /*******************************************************************************
00109 
00110         A simple layout comprised only of level, name, and message
00111 
00112 *******************************************************************************/
00113 
00114 public class SimpleLayout : Layout
00115 {
00116         static protected SimpleLayout simpleLayout;
00117          
00118         /***********************************************************************
00119                 
00120                 Make one of these available for use as the default layout
00121 
00122         ***********************************************************************/
00123 
00124         static this ()
00125         {
00126                 simpleLayout = new SimpleLayout();
00127         }
00128 
00129         /***********************************************************************
00130                 
00131                 Format outgoing message
00132 
00133         ***********************************************************************/
00134 
00135         char[] header (Event event)
00136         {
00137                 event.append (event.getLevelName)
00138                      .append(event.getName)
00139                      .append(" - ");
00140                 return event.getContent;
00141         }
00142 }
00143 
00144 /*******************************************************************************
00145 
00146         A simple layout comprised only of time(ms), level, name, and message
00147 
00148 *******************************************************************************/
00149 
00150 public class SimpleTimerLayout : Layout
00151 {
00152         /***********************************************************************
00153                 
00154                 Format outgoing message
00155 
00156         ***********************************************************************/
00157 
00158         char[] header (Event event)
00159         {
00160                 char[20] tmp;
00161 
00162                 event.append (ultoa (tmp, event.getTime))
00163                      .append (" ")
00164                      .append (event.getLevelName)
00165                      .append (event.getName)
00166                      .append (" - ");
00167                 return event.getContent;
00168         }
00169 }

Generated on Mon Nov 14 10:59:39 2005 for Mango by  doxygen 1.4.0