Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4J at Request Scope

Tags:

java

log4j

Before writing this query, I reviewed similar queries at:

  • Log4j: One log file per request
  • Log TraceNo for each request in web application using Log4j

I felt my query sounds similar but not the same.

Did you ever come across grouping of log messages on request entry and flush them on response close. i.e. the sequence of operations expected would be as below:

  1. configure the Logger to request scope.
  2. server receives request.
  3. logs written by each of the context beans be buffered by request scoped logger.
  4. response prepared, flushed and closed.
  5. logger gets notified that response is complete.
  6. now logger writes the buffered messages as a batch to associated appender and then clears its buffer.

I am looking for such a possibility with currently available log4j implementation.

Please share your opinions.

like image 612
Ravinder Reddy Avatar asked Oct 10 '11 13:10

Ravinder Reddy


People also ask

What is log4js used for?

Log4j is used by developers to keep track of what happens in their software applications or online services. It's basically a huge journal of the activity of a system or application. This activity is called 'logging' and it's used by developers to keep an eye out for problems for users.

Is log4j installed by default?

From what I can see Apache log4j 2 is an open-source Java-based logging framework that should not be installed by default on your Apache server, hence you've not manually installed/configured it then CVE-2021-44228 should not affect your server.


1 Answers

include request id into log (you may use log4j's NDC). sort log file by this id and by timestamp.

i think it's wrong, to record events in the order, different from their original order. This may lead to a a very big confusion.

like image 163
aav Avatar answered Sep 21 '22 21:09

aav