Search code examples
javalogbackslf4j

SLF4J-Logback : Multiple Pattern based on Log Level


Logback is used because we need some Appenders which are not provided by log4j .

Requirement: For Log level Error we want to use custom pattern which will add information based on stack trace.

For all other log level it should use simple pattern.

All the log output should go in same file.

Below things are tried : Created two Appenders, one for error log level and other for other log level. When same destination file is used for both Appenders then error log are not getting written to file. When diffrent destination file is used for both appenders then two files are getting created one with error log level and other with all other log level

With log4j2 found some pointers but with logback unable to find solution so far.

Can someone please suggest some approach


Solution

  • In the appender config, set prudent to true. This will allow multiple appenders to write to the same file.