Home Interview Questions and Answers Log4j Interview Questions and Answers For Graduates Part-2

log4j11.What is the purpose of LogManager object?
LogManager − The LogManager object manages the logging framework. It is responsible for reading the initial configuration parameters from a system-wide configuration file or a configuration class.

12.What is the use of log4j.properties?
The log4j.properties file is a log4j configuration file which keeps properties in key-value pairs. By default, the LogManager looks for a file named log4j.properties in the CLASSPATH.

13.What is the purpose of layout object in Appender?
layout − Appender uses the Layout objects and the conversion pattern associated with them to format the logging information.

14.What is the purpose of target in Appender?
target − The target may be a console, a file, or another item depending on the appender.

15.What is the purpose of level in Appender?
level − The level is required to control the filtration of the log messages.

16.What is the purpose of threshold in Appender?
threshold − Appender can have a threshold level associated with it independent of the logger level. The Appender ignores any logging messages that have a level lower than the threshold level.

17.What is the purpose of filter in Appender?
filter − The Filter objects can analyze logging information beyond level matching and decide whether logging requests should be handled by a particular Appender or ignored.

18.How will you define a root logger with appender file using log4j.properties?
Following syntax defines the root logger with appender file:

# Define the root logger with appender file
log = /usr/home/log4j
log4j.rootLogger = DEBUG, FILE

19.How will you define a file appender using log4j.properties?
Following syntax defines a file appender −

# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=${log}/log.out

20.How will you define the layout of file appender using log4j.properties?
Following syntax defines the layout of file appender −

# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n

You may also like

Leave a Comment