Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j Logging to a Shared Log File

Tags:

java

log4j

Is there a way to write log4j logging events to a log file that is also being written to by other applications. The other applications could be non-java applications. What are the drawbacks? Locking issues? Formatting?

like image 867
Paul Croarkin Avatar asked Nov 12 '08 19:11

Paul Croarkin


People also ask

Where is the log4j log file?

The Log4j logging settings are stored in the file app_data /conf/server/log4j. properties, where app_data is the application data folder. You can edit this file directly on the server or open it by clicking Settings > Logging.

How does log4j logging work?

Log4j allows logged messages to contain format strings that reference external information through the Java Naming and Directory Interface (JNDI). This allows information to be remotely retrieved across a variety of protocols, including the Lightweight Directory Access Protocol (LDAP).

Does logging use log4j?

log4j is a reliable, fast and flexible logging framework (APIs) written in Java, which is distributed under the Apache Software License. log4j is a popular logging package written in Java.


2 Answers

Log4j has a SocketAppender, which will send events to a service, which you can implement yourself or use the simple implementation bundled with Log4j.

It also supports syslogd and the Windows event log, which may be useful in trying to unify your log output with events from non-Java applications.

If performance is an issue at all, you want a single service writing the log file, rather than trying to coordinate a consistent locking strategy among diverse logging applications.

like image 132
erickson Avatar answered Sep 28 '22 01:09

erickson


Your best bet might be to let each application log separately, then put a scheduled job in place to 'zipper' the files together based on time. If you need really up-to-date access to the full log, you could have this run every hour.

like image 31
Dana the Sane Avatar answered Sep 28 '22 02:09

Dana the Sane