top of page
hand-businesswoman-touching-hand-artificial-intelligence-meaning-technology-connection-go-

LOG4J













Log4J is a logging tool used in the production environment. It used to find success messages ,information , warnings, errors in application while using it.Log4J used in the production environment.

By default Messages/errors printed in the console ,these are temporary location.

To see all problems from beginning to till date use Log4J.

Log4J can write errors to File, Database, Email, Network etc.Log4J provides Error details like Exception type, class an method with line numbers it occurred, Date ,Time and other information as well.


Log4J components


1. Layout

2. Appender

3. Logger



1.Logger

The object must created inside of a class as a instance variable.It is used to enable Log4J service to the current class.If we are not creating Logger object we can apply the Log4J concept.

There are 5 priority methods

Order method Name

1 debug(obj) DEBUG

2 info(obj) INFO

3 warn(obj) WARN

4 error(obj) ERROR

5 fatal(obj) FATAL



Debug

This method used to print a final/success message.

Ex:ID reated successfully etc..


Info

Print current state I the execution

Ex: If block executed,Mail sent etc..


Warn

Used to print warnings in application

Ex: local variables not used, resource not closed


Error

Used to print Exceptions like NullPointer,ArrayIndex,SQLException etc..


Fatal

This method used to print any high level exceptions



2.Appender

Appender provide details like, where to print message? Where to store log messages?

· FileAppender

· Database Appender

· Email

· Console

· Network


FileAppender

store messages in log file.


JDBCAppender

store log messages in the db table


FTP/Telnet

send messages from one server to another


SMTPAppender

send log messages using a mail

3.Layout

It provides format of the message to be printed.possible layouts are

· Simple Layout

· HTML Layout

· XML Layout

· Pattern Layout







In this Example

First I created logger object for the class.

Then created object for the Appender class. In the Appender class mention what type message to be printed. Here by using INFO simple message printing in the Console.So we have to use ConsoleAppender to see messages.To see this message creating PatternLayout with date and time format.




36 views0 comments

Recent Posts

See All
bottom of page