8

I have my own logging engine which writes the logs on a separate thread with a blocking queue. For the sake of using "standard software" I am thinking about switching to log4j.

I don't want my highly concurrent software to be slowed down by log commands that write everything to disk as some as the command is called. Can log4j be used as a dumpster instead?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Franz Kafka
  • 10,623
  • 20
  • 93
  • 149
  • 3
    logj4 might not be your best bet, if you need highly concurrent logging you should go w/ just something like a concurrent linked queue (or blocking) and a dedicated polling thread. Logging by default blocks hard (if you need to log for real). If you need even higher concurrency you can use a queue per thread (and still poll each queue by a separate one) – bestsss May 22 '11 at 17:15
  • See http://stackoverflow.com/a/13144054/603516 for some links to related log4j locking issues. – Vadzim Oct 30 '12 at 17:05

2 Answers2

7

Log4j is the logging implementation on most JavaEE app-servers out there, so that's a good advert for its concurrency abilities.

Having said that, I have seen Log4j 1.2 deadlock under high load conditions. A bit of investigation highlighted some scarily bad synchronization in the source code. Apparently, this was fixed in Log4j 1.3, although development on this has slowed or stopped altogether - I get the feeling much of the source was unsalvageable.

However, if you're free to choose, then you should consider Logback instead, the spiritual successor to Log4j. It's a ground-up redesign, and is probably a better option for you.

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • 1
    Most (all) EE servers are anything but heavily concurrent, simply they are not. Saying that after 2 days+night battles vs tomcat data races. Note. as "heavily concurrent" I assume 32+ cores that don't get starved. – bestsss May 22 '11 at 21:17
3

Check out log4j's asynchronous appender, it buffers log messages ad passes them on to appenders using a separate thread. It might be that you decide the log4j async appender is not appropriate (here are some complaints about it), you could always make your own appender.

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276