Ans: 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.
Ans:
Ans: There are several logging levels 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.
Ans: DEBUG: Designates fine-grained informational events that are most useful to debug an application.
Ans:
Ans: Following are features of log4j:
Ans: Following are the Pros and Cons of Logging −
Logging is an important component of the software development. A well-written logging code offers quick debugging, easy maintenance, and structured storage of an application's runtime information.
Logging does have its drawbacks also. It can slow down an application. If too verbose, it can cause scrolling blindness. To alleviate these concerns, log4j is designed to be reliable, fast and extensible.
Since logging is rarely the main focus of an application, the log4j API strives to be simple to understand and to use.
Ans: Usually in any application there two types of logs:
Ans: A log request of level p in a logger with level q is enabled if p >= q. This rule is at the heart of log4j. It assumes that levels are ordered. For the standard levels, we have ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF.
Ans: ERROR: Designates error events that might still allow the application to continue running.
Ans: FATAL: Designates very severe error events that will presumably lead the application to abort.
Ans: INFO: Designates informational messages that highlight the progress of the application at coarse-grained level.
Ans: OFF: The highest possible rank and is intended to turn off logging.
Ans: TRACE: Designates finer-grained informational events than the DEBUG.
Ans: WARN: Designates potentially harmful situations.
Ans: The best way to migrate from java.util logged to log4j is to use global file search/replace method. It will replace with “org.apache.log4j.Logger”
Ans: The two static methods for obtaining a logger object are:
Ans: Appender Object: This is a lower-level layer of log4j architecture which provides Appender objects. The Appender object is responsible for publishing logging information to various preferred destinations such as a database, file, console, UNIX Syslog, etc.
Ans: ObjectRenderer: The ObjectRenderer object is specialized in providing a String representation of different objects passed to the logging framework. This object is used by Layout objects to prepare the final logging information.
Ans: Any other named Logger object instance is obtained through the second method by passing the name of the logger. The name of the logger can be any string you can pass, usually a class or a package name as we have used in the last chapter and it is mentioned below −
static Logger log = Logger.getLogger(log4jExample.class.getName());
Ans: Following syntax defines the root logger with WARN mode turning DEBUG mode off.
# Define the root logger with appender file log = /usr/home/log4j log4j.rootLogger = WARN, FILE
Ans: c: Used to output the category of the logging event. For example, for the category name "a.b.c" the pattern %c{2} will output "b.c".
Ans: The format characters used in log4j are:
Ans: Log4j file is defined by the name log4j.properties, it keeps properties in key-value pairs. By default, the log manager looks for a file name log4j.properties in the CLASSPATH.
Ans: 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.