1 9 package com.vladium.emma; 10 11 import java.util.HashSet ; 12 import java.util.Set ; 13 import java.util.StringTokenizer ; 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 24 public 25 abstract class AppLoggers 26 { 27 29 public static final String PREFIX_VERBOSITY = "verbosity."; 30 31 public static final String PROPERTY_VERBOSITY_LEVEL = PREFIX_VERBOSITY + "level"; 32 public static final String DEFAULT_VERBOSITY_LEVEL = ILogLevels.INFO_STRING; 33 34 public static final String PROPERTY_VERBOSITY_FILTER = PREFIX_VERBOSITY + "filter"; 35 36 public static Logger create (final String appName, final IProperties properties, final Logger base) 37 { 38 if (properties == null) 39 throw new IllegalArgumentException ("null input: properties"); 40 41 43 final int level; 44 { 45 final String _level = properties.getProperty (PROPERTY_VERBOSITY_LEVEL, 46 DEFAULT_VERBOSITY_LEVEL); 47 level = Logger.stringToLevel (_level); 48 } 49 50 52 final Set filter; 53 { 54 final String _filter = properties.getProperty (PROPERTY_VERBOSITY_FILTER); 55 Set temp = null; 56 57 if (_filter != null) 58 { 59 final StringTokenizer tokenizer = new StringTokenizer (_filter, COMMA_DELIMITERS); 60 if (tokenizer.countTokens () > 0) 61 { 62 temp = new HashSet (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 80 82 84 85 private AppLoggers () {} 87 private static final String COMMA_DELIMITERS = "," + Strings.WHITE_SPACE; 88 89 } | Popular Tags |