Search code examples
javaloggingtinylog

Multiple writers for tinylog


I'm using tinylog for my logging needs and were wondering if anybody knows a way to log to a file and the console. When I use the configuration below I only get output on the console. When I remove .writer(new ConsoleWriter())the logging is done only to file (as one would expect).

Configurator.currentConfig()
                          .level(LoggingLevel.valueOf("TRACE"))
                          .writer(new RollingFileWriter(file,10))
                          .writer(new ConsoleWriter())
                          .activate();

Solution

  • According to the docs, this is possible (now), the 'trick' being the the call to addWriter() instead of multiple calls to the writer() method.

    Quoting http://www.tinylog.org/configuration#writers:

    Multiple writers can be used in parallel. For example, it is possible to write log entries to the console and to a log file simultaneously. Example:

    Configurator.currentConfig()    
      .writer(new ConsoleWriter())    
      .addWriter(new FileWriter("log.txt"))    
      .activate();