132
|
1 /*******************************************************************************
|
|
2
|
|
3 copyright: Copyright (c) 2004 Kris Bell. All rights reserved
|
|
4
|
|
5 license: BSD style: $(LICENSE)
|
|
6
|
|
7 version: Nov 2005: split from Configurator.d
|
|
8 verison: Feb 2007: removed default console configuration
|
|
9
|
|
10 author: Kris
|
|
11
|
|
12 *******************************************************************************/
|
|
13
|
|
14 module tango.util.log.PropertyConfigurator;
|
|
15
|
|
16 private import tango.io.FilePath;
|
|
17
|
|
18 private import tango.util.log.Log;
|
|
19
|
|
20 private import tango.text.Properties;
|
|
21
|
|
22 /*******************************************************************************
|
|
23
|
|
24 A utility class for initializing the basic behaviour of the
|
|
25 default logging hierarchy.
|
|
26
|
|
27 PropertyConfigurator parses a much simplified version of the
|
|
28 property file. tango.log only supports the settings of Logger
|
|
29 levels at this time; setup of Appenders and Layouts are currently
|
|
30 done "in the code"
|
|
31
|
|
32 *******************************************************************************/
|
|
33
|
|
34 struct PropertyConfigurator
|
|
35 {
|
|
36 /***********************************************************************
|
|
37
|
|
38 Add a default StdioAppender, with a SimpleTimerLayout, to
|
|
39 the root node. The activity levels of all nodes are set
|
|
40 via a property file with name=value pairs specified in the
|
|
41 following format:
|
|
42
|
|
43 name: the actual logger name, in dot notation
|
|
44 format. The name "root" is reserved to
|
|
45 match the root logger node.
|
|
46
|
|
47 value: one of TRACE, INFO, WARN, ERROR, FATAL
|
|
48 or NONE (or the lowercase equivalents).
|
|
49
|
|
50 For example, the declaration
|
|
51
|
|
52 ---
|
|
53 tango.unittest = INFO
|
|
54 myApp.SocketActivity = TRACE
|
|
55 ---
|
|
56
|
|
57 sets the level of the loggers called tango.unittest and
|
|
58 myApp.SocketActivity
|
|
59
|
|
60 ***********************************************************************/
|
|
61
|
|
62 static void opCall (FilePath path)
|
|
63 {
|
|
64 void loader (char[] name, char[] value)
|
|
65 {
|
|
66 auto l = (name == "root") ? Log.getRootLogger
|
|
67 : Log.getLogger (name);
|
|
68
|
|
69 if (l)
|
|
70 l.setLevel (Log.level(value));
|
|
71 }
|
|
72
|
|
73 // read and parse properties from file
|
|
74 Properties!(char).load (path, &loader);
|
|
75 }
|
|
76 }
|
|
77
|