public static void loggerInit ( Level level , boolean isRedirectStdOutErr , String format ) throws IOException { // Set the java util logging format setLoggingFormat ( format ) ; // Configure the root logger and its handlers so that all the // derived loggers will inherit the properties Logger rootLogger = Logger . getLogger ( "" ) ; for ( Handler handler : rootLogger . getHandlers ( ) ) { handler . setLevel ( level ) ; } rootLogger . setLevel ( level ) ; if ( rootLogger . getLevel ( ) . intValue ( ) < Level . WARNING . intValue ( ) ) { // zookeeper logging scares me. if people want this, we can patch to config-drive this Logger . getLogger ( "org.apache.zookeeper" ) . setLevel ( Level . WARNING ) ; } // setting logging for http client to be error level System . setProperty ( "org.apache.commons.logging.Log" , "org.apache.commons.logging.impl.SimpleLog" ) ; System . setProperty ( "org.apache.commons.logging.simplelog.log.httpclient.wire" , "ERROR" ) ; System . setProperty ( "org.apache.commons.logging.simplelog.log.org.apache.http" , "ERROR" ) ; System . setProperty ( "org.apache.commons.logging.simplelog.log.org.apache.http.headers" , "ERROR" ) ; if ( isRedirectStdOutErr ) { // Remove ConsoleHandler if present, to avoid StackOverflowError. // ConsoleHandler writes to System.err and since we are redirecting // System.err to Logger, it results in an infinite loop. for ( Handler handler : rootLogger . getHandlers ( ) ) { if ( handler instanceof ConsoleHandler ) { rootLogger . removeHandler ( handler ) ; } } // now rebind stdout/stderr to logger Logger logger ; LoggingOutputStream los ; logger = Logger . getLogger ( "stdout" ) ; los = new LoggingOutputStream ( logger , StdOutErrLevel . STDOUT ) ; System . setOut ( new PrintStream ( los , true ) ) ; logger = Logger . getLogger ( "stderr" ) ; los = new LoggingOutputStream ( logger , StdOutErrLevel . STDERR ) ; System . setErr ( new PrintStream ( los , true ) ) ; } }
Init java util logging