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

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

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
Ā
participants (2)
-
Ceki Gülcü
-
Thomas Schittli