comparison tango/tango/util/log/Log.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 version: Hierarchy moved due to circular dependencies; Oct 2004
9
10 author: Kris
11
12 *******************************************************************************/
13
14 module tango.util.log.Log;
15
16 public import tango.util.log.Logger;
17
18 private import tango.util.log.Event,
19 tango.util.log.Hierarchy;
20
21 private import tango.util.log.model.ILevel;
22
23 /*******************************************************************************
24
25 Manager for routing Logger calls to the default hierarchy. Note
26 that you may have multiple hierarchies per application, but must
27 access the hierarchy directly for getRootLogger() and getLogger()
28 methods within each additional instance.
29
30 *******************************************************************************/
31
32 class Log : ILevel
33 {
34 static private Hierarchy base;
35
36 private static ILevel.Level[char[]] map;
37
38 private struct Pair {char[] name; ILevel.Level value;}
39
40 private static Pair[] Pairs =
41 [
42 {"TRACE", ILevel.Level.Trace},
43 {"Trace", ILevel.Level.Trace},
44 {"trace", ILevel.Level.Trace},
45 {"INFO", ILevel.Level.Info},
46 {"Info", ILevel.Level.Info},
47 {"info", ILevel.Level.Info},
48 {"WARN", ILevel.Level.Warn},
49 {"Warn", ILevel.Level.Warn},
50 {"warn", ILevel.Level.Warn},
51 {"ERROR", ILevel.Level.Error},
52 {"Error", ILevel.Level.Error},
53 {"error", ILevel.Level.Error},
54 {"Fatal", ILevel.Level.Fatal},
55 {"FATAL", ILevel.Level.Fatal},
56 {"fatal", ILevel.Level.Fatal},
57 {"NONE", ILevel.Level.None},
58 {"None", ILevel.Level.None},
59 {"none", ILevel.Level.None},
60 ];
61
62 /***********************************************************************
63
64 This is a singleton, so hide the constructor.
65
66 ***********************************************************************/
67
68 private this ()
69 {
70 }
71
72 /***********************************************************************
73
74 Initialize the base hierarchy.
75
76 ***********************************************************************/
77
78 static this ()
79 {
80 base = new Hierarchy ("tango");
81 Event.initialize ();
82
83 // populate a map of acceptable level names
84 foreach (p; Pairs)
85 map[p.name] = p.value;
86 }
87
88 /***********************************************************************
89
90 Return the root Logger instance. This is the ancestor of
91 all loggers and, as such, can be used to manipulate the
92 entire hierarchy. For instance, setting the root 'level'
93 attribute will affect all other loggers in the tree.
94
95 ***********************************************************************/
96
97 static Logger getRootLogger ()
98 {
99 return base.getRootLogger ();
100 }
101
102 /***********************************************************************
103
104 Return an instance of the named logger. Names should be
105 hierarchical in nature, using dot notation (with '.') to
106 separate each name section. For example, a typical name
107 might be something like "tango.io.Buffer".
108
109 If the logger does not currently exist, it is created and
110 inserted into the hierarchy. A parent will be attached to
111 it, which will be either the root logger or the closest
112 ancestor in terms of the hierarchical name space.
113
114 ***********************************************************************/
115
116 static Logger getLogger (char[] name)
117 {
118 return base.getLogger (name);
119 }
120
121 /***********************************************************************
122
123 Return the singleton hierarchy.
124
125 ***********************************************************************/
126
127 static Hierarchy getHierarchy ()
128 {
129 return base;
130 }
131
132 /***********************************************************************
133
134 Return the level of a given name
135
136 ***********************************************************************/
137
138 static ILevel.Level level (char[] name, ILevel.Level def=ILevel.Level.Trace)
139 {
140 auto p = name in map;
141 if (p)
142 return *p;
143 return def;
144 }
145 }