Blog Archive

Theme images by Storman. Powered by Blogger.

Sunday, August 21, 2016

Frequently Asked Log4j Interview Questions with Answers.

Frequently Asked Log4j Interview Questions with Answers. Latest Log4j Interview Questions and Answers. Most Frequently Asked Log4j Interview Questions And Answers.

1) Explain what is Log4j?

Log4j is a fast, flexible and reliable logging framework  written in Java developed in early 1996. It is distributed under the Apache software license and can be used for small to large scale projects.  It has been ported to the languages like C, C++, C#, Python, etc.

2) Explain why to use Log4j?

Being open-source its completely free to use.
You can easily save log information into either files or even databases.
Can be used for projects of any sizes small or large.

3) Mention what are the three principal components of Log4j?

The three principal components of Log4j are

4) Inside logger component what are the different log levels?

Different log levels inside logger components are


5) Explain what are Appenders in Log4j?

Appenders are used to deliver LogEvents to their destination. In simple words, it is used to write the logs in the file.


6) Mention what are the different types of Appenders?

Some of the Appenders type include

ConsoleAppender logs to standard output
FileAppender prints logs to some file
Rolling file appender to a file with maximum size

7) Explain what is layouts in log4j?

Layout in log4j is responsible for formatting logging information in different styles.

8) Mention what are the two static methods for obtaining a logger object?

The two static methods for obtaining a logger object are

Public static Logger getRootLogger()
Public static Logger getLogger(String name)

9) Mention what are the other support objects in Log4j?

There are other support objects in Log4j framework they are

Level Object
Filter Object
Object Renderer
Log Manager

10) How log4j file is defined?

Log4j file is defined by the name, it keeps properties in key-value pairs. By default, the log manager looks for a file name in the CLASSPATH.

11) Explain what is the command to write your logging information into a file?

To write your logging information into a file, you would need to use a command org.apache.log4j.FileAppender

12) Mention what are the logging methods provided by logger class?

Logger class provides a variety of methods to handle logging activities.  To obtain a logger object it provides two static methods

Public static logger getRootLogger();
Public static logger getLogger(String name);

13) In log4j how can you log into the database?

The log4j API provides the object org.apache.log4j.jdbc. JDBCAppender object can put logging information in a particular database.

14) Explain whether log4j is a thread safe?

Log4j is a thread safe, log4j components are built to be used in multithread systems.

15) Explain whether a log output format can be customized?

Yes, you can extend the layout class to create your own customized log format. Appenders can be parameterized to use the layout of your choice.

16) Explain what are the system properties checked by log4j?

The system properties checked by log4j are

Log4j debug, if true, log4j will show internal debugging messages to the console
defaultInitOverride, if true, log4j will not execute default initialization
configuration, URL for default initialization configuration file
configurationClass, Class name for configurator to execute default initialization configuration file
ignoreTCL, if true, the thread class loader will be overlooked when loading classes

17) Mention what is the role of filter in log4j?

Filter objects in log4j decide whether logging request should be handled by a particular Appender or ignored.

18) Explain how can you get multiple processes to log to the same file?

You may have each process log to a socket Appender. The receiving socket server can receive all the events and send them to a single log file.

19) Mention what is the difference between Threshold and LevelRangeFilter in log4j?

Both Threshold and LevelRangeFilter does the same thing. However threshold should be faster. Filters enable you to implement your own logic, and you can also link them together if required. If you need a basic threshold functionality, then “threshold” function will be enough.

20) Mention what does .class mean in log4j context?

In log4j context, .class is used to get the full name of your class and that string is used to configure this logger object.  For example, logger.getlogget (Myclass.class)

0 on: "Frequently Asked Log4j Interview Questions with Answers."