multithreading - logging one thread in Java using log4j -


I have a web application written in Java, and I have a thread-pool.

The application is too big, and I can not make big changes, for example, I can not change log4j.

I am performing a batch process in the thread pool, and I want to log in, which is run to execute the process.

Always a thread is active in the thread pool.

How can I do this?

I think you have other threads, such as request threads that you do not want to log into Logfile, and want to log in to only dedicate only one event from the batch.

To write all the logs of the batch in a logfile, you will need to create some runtime tweaks on the log4j configuration on runtime, you add these changes at the beginning of the batch, and when the batch completes the changes - Delete static log4j application configs, and runtime log-44 configuration changes will not affect the remaining app.

This change is for you to enable logging for batch only:

  • At the beginning of the batch, a new appender for Cataegory / Logger instances Add, from which you want to log in
  • The new applicant is configured with the current thread (Thread Pool Thread on which the batch is running). The appendor uses it as part of its internal filtering to write the log only from the given thread, Custom Apeender writes logs only by appointing a regular appender, who writes, as long as you want, log Does this.
  • And remove the logger from the end of the batch, (or just disable the appender by setting the log thread blank.)

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -