KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > vladium > emma > AppLoggers


1 /* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
2  *
3  * This program and the accompanying materials are made available under
4  * the terms of the Common Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/cpl-v10.html
6  *
7  * $Id: AppLoggers.java,v 1.1.2.1 2004/07/16 23:32:03 vlad_r Exp $
8  */

9 package com.vladium.emma;
10
11 import java.util.HashSet JavaDoc;
12 import java.util.Set JavaDoc;
13 import java.util.StringTokenizer JavaDoc;
14
15 import com.vladium.logging.ILogLevels;
16 import com.vladium.logging.Logger;
17 import com.vladium.util.IProperties;
18 import com.vladium.util.Strings;
19
20 // ----------------------------------------------------------------------------
21
/**
22  * @author Vlad Roubtsov, (C) 2004
23  */

24 public
25 abstract class AppLoggers
26 {
27     // public: ................................................................
28

29     public static final String JavaDoc PREFIX_VERBOSITY = "verbosity.";
30
31     public static final String JavaDoc PROPERTY_VERBOSITY_LEVEL = PREFIX_VERBOSITY + "level";
32     public static final String JavaDoc DEFAULT_VERBOSITY_LEVEL = ILogLevels.INFO_STRING;
33     
34     public static final String JavaDoc PROPERTY_VERBOSITY_FILTER = PREFIX_VERBOSITY + "filter";
35     
36     public static Logger create (final String JavaDoc appName, final IProperties properties, final Logger base)
37     {
38         if (properties == null)
39             throw new IllegalArgumentException JavaDoc ("null input: properties");
40         
41         // verbosity level:
42

43         final int level;
44         {
45             final String JavaDoc _level = properties.getProperty (PROPERTY_VERBOSITY_LEVEL,
46                                                           DEFAULT_VERBOSITY_LEVEL);
47             level = Logger.stringToLevel (_level);
48         }
49         
50         // verbosity filter:
51

52         final Set JavaDoc filter;
53         {
54             final String JavaDoc _filter = properties.getProperty (PROPERTY_VERBOSITY_FILTER);
55             Set JavaDoc temp = null;
56             
57             if (_filter != null)
58             {
59                 final StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc (_filter, COMMA_DELIMITERS);
60                 if (tokenizer.countTokens () > 0)
61                 {
62                     temp = new HashSet JavaDoc (tokenizer.countTokens ());
63                     while (tokenizer.hasMoreTokens ())
64                     {
65                         temp.add (tokenizer.nextToken ());
66                     }
67                 }
68             }
69             
70             filter = temp;
71         }
72         
73         return Logger.create (level, null, appName, filter, base);
74     }
75     
76     
77     
78     // protected: .............................................................
79

80     // package: ...............................................................
81

82     // private: ...............................................................
83

84
85     private AppLoggers () {} // this class is not extendible
86

87     private static final String JavaDoc COMMA_DELIMITERS = "," + Strings.WHITE_SPACE;
88
89 } // end of class
90
// ----------------------------------------------------------------------------
Popular Tags