top of page
abhilasharughwani

Simplified version of Log4j in Java

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:

  1. Console Appender: To print the log on console.

  2. File Appender: Store the log in .log file.

  3. JDBC Appender: To store the message in database table.

  4. FTP/ Telnet Appender : Send the data from one server to another.

  5. SMTP : Send the log using mail.


Layout


  • We can indicate which format should be printed on Appender.

  1. Simple Layout

  2. HTML layout : Print the messages in HTML format.

  3. XML Layout: Print the messages as XML output.

9 views0 comments

Recent Posts

See All

Battle of the Backends: Java vs Node.js

Comparing Java and Node.js involves contrasting two distinct platforms commonly used in backend development. Here’s a breakdown of their...

Comentários


bottom of page