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.ConfigProps; 15 16 private import tango.util.log.Log; 17 18 private import tango.io.stream.Map, 19 tango.io.device.File; 20 21 /******************************************************************************* 22 23 A utility class for initializing the basic behaviour of the 24 default logging hierarchy. 25 26 ConfigProps parses a much simplified version of the property file. 27 Tango.log only supports the settings of Logger levels at this time, 28 and setup of Appenders and Layouts are currently done "in the code" 29 30 *******************************************************************************/ 31 32 struct ConfigProps 33 { 34 /*********************************************************************** 35 36 Add a default StdioAppender, with a SimpleTimerLayout, to 37 the root node. The activity levels of all nodes are set 38 via a property file with name=value pairs specified in the 39 following format: 40 41 name: the actual logger name, in dot notation 42 format. The name "root" is reserved to 43 match the root logger node. 44 45 value: one of TRACE, INFO, WARN, ERROR, FATAL 46 or NONE (or the lowercase equivalents). 47 48 For example, the declaration 49 50 --- 51 tango.unittest = INFO 52 myApp.SocketActivity = TRACE 53 --- 54 55 sets the level of the loggers called tango.unittest and 56 myApp.SocketActivity 57 58 ***********************************************************************/ 59 60 static void opCall (char[] path) 61 { 62 auto input = new MapInput!(char)(new File(path)); 63 scope (exit) 64 input.close(); 65 66 // read and parse properties from file 67 foreach (name, value; input) 68 { 69 auto log = (name == "root") ? Log.root 70 : Log.lookup (name); 71 if (log) 72 log.level (Log.convert (value)); 73 } 74 } 75 } 76