1

I am currently using SLF4J with log4j-over-slf4j and logback-classic.

The program processes files in a loop.

I need to create a separate log file for each iteration of the program. Can someone point me to the sample code or code snippet? I have done enough research but running in circles with SLF4J, log4j and Kogback.

Preferably, I would like to do all configuration programmatically, instead of a properties file.

palacsint
  • 28,416
  • 10
  • 82
  • 109
srini.venigalla
  • 5,137
  • 1
  • 18
  • 29

1 Answers1

3

You need Logback's SiftingAppender http://logback.qos.ch/manual/appenders.html#SiftingAppender. SLF4J and log4j are irrelevant here.

Edit: Follow the example configuration XML file. Change the line

MDC.put("userid", "Alice");

to set a different userId after each iteration of the program loop, then each run will have a different output file.

palacsint
  • 28,416
  • 10
  • 82
  • 109
artbristol
  • 32,010
  • 5
  • 70
  • 103