Logging in Spring Framework using Log4j - Part (1/3) Logging Introduction

Today we are starting a log4j tutorial series under 'LOG4J configuration in Spring'. We will cover topics on 'log4j in java' and come to know what is log4j in java ?'. Here we will get a dive into basics of LOG4J and configuration of LOG4J with spring under three parts. These parts are

LOG4J configuration with Spring - Part 1 : Logging Introduction
LOG4J configuration with Spring - Part 2 : LOG4J architecture and levels
LOG4J configuration with Spring - part 3 : Log4J configuration with spring

In this particular blog we will learn, What is Logging ?, Types of Logging in Java and a brief introduction to log4j and its functionality overview.

What is Logging in Java (Spring Framework)

In computer software and application programming world logging refers to the process of recording events so that the internal structure and functioning of application can be learned and problem can be diagnosed.

Logging Functionality Overview ? Logging Components

In java logging is a three step process, these steps are listed below

1) Logger : Logger is an object that is responsible to capture event messages from the application and passes them to the framework.
2) Formatter : Once the framework receives log messages it called Formatter to format the messages in output form.
3) Handler(Adapter) : The framework at the last handover the formatted messages from Formatter to Handler or Adapter.

Solutions used to implement Logging in Java

There are a number of standard and general purpose solutions provided to implement Logging in Java , some of them are listed below :

1) Apache Log4J

Apache Log4J is a Java based logging utility and is under Apache Software Foundation. Log4J is very popular logging framework of today. Log4J supports OFF, FATAL, ERROR, WARN, INFO, DEBUG and TRACE log levels. Log4J can be configured in three ways - property file, XML file or through Java Code.

2) Java Logging API

Java Logging API is an pre build logging solution provided under java.util.logging. The logging API captures information of security failures, configuration errors, performance bottlenecks, and bugs in the application or platforms. The API is capable of delivering logs information on console, XML and store in a file format.

3) Apache Commons Logging

Apache Commons Logging is not really a logging framework, but it wraps over any one logging framework in it. More details can be found at Documentation. 

4) SLF4J

SLF4J so called Simple Logging Facade for Java (SLF4J) is a java logging api based on single fašade pattern. The logging backend is determined at compile time, this makes it easy to reduce coupling between application and logging framework. SLF4J is a smart choice whenever you decided to integrate with existing or a third party api for logging.

5) tinylog

 Tinylog provides a static logger, so it isn't necessary to create an instance of the logger before logging. In tinylog all log entries of the level info or higher are written into the console. More information can be found at Documentation

In this blog on log4j in java tutorial series we come across the basic introduction to logging in java, we come to know components and functioning of logging and all possible logging solutions to implement.