[logback-user] programmatic configuration to log to file

Marshall Pierce marshall at mpierce.org
Fri Feb 1 18:45:40 CET 2013


Is it the same output that is also showing up in the log file, or other output? Can you provide a more complete code sample with file output and stdout output?

Marshall

On Feb 1, 2013, at 9:42 AM, Steve Prior <sprior at geekster.com> wrote:

> Anyone? ...  Bueller?
> 
> Steve
> -------- Original Message --------
> Subject: [logback-user] programmatic configuration to log to file
> Date: Wed, 30 Jan 2013 20:36:42 -0500
> 
> 
> Based on some examples I cobbled together the following code to programmatically
> configure logback to write its output to a file (I don't like having config
> files around), but the output still goes to stdout in addition to the file.  Can
> anyone give me a clue how I can only have the output go to the specific file and
> not stdout?
> 
> Thanks
> Steve
> 
>      LoggerContext loggerContext = (LoggerContext)
> LoggerFactory.getILoggerFactory();
> 
>      FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>();
>      fileAppender.setContext(loggerContext);
>      fileAppender.setFile(ConcurrencyExample.class.getSimpleName() + ".log");
> 
>      PatternLayout pl = new PatternLayout();
>      pl.setPattern("%d %5p %t [%c:%L] %m%n)");
>      pl.setContext(loggerContext);
>      pl.start();
>      fileAppender.setLayout(pl);
> 
>      fileAppender.start();
> 
>      // attach the rolling file appender to the logger of your choice
>      Logger logbackLogger = loggerContext.getLogger(ConcurrencyExample.class);
>      logbackLogger.addAppender(fileAppender);
> 
>      // OPTIONAL: print logback internal status messages
>      StatusPrinter.print(loggerContext);
> 
>      // log something
>      logbackLogger.info("hello");
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user
> 
> 
> _______________________________________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/logback-user



More information about the Logback-user mailing list