srini.venigalla
srini.venigalla

Reputation: 5145

SLF4J code snippet to log messages into a file

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.

Upvotes: 1

Views: 434

Answers (1)

artbristol
artbristol

Reputation: 32437

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.

Upvotes: 3

Related Questions