Concurrent logging to same log file
Hi,
I'm using Java Logging API for logging. I'm planning to let the same application run on several servers, and they all should write things into the same log file in the file system.
Is that possible? Are there any prerequisites to do that? I couldn't find any hints in the Logging API documentation nor in this forum.
Thanks in advance!
Mike
[381 byte] By [
micro5a] at [2007-11-27 11:13:38]

ive never used a logging api so take my advice with a grain of salt...
id imagine you'd create a queue that takes Strings.
this thread-safe queue would be where all the messages funneled into.
then youd have another thread taking one thing at a time off the queue
and writing it into the file.
So basically all you need is a class with a Queue with 2 methods:
synchronized void addLogMessage(string)
synchronized String getNextLogMessage()
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Queue.html
TuringPest, I believe he is talking about seperate applications, not seperate threads in a single application. So if this is true, my advice to the OP is to simply NOT have the applications share a single log file. That's not what logging (to files anyway) is for. A log file is more for diagnostics of a single application.
@TuringPest,
Java Logging API is a feature since Java 1.4, quite useful.
Before I start creating workarounds I'd like to know whether Logging API can handle concurrent logging requests into the same file.
@warnerja,
It's about separate applications, that's right.
Logging API can handle a broad range of log levels, from diagnostical logs to informational ones. Diagnostical logs I would of course store on the individual servers but I need a short, centrally stored summary of what all the application instances have done.
> @TuringPest,
> Java Logging API is a feature since Java 1.4, quite
> useful.
>
> Before I start creating workarounds I'd like to know
> whether Logging API can handle concurrent logging
> requests into the same file.
I don't think it can, as I recall. Log4J can, though
> I don't think it can, as I recall. Log4J can, though
I thought they were equivalent? But thanks for the hint.
Message was edited by:
micro5