[logback-user] Logback FileAppender question: is it able to create log filenames dynamically by a string passed e.g. in LOGGER.trace()?

Ceki Gülcü ceki at qos.ch
Tue Aug 30 21:26:44 CEST 2022


Hi Thomas,

SiftingAppender is probably what you are looking for.

https://logback.qos.ch/manual/appenders.html#SiftingAppender
-- 
Ceki Gülcü

Sponsoring SLF4J/logback/reload4j at https://github.com/sponsors/qos-ch


On 8/30/2022 2:59 PM, Thomas Schittli wrote:
> Good afternoon
> 
>  
> 
> The documentation for SLF4J and Logback is very detailed 😊, but
> unfortunately it is still difficult to understand the various
> possibilities and mechanisms, so I have a question:
> 
>  
> 
> Is it possible to configure the logback FileAppender
> so that it automatically / dynamically creates logfile names based on a
> string which the developer passes in e.g. LOGGER.trace()?
> 
>  
> 
> The background to the idea is as follows:
> 
>  
> 
>  1. The developer is programming a new module (e.g. a configuration manager)
>     and he would like to have the log entries summarised in a separate
>     log file.
> 
>  2. Therefore, he calls something like that: LOGGER.trace(“Config-Mgr”,
>     “Message”)
> 
>  3. SLF4J / Logback automatically reads this string and create this
>     Logfile: AppLog-Config-Mgr.log
> 
> 
>  4. The central element is that we do not have to modify logback.xml and
>     create an appender for each Logfile.
> 
>     This means that if the user now calls e.g.:
>     LOGGER.trace(“User-Actionlog”, “Message”)
>     then this new log file will created without having to modify
>     logback.xml:
>     AppLog-User-Actionlog.log
> 
>  
> 
> 
> Thank you very much for any tips & tricks 😊
> 
> Thanks a lot, kind regards,
> Thomas
> 
>  


More information about the logback-user mailing list