[logback-user] separate task log files (slf4j + logback)

Oleksandr Gavenko gavenkoa at gmail.com
Tue Oct 17 15:57:21 CEST 2017


On Tue, Oct 17, 2017 at 4:28 PM, Денис Матвеев <denism78 at gmail.com> wrote:
> I began to consider the possibility of logging in a new major Java
> application and so far I could not find (jul, logback) how to do the
> following:
> - Loggers for different subtasks are created inside the program
> (LoggerFactory.getLogger(logName)), I want the logName to be the name of the
> log file, the number of subtasks is unknown in advance,
>
You need to use https://logback.qos.ch/manual/mdc.html

Logger names are capable to be filtered in hierarchical way. Your
thoughts to use them differently are ill minded...

In order to write to different file names you need to implement custom
writer/appender.

It's better to provide job in in MDC context:

MDC.put("job-id", "money-pump-2");
if ( ! pumpMoney())
    log.error("where is my money?");
MDC.remove("job-id");

and collect and route logs in Fluentd, Logstash, Flume, Kafka etc or
save to storage like Elasticsearch, MongoDB, Couchbase, etc and do
business analyze / troubleshooting by filter on job-id .


More information about the logback-user mailing list