Introduction
In Eclipse or any IDE (Integrated development environment), the console has a limited memory to store all the logs or print the messages like errors, exceptions etc.. Therefore log4j was invented.
Log4j is a logging tool.
We can get and store the logs/messages in following formats:
1.File (name.log)
2.Database
3.Email (send mail)
4.Console
Logs are usually used by support team or Dev team to read the errors and fix the issues.
Steps on how to check the console memory in Eclipse
Window->Preferences->Run/Debug->Console-see the memory i.e. 80000
Log4j framework components
Logger
Layout
Appender
Picture courtesy: innovationm.co
Logger
Logger must be created inside the class for which Log4j is required.
Eg. There are 3 class, choose which class needs the Log4j where there are chances of highest errors.
Appender
It is used to specify where to store the log message.
Types of Appenders:
Console Appender: To print the log on console.
File Appender: Store the log in .log file.
JDBC Appender: To store the message in database table.
FTP/ Telnet Appender : Send the data from one server to another.
SMTP : Send the log using mail.
Layout
We can indicate which format should be printed on Appender.
Simple Layout
HTML layout : Print the messages in HTML format.
XML Layout: Print the messages as XML output.
Comentários