Greetings,

We are in the midst of tech stack upgrade and have upgraded to log4j
version 2.23.0. I am checking if I can do things differently or in a better
way.

We have an application not web application, but good old java/jar
application. It receives "jobs/tasks" on MQ queues. Each job can create
large number of log entries. We want to have separation of logs for each
logs.

Currently we use routers in the xml config file. This mostly works, as long
as developer remembers to set the right route values for the thread.

I'd like to do this programmatically as we have a need for splitting logs
even more. Each class can request logger based on task id and type of log
and log to that logger.

I am creating a new LoggerContext with task id as name. As application
requests the loggers, I am creating the appenders and adding it to
loggers.  At the end of task, we basically close all the taks specific
appenders. This works the way I want it to work. However
method org.apache.logging.log4j.core.Logger.addAppender(Appender) says not
exposed as public API.

Is there any better way to achieve what I want to do without using routes?

Regards,

Niranjan

Reply via email to