public static Logger createLogger ( String name , Level level , String file ) { LoggerContext lc = ( LoggerContext ) LoggerFactory . getILoggerFactory ( ) ; PatternLayoutEncoder ple = new PatternLayoutEncoder ( ) ; ple . setPattern ( "%date %level [%thread] %logger{10} [%file:%line]%n%msg%n%n" ) ; ple . setContext ( lc ) ; ple . start ( ) ; FileAppender < ILoggingEvent > fileAppender = new FileAppender < ILoggingEvent > ( ) ; fileAppender . setFile ( file ) ; fileAppender . setEncoder ( ple ) ; fileAppender . setAppend ( false ) ; fileAppender . setContext ( lc ) ; fileAppender . start ( ) ; logger = ( Logger ) LoggerFactory . getLogger ( name ) ; logger . detachAndStopAllAppenders ( ) ; // detach console (doesn't seem to work) logger . addAppender ( fileAppender ) ; // attach file appender logger . setLevel ( level ) ; logger . setAdditive ( true ) ; // set to true if root should log too return logger ; }
Creates a new logger .