diff tango/tango/util/log/PropertyConfigurator.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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tango/tango/util/log/PropertyConfigurator.d	Fri Jan 11 17:57:40 2008 +0100
@@ -0,0 +1,77 @@
+/*******************************************************************************
+
+        copyright:      Copyright (c) 2004 Kris Bell. All rights reserved
+
+        license:        BSD style: $(LICENSE)
+      
+        version:        Nov 2005: split from Configurator.d
+        verison:        Feb 2007: removed default console configuration
+         
+        author:         Kris
+
+*******************************************************************************/
+
+module tango.util.log.PropertyConfigurator;
+
+private import  tango.io.FilePath;
+
+private import  tango.util.log.Log;
+
+private import  tango.text.Properties;
+
+/*******************************************************************************
+
+        A utility class for initializing the basic behaviour of the
+        default logging hierarchy.
+
+        PropertyConfigurator parses a much simplified version of the 
+        property file. tango.log only supports the settings of Logger 
+        levels at this time; setup of Appenders and Layouts are currently 
+        done "in the code"
+
+*******************************************************************************/
+
+struct PropertyConfigurator
+{
+        /***********************************************************************
+        
+                Add a default StdioAppender, with a SimpleTimerLayout, to 
+                the root node. The activity levels of all nodes are set
+                via a property file with name=value pairs specified in the
+                following format:
+
+                    name: the actual logger name, in dot notation
+                          format. The name "root" is reserved to
+                          match the root logger node.
+
+                   value: one of TRACE, INFO, WARN, ERROR, FATAL
+                          or NONE (or the lowercase equivalents).
+
+                For example, the declaration
+
+                ---
+                tango.unittest = INFO
+                myApp.SocketActivity = TRACE
+                ---
+                
+                sets the level of the loggers called tango.unittest and
+                myApp.SocketActivity
+
+        ***********************************************************************/
+
+        static void opCall (FilePath path)
+        {
+                void loader (char[] name, char[] value)
+                {
+                        auto l = (name == "root") ? Log.getRootLogger
+                                                  : Log.getLogger (name);
+
+                        if (l)
+                            l.setLevel (Log.level(value));
+                }
+
+                // read and parse properties from file
+                Properties!(char).load (path, &loader);
+        }
+}
+