Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Log4j Interview Questions and Answers

Ques 1. What is Log4j?

Log4j (Log for Java) is logging framework provided by apache foundation for java based applications.
In the applicaitons, if you want to log some information, like any event triggered, or any Database updated is happened, we have the need to log the specific information or error for the useful of the application.
To debug any issues in applications, we have to log the error/exceptions in the logs. For this we will use log4j mechanism.
Log4j logs the information and shows this information in different targets. The different targets are called appenders (console, file etc)

Is it helpful? Add Comment View Comments
 

Ques 2. What are the different logging levels?

There are several logging levels that you can configure in you applicaiton.

Those are FATAL, ERROR, WARN, TRACE, DEBUG, INFO and ALL in apache logging. 
Default logging level is INFO.

Is it helpful? Add Comment View Comments
 

Ques 3. What is the importance of logging applications?

Logging helps in debugging as well. Although debuggers are available but frankly it takes time to debug an application using a debugger. An application can be debugged more easily with few well-placed logging messages. So we can safely say that logging is a very good debugging tool. If logging is done sensibly and wisely, it can provide detailed context for application failures.
In distributed applications (e.g. web/remote applications), the logging is very important. The administrator can read logs to learn about the problems that occurred during some interval.
Java's built-in APIs provide logging options but they are not that flexible. Another option is to use Apache's open source logging framework called log4j. 

Drawbacks of logging applications:
There are some drawbacks of use logging in your application. For example: logging will
- pollute the code
- increase the size of the code
- reduce the speed

These are important points because, we ultimately want efficient applications. Log4J has the solution to this. You may turn on or turn off the logging at runtime by changing the configuration file. This means no change in the Java source code (binary).

To reduce the code now in Spring Framework you can use of AOP (Aspect Oriented Programming) where you can configure log mechanisms easily.

Is it helpful? Add Comment View Comments
 

Ques 4. Describe about logger levels in log4j.

Before using log4j framework, one should be aware of different categories of log messages. Following are 5 categories:

DEBUG
The DEBUG Level is used to indicate events that are useful to debug an application. Handling method for DEBUG level is: debug().

INFO
INFO level is used to highlight the progress of the application. Handling method for INFO level is: info().

WARN
The WARN level is used to indicate potentially harmful situations. Handling method for WARN level is: warn().

ERROR
The ERROR level shows errors messages that might not be serious enough and allow the application to continue. Handling method for ERROR level is: error().

FATAL
The Fatal level is used to indicate severe events that will may cause abortion of the application. Handling method for FATAL level is: fatal().

If you declare log level as debug in the configuration file, then all the other log messages will also be recorded. 
If you declare log level as info in the configuration file, then info, warn, error and fatal log messages will be recorded.
If you declare log level as warn in the configuration file, then warn, error and fatal log messages will be recorded.
If you declare log level as error in the configuration file, then error and fatal log messages will be recorded.
If you declare log level as fatal in the configuration file, then only fatal log messages will be recorded.

Is it helpful? Add Comment View Comments
 

Ques 5. What are the three main components in log4j?

There are 3 main components that are used to log messages based upon type and level. These components also control the formatting and report place at runtime. These components are:

  • loggers
  • appenders
  • layouts

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2024 WithoutBook