0

I'm using Log4j in my server project. Until now I logged multiple threads to multiple files without any issue.

I now need to change the Log4j implementation to log everything to one single file.

Browsing a little I've found out that it's possible to have two appenders to one Logger by changing the Log4J configuration, but is it possible to configure it to have 'N' appenders? With 'N' I mean from 200 to 2000 or more threads writing to one single file.

Also I would like to know if some syncronization problems are to be expected at some point, even if it is going to slow down my server.

I have also found SLF4J has native implementation to do this, but do you people recommend it?

user2256799
  • 229
  • 1
  • 3
  • 10
  • 2
    If you want to log to a single file, you only need one appender, no? – Thilo Apr 17 '17 at 08:24
  • The problem I'm facing right now is that I've got too many files opened in my server. I believe the library log4j can not handle well multiple threads writing simultaneously in the same file, altough is only one appender I think it is being called from multiple sources at a time. – user2256799 Apr 17 '17 at 08:29
  • 3
    What problems are you seeing with multiple threads logging to the same file via Log4J. If your definition of working is "the output is interleaved, but each individual message is written atomically, and you can put a thread identifier in your layout definition" then that should be fine. http://stackoverflow.com/a/565904/14955 – Thilo Apr 17 '17 at 08:41

0 Answers0