Tags

, , ,

Here we see some comparisons on the logging frameworks. The below table shows the comparison of three logging frameworks Apache, Java logging and Log4j based on the logging features.

 

Apache Logging

Java Logging

Log4j

General

License

Apache

Oracle

Apache

Source Available

Yes

Yes

Yes

Website

Link

Link

Link

Basic Features

Logging simple text messages

Yes

Yes

Yes

Log levels to filter messages

All

Info

Fine

Finer

Finest

Config

Severe

Warning

All

Info

Fine

Finer

Finest

Config

Severe

Warning

Debug
Trace
Info
Warn
Error
Fatal

Log file rotation by date

Yes

No

Yes

Log file rotation by size

No

Yes

Yes

Log file rotation max parts

No

Yes

Yes

Change logging settings at run time

No

No

Yes

Advanced Features

Thread-safe logging

Yes

Yes

Yes

Multi threading

Yes

Yes

Yes

Asynchronous logging

No

No

Yes

   Documentation

API Reference

Link

Link

Link

Documentation

Docs

Docs

Docs

Click here to see the sample logging using apache.

Click here to see the sample logging using java util logging.

Click here to see the sample logging using Log4j.

Based on the comparison of 3 logging frameworks, log4j has more precedence than the other 2 logging frameworks. It has the features of asynchronous logging, log file rotation by date and mainly changing the logging properties during run time without deploying their packages nor restarting the Tomcat Server.

Configuring a Web Application with log4j Logging
You can configure your Web applications to use log4j for their own logging, which is in addition to the Tomcat Runtime logging configuration

1. Add log4.j dependency in your <Project>/pom.xml
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/log4j.jar</systemPath>
</dependency>

2. Create a log4j.xml file and place it in the location <Project>\src\main\resources\

Note:
Do make sure the log4j.xml is present in resources folder so that it is copied over to classes folder after building your package.

Advertisements