beinghuman
beinghuman

Reputation: 2136

configuring slf4j to store logs in different files based on log level

I am using slf4j+log4J in Spring. I want to store logs in different files based on log levels and also in one common file,so that I will first check this common log file and later review individual level logs files. In short all level logs in one log file and then individual level logs in individual files.

Please guide me how to do this? Also ,suggest suitable purpose of the levels keeping live projects in view.like where to use info,debug etc.

Upvotes: 0

Views: 685

Answers (1)

Adrian Shum
Adrian Shum

Reputation: 40036

It should be straight forward. I am not giving the config directly but I think it should be easy for you to figure out the real config.

First, in the root logger (or the parent logger you want), point to several appenders, e.g. FILE_ALL, FILE_ERROR, FILE_WARN etc

Then declare FILE_ALL as normal file appender, which accept log event of all levels.

For other "level-specific" appender, it is still a normal file appender, PLUS a filter config. You may make use of LevelMatchFilter and declare the "level to match" as the corresponding level of the file.

Upvotes: 1

Related Questions