10 Interview Questions answers for Log4j in java

What is Log4j?

Log4j is logging framework provided by apache foundation for java based applications.
In the applicaitons, if you want to log the 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 .
Log4js log the information and show this information in different targets. The different targets are called appenders (console).

How do you define logging for your applicaiton

if you want to add logging for any applicaiton, you have to download the log4j framework from the apache site.
Once log4j jars are downloaed, make sure that these jars are in classpath of your application. let say you have webapplicaiton need to be added log4j. In this case, log4j jars are copied to WEB-INFO/lib folder of your webapplication
create new file either logging.properties or log4j.xml which will be copied to WEB-INF/classes folder
logging.properties contain the all the configuraiton related to looging mechanism and logger level and package that you want to define logger level.

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 OR ALL in apache logging. Default logging level is INFO.

what are defifferent types of logs?

usually in any application there two types of logs
1.Application server logs :- These are the logs configured at the applicaiton server level. for example in tomcat,
we have log files called localhost.log. tomcat.log,catalina.log, stdout.log, sterr.log. all these logs are showing with default settings defined in logging.properites located in your tomcat installation folder/conf folder.
if you want custom settings, we have to change the different parameters in logging.properties in conf folder of tomcat directory.

2.Application logs:- We can define logging at each applicaiton level, For this we have to create log4j.xml or logging.properties in WEB-INF/classes folder

what are dfifferent appendeds that can configure in log4j?

There are different appendeds that we can configure in log4j are CONSOLE,FILES,DATABASE,JMS, EVENT LOGGING

CONSOLE in log4j:- if we use this as appenders in your applicaiton, log4j logs the information in the console or command prompt window that is started with statup script.
Files in log4j:- Files Appender is used to log the information into our custom name files. when we are configuring this appender, we can spcefy the file name

No comments:

Post a Comment

Note: only a member of this blog may post a comment.