public static void initLogging ( ) throws IOException { sendCommonsLogToJDKLog ( ) ; try ( InputStream resource = Thread . currentThread ( ) . getContextClassLoader ( ) . getResourceAsStream ( "logging.properties" ) ) { // apply configuration if ( resource != null ) { try { LogManager . getLogManager ( ) . readConfiguration ( resource ) ; } finally { resource . close ( ) ; } } // apply a default format to the log handlers here before throwing an exception further down Logger log = Logger . getLogger ( "" ) ; // NOSONAR - local logger used on purpose here for ( Handler handler : log . getHandlers ( ) ) { handler . setFormatter ( new DefaultFormatter ( ) ) ; } if ( resource == null ) { throw new IOException ( "Did not find a file 'logging.properties' in the classpath" ) ; } } }
Initialize Logging from a file logging . properties which needs to be found in the classpath .