comparison tango/tango/util/log/Appender.d @ 132:1700239cab2e trunk

[svn r136] MAJOR UNSTABLE UPDATE!!! Initial commit after moving to Tango instead of Phobos. Lots of bugfixes... This build is not suitable for most things.
author lindquist
date Fri, 11 Jan 2008 17:57:40 +0100
parents
children
comparison
equal deleted inserted replaced
131:5825d48b27d1 132:1700239cab2e
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.Appender;
14
15 public import tango.core.Exception;
16
17 public import tango.util.log.Event,
18 tango.util.log.EventLayout;
19
20 /*******************************************************************************
21
22 Base class for all Appenders. These objects are responsible for
23 emitting messages sent to a particular logger. There may be more
24 than one appender attached to any logger. The actual message is
25 constructed by another class known as an EventLayout.
26
27 *******************************************************************************/
28
29 public class Appender
30 {
31 typedef int Mask;
32
33 private Appender next;
34 private EventLayout layout;
35
36 /***********************************************************************
37
38 Return the mask used to identify this Appender. The mask
39 is used to figure out whether an appender has already been
40 invoked for a particular logger.
41
42 ***********************************************************************/
43
44 abstract Mask getMask ();
45
46 /***********************************************************************
47
48 Return the name of this Appender.
49
50 ***********************************************************************/
51
52 abstract char[] getName ();
53
54 /***********************************************************************
55
56 Append a message to the output.
57
58 ***********************************************************************/
59
60 abstract void append (Event event);
61
62 /***********************************************************************
63
64 Create an Appender and default its layout to SimpleLayout.
65
66 ***********************************************************************/
67
68 this ()
69 {
70 layout = new SimpleLayout;
71 }
72
73 /***********************************************************************
74
75 Static method to return a mask for identifying the Appender.
76 Each Appender class should have a unique fingerprint so that
77 we can figure out which ones have been invoked for a given
78 event. A bitmask is a simple an efficient way to do that.
79
80 ***********************************************************************/
81
82 protected Mask register (char[] tag)
83 {
84 static Mask mask = 1;
85 static Mask[char[]] registry;
86
87 Mask* p = tag in registry;
88 if (p)
89 return *p;
90 else
91 {
92 auto ret = mask;
93 registry [tag] = mask;
94
95 if (mask < 0)
96 throw new IllegalArgumentException ("too many unique registrations");
97
98 mask <<= 1;
99 return ret;
100 }
101 }
102
103 /***********************************************************************
104
105 Set the current layout to be that of the argument.
106
107 ***********************************************************************/
108
109 void setLayout (EventLayout layout)
110 {
111 if (layout)
112 this.layout = layout;
113 }
114
115 /***********************************************************************
116
117 Return the current Layout
118
119 ***********************************************************************/
120
121 EventLayout getLayout ()
122 {
123 return layout;
124 }
125
126 /***********************************************************************
127
128 Attach another appender to this one
129
130 ***********************************************************************/
131
132 void setNext (Appender next)
133 {
134 this.next = next;
135 }
136
137 /***********************************************************************
138
139 Return the next appender in the list
140
141 ***********************************************************************/
142
143 Appender getNext ()
144 {
145 return next;
146 }
147
148 /***********************************************************************
149
150 Close this appender. This would be used for file, sockets,
151 and such like.
152
153 ***********************************************************************/
154
155 void close ()
156 {
157 }
158 }
159