4

I have 4 java/Java EE applications- Two are server based j2ee applications running in WebSphere. Other two are standalone java applications. My logging framework is log4j using log4j.properties.

Question 1: Can I have a same log file for logging from all the applications. Will it cause any file writing issues even if all the applications are writing at the same time?

Question 2: If all the applications can write without any issues, how can I pre-append the application name to each of the log statement?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
user1929905
  • 389
  • 3
  • 9
  • 25
  • Is there a reason why you'd want to do this? Maybe you could log to separate log files and then use some form of log file analysis tool to review the data logged. I'm not sure if there are tools that amalgamate the data from multiple log files, but it'd be worth a look. – Mr Moose Jan 16 '13 at 08:32
  • actually the requirement is to have single log file across the applications – user1929905 Jan 16 '13 at 08:33
  • Use some kind of log aggregation software... This requirement of yours doesn't make too much sense... – ppeterka Jan 16 '13 at 11:35
  • possible duplicate of [Logging from multiple apps/processes to a single log file](http://stackoverflow.com/questions/2596092/logging-from-multiple-apps-processes-to-a-single-log-file) – Devon_C_Miller Jan 16 '13 at 16:27

1 Answers1

2

Question 1:

I believe by default it will NOT work.

If you are using SLF4J, consider switching to LogBack. In LogBack's File Appender, there is a prudent mode that allow multiple FileAppenders in different JVMs to write to same log file (of course, all of them need to have prudent mode turned on)

http://logback.qos.ch/manual/appenders.html#prudent

Question 2: You should NEVER make the log message different by manually logging your app name.

There are quite some way to do. The easiest way is: As you are having two different applications, you can have different logging config files for them. Just add corresponding app name information in the log pattern used by the appender will serve what you want.

Adrian Shum
  • 38,812
  • 10
  • 83
  • 131
  • 1
    so can i assume that i will end up a corrupted file? – user1929905 Jan 16 '13 at 10:21
  • 1
    I don't think you are replying to my answer right? My suggested approach won't lead to corrupted file. If you are referring to comments under another answer, I think I have quoted enough reference for you to decide. You *may* (depends on JVM impl) have corrupted file, and file rolling is most likely not working properly too. – Adrian Shum Jan 17 '13 at 01:57