YouTube Icon

Interview Questions.

Log4j Interview Questions and Answers - Jul 14, 2022

fluid

Log4j Interview Questions and Answers

Q1. What is Log4j?

Ans: Log4j is a fast, bendy and reliable logging framework written in Java developed in early 1996. It is shipped under the Apache software program license and can be used for small to massive scale initiatives. It has been ported to the languages like C, C++, C#, Python, etc.

Q2. What are the additives of log4j?

Ans:

Logger: It is used to log the messages.

Appender: It is used to post the logging records to the vacation spot like file, database, console and so on.

Layout: It is used to format logging data in different styles.

Q3. What are the unique logging ranges?

Ans: There are several logging ranges that you can configure in you applicaiton

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

Q4. What is purpose of DEBUG log level?

Ans: DEBUG: Designates great-grained informational occasions that are maximum beneficial to debug an utility.

HubSpot Video
 

Q5. Why to use Log4j?

Ans:

Being open-supply its absolutely unfastened to use.

You can without difficulty keep log information into either files or even databases.

Can be used for tasks of any sizes small or large.

Q6. What are the functions of log4j?

Ans: Following are capabilities of log4j:

It is thread-secure.

It is optimized for speed.

It is primarily based on a named logger hierarchy.

It helps more than one output appenders in keeping with logger.

It supports internationalization.

It isn't always limited to a predefined set of centers.

Logging conduct can be set at runtime using a configuration file.

It is designed to address Java Exceptions from the start.

It makes use of multiple degrees, namely ALL, TRACE, DEBUG, INFO, WARN, ERROR and FATAL.

The format of the log output may be without problems modified by means of extending the Layout magnificence.

The goal of the log output as well as the writing approach can be altered by implementations of the Appender interface.

It is fail-prevent. However, although it actually strives to ensure shipping, log4j does now not guarantee that each log assertion will be brought to its vacation spot.

Q7. What are Pros and Cons of Logging?

Ans: Following are the Pros and Cons of Logging −

Logging is an essential factor of the software program improvement. A nicely-written logging code gives short debugging, clean protection, and structured garage of an utility's runtime information.

Logging does have its drawbacks also. It can gradual down an utility. If too verbose, it may reason scrolling blindness. To alleviate these issues, log4j is designed to be reliable, fast and extensible.

Since logging is rarely the principle cognizance of an software, the log4j API strives to be simple to apprehend and to apply.

Q8. What are different styles of logs?

Ans: Usually in any software there  forms of logs:

Application server logs: These are the logs configured at the utility server degree. As an instance in tomcat,

we have log documents referred to as localhost.Log. Tomcat.Log,catalina.Log, stdout.Log, sterr.Log. These types of logs are displaying with default settings described in logging.Properites placed on your tomcat installation folder/conf folder.

If you want custom settings, we ought to alternate the specific parameters in logging.Homes in conf folder of tomcat listing.

Application logs: We can define logging at each applicaiton stage, For this we need to create log4j.Xml or logging.Properties in WEB-INF/lessons folder.

Q9. How do Levels Works?

Ans: A log request of level p in a logger with stage q is enabled if p >= q. This rule is on the coronary heart of log4j. It assumes that stages are ordered. For the same old levels, we have ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF.

Q10. What is motive of ERROR log stage?

Ans: ERROR: Designates blunders activities that would nevertheless allow the application to maintain going for walks.

Q11. What is reason of FATAL log stage?

Ans: FATAL: Designates very excessive error activities a good way to possibly lead the software to abort.

Q12. What is purpose of INFO log degree?

Ans: INFO: Designates informational messages that spotlight the development of the software at coarse-grained degree.

Q13. What is cause of OFF log level?

Ans: OFF: The highest viable rank and is meant to turn off logging.

Q14. What is motive of TRACE log stage?

Ans: TRACE: Designates finer-grained informational events than the DEBUG.

Q15. What is cause of WARN log degree?

Ans: WARN: Designates doubtlessly harmful conditions.

Q16. Mention what's the best way emigrate from java.Util logging to log4j?

Ans: The excellent manner emigrate from java.Util logged to log4j is to use worldwide file search/replace method. It will update with “org.Apache.Log4j.Logger”

Q17. Mention what are the two static techniques for acquiring a logger object?

Ans: The two static methods for obtaining a logger object are:

Public static Logger getRootLogger()

Public static Logger getLogger(String call)

Q18. What is the cause of Appender item?

Ans: Appender Object: This is a decrease-stage layer of log4j architecture which presents Appender items. The Appender item is liable for publishing logging records to various favored destinations which include a database, report, console, UNIX Syslog, and so forth.

Q19. What is the reason of ObjectRenderer item?

Ans: ObjectRenderer: The ObjectRenderer object is specialised in providing a String illustration of different items passed to the logging framework. This object is used by Layout items to prepare the very last logging facts.

Q20. How will you create a logger in any magnificence?

Ans: Any other named Logger item instance is obtained via the second one technique by way of passing the call of the logger. The call of the logger may be any string you can bypass, generally a class or a package call as we've got used inside the final bankruptcy and it is stated underneath −

static Logger log = Logger.GetLogger(log4jExample.Magnificence.GetName());

Q21. How will you outline a root logger turning DEBUG mode off?

Ans: Following syntax defines the foundation logger with WARN mode turning DEBUG mode off.

# Define the basis logger with appender file log = /usr/domestic/log4j log4j.RootLogger = WARN, FILE

Q22. What is the cause of c character used within the conversionPattern of PatternLayout object?

Ans: c: Used to output the class of the logging event. For example, for the category call "a.B.C" the pattern %c2 will output "b.C".

Q23. Explain what are the layout characters used in log4j?

Ans: The format characters utilized in log4j are:

L: it is used to output the line wide variety from where the logging request became processed or issued

M: It is used to output the software supplied message associated with the logging occasion

P: It is used to output the priority of the logging occasion

C: It is used to output the class name of the caller issuing the logging request

Q24. How log4j file is described?

Ans: Log4j report is defined by means of the call log4j.Houses, it keeps houses in key-fee pairs. By default, the log supervisor looks for a file name log4j.Properties within the CLASSPATH.

Q25. Mention what's the difference among Threshold and LevelRangeFilter in log4j?

Ans: Both Threshold and LevelRangeFilter does the equal aspect. However threshold have to be quicker. Filters allow you to enforce your very own good judgment, and you may additionally link them together if required. If you need a simple threshold functionality, then “threshold” function might be sufficient.




CFG