package textbender.g.util.logging; // Copyright 2004-2006, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. import java.util.*; import java.util.logging.*; /** Logger utilities. */ public final class LoggerX { private LoggerX() {} public static final Level ALL = Level.ALL; public static final Level CONFIG = Level.CONFIG; public static final Level FINE = Level.FINE; public static final Level FINER = Level.FINER; public static final Level FINEST = Level.FINEST; public static final Level INFO = Level.INFO; public static final Level OFF = Level.OFF; public static final Level SEVERE = Level.SEVERE; public static final Level WARNING = Level.WARNING; /** Returns a string listing all key/value pairs in the specified map. * The result is suitable for logging purposes, * e.g. to record system properties in a log at start-up. */ @Deprecated // properties.toString() works fine, and probably so does map.toString() public static String contentString( Map map ) { StringBuffer stringBuffer = new StringBuffer( /*intial capacity*/2000 ); Iterator entryIterator = map.entrySet().iterator(); if( entryIterator.hasNext() ) for( ;; ) { Map.Entry entry = (Map.Entry)entryIterator.next(); stringBuffer.append( entry.getKey() ); stringBuffer.append( "=\"" ); stringBuffer.append( entry.getValue() ); stringBuffer.append( '"' ); if( entryIterator.hasNext() ) stringBuffer.append( ", " ); else break; } return stringBuffer.toString(); } /** Returns the standard logger for a class. */ // public static Logger i( Class cl ) { return Logger.getLogger( cl.getPackage().getName() ); } ///// maybe no harm in a separate logger per class (allows finer config): public static Logger i( Class cl ) { return Logger.getLogger( cl.getName() ); } /** Returns the standard logger for a class name. */ public static Logger i( String className ) { return Logger.getLogger( className ); } /** Logs a test message at the specified level. */ public static void test( Logger logger, Level level ) { logger.log( level, "test message at level " + level.toString() ); } /** Logs test messages at all levels. */ public static void test( Logger logger ) { logger.severe( "just testing: SEVERE down to FINEST..." ); logger.warning( "this is a WARNING" ); logger.info( "this is INFO" ); logger.config( "this is CONFIG" ); logger.fine( "this is FINE" ); logger.finer( "this is FINER" ); logger.finest( "this is FINEST :)" ); } }