public static String[] enableDebugLogging() { return LogUtil.setLog4jLevel( CONTEXTS, "DEBUG" ); }
public static String[] setLog4jLevel( String[] contexts, String level ) { String[] results = new String[ contexts.length ]; for( int i = 0; i < contexts.length; i++ ) results[ i ] = setLog4jLevel( contexts[ i ], level ); return results; }
public static void restoreLogging( String[] levels ) { if( levels != null ) LogUtil.setLog4jLevel( CONTEXTS, levels ); } }
public static String[] setLog4jLevel( String[] contexts, String[] levels ) { String[] results = new String[ contexts.length ]; for( int i = 0; i < contexts.length; i++ ) results[ i ] = setLog4jLevel( contexts[ i ], levels[ i ] ); return results; }
public static String[] enableTraceLogging() { return LogUtil.setLog4jLevel( CONTEXTS, "TRACE" ); }
public static String[] enableLogging( LogLevel level ) { if( level == null ) return null; return LogUtil.setLog4jLevel( CONTEXTS, level.toString() ); }
public static void initLog4j( Configuration configuration ) { String values = configuration.get( "log4j.logger", null ); if( values == null || values.length() == 0 ) return; if( !Util.hasClass( "org.apache.log4j.Logger" ) ) { LOG.info( "org.apache.log4j.Logger is not in the current CLASSPATH, not setting log4j.logger properties" ); return; } String[] elements = values.split( "," ); for( String element : elements ) LogUtil.setLog4jLevel( element.split( "=" ) ); }
public static void initLog4j( Configuration configuration ) { String values = configuration.get( "log4j.logger", null ); if( values == null || values.length() == 0 ) return; if( !Util.hasClass( "org.apache.log4j.Logger" ) ) { LOG.info( "org.apache.log4j.Logger is not in the current CLASSPATH, not setting log4j.logger properties" ); return; } String[] elements = values.split( "," ); for( String element : elements ) LogUtil.setLog4jLevel( element.split( "=" ) ); }
public static String setLog4jLevel( String logger, String level ) { // removing logj4 dependency // org.apache.log4j.Logger.getLogger( logger[ 0 ] ).setLevel( org.apache.log4j.Level.toLevel( logger[ 1 ] ) ); Object loggerObject = Util.invokeStaticMethod( "org.apache.log4j.Logger", "getLogger", new Object[]{logger}, new Class[]{String.class} ); Object levelObject = null; if( level != null ) levelObject = Util.invokeStaticMethod( "org.apache.log4j.Level", "toLevel", new Object[]{level}, new Class[]{String.class} ); Object oldLevel = Util.invokeInstanceMethod( loggerObject, "getLevel", new Object[]{}, new Class[]{} ); Util.invokeInstanceMethod( loggerObject, "setLevel", new Object[]{levelObject}, new Class[]{Util.loadClass( "org.apache.log4j.Level" )} ); if( oldLevel == null ) return null; return oldLevel.toString(); }