@ SuppressWarnings ( "unchecked" ) static void logToFile ( String filename ) { Logger rootLogger = ( Logger ) LoggerFactory . getLogger ( org . slf4j . Logger . ROOT_LOGGER_NAME ) ; FileAppender < ILoggingEvent > fileappender = new FileAppender <> ( ) ; fileappender . setContext ( rootLogger . getLoggerContext ( ) ) ; fileappender . setFile ( filename ) ; fileappender . setName ( "FILE" ) ; ConsoleAppender < ? > console = ( ConsoleAppender < ? > ) rootLogger . getAppender ( "STDOUT" ) ; fileappender . setEncoder ( ( Encoder < ILoggingEvent > ) console . getEncoder ( ) ) ; fileappender . start ( ) ; rootLogger . addAppender ( fileappender ) ; console . stop ( ) ; }
Configure file logging and stop console logging .