Without Book Interview Questions and Answers | Online Test | Moct Test
Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Institute Training Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

Log4j Interview Questions and Answers

Ques 1. What is Log4j?

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

Is it helpful? Add Comment View Comments
Ques 2. How do you define logging for your application?
Ans. To define logging for your application, you have to download the log4j framework (log4j.jar) from the apache site.
Once log4j jars are downloaded, make sure that these jars are in classpath of your application. let say you have web-application 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/log4j.xml contains the all the configuration related to logging mechanism and logger level and package that you want to define logger level.

Example:
logging.properties:
logger.level=INFO
logger.handlers=CONSOLE,FILE,RejRec
handler.RejRec=org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
handler.RejRec.level=WARN
handler.RejRec.formatter=RejRec
handler.RejRec.properties=append,autoFlush,enabled,suffix,fileName
handler.RejRec.append=true
handler.RejRec.autoFlush=true
handler.RejRec.enabled=true
handler.RejRec.suffix=.yyyy-MM-dd
handler.RejRec.fileName=E\:\\Docs\\WithoutBook\\DID\\jboss-eap-6.2\\standalone\\log\\RejectedRecords.log

log4j.xml:
<log4j:configuration>

<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
       <appender-ref ref="LOG"/>
</appender>

 <appender name="MEETING-APP-LOG" class="org.apache.log4j.DailyRollingFileAppender"> <param name="File" value="E:/Softwares/glassfish_dump/glassfish/domains/domain1/logs/meeting_app.log" /> <param name="Append" value="true"/> <param name="DatePattern" value="'.'yyyy-MM-dd-a"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{yyyy-MM-dd} %d{HH:mm:ss,SSS} %-5p [%t] %c - %m%n" /> </layout> </appender>

 <logger name="com.withoutbook" additivity="false">
        <level value="warn"/>
        <appender-ref ref="MEETING-APP-LOG"/>
</logger>
    <root>
        <priority value="debug"/>
        <appender-ref ref="ASYNC"/>
        <appender-ref ref="ERROR-LOG"/>

    </root>
</log4j:configuration>
Is it helpful? Add Comment View Comments
Ques 3. What are the different logging levels?
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.
Is it helpful? Add Comment View Comments
Ques 4. What are different types of logs?
Ans. Usually in any application there two types of logs
1.Application server logs :- These are the logs configured at the application 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.
Is it helpful? Add Comment View Comments
Ques 5. What are different appenders that can configure in log4j?
Ans. There are different appenders that we can configure in log4j are: CONSOLE, FILES, DATABASE, JMS, EVENT LOGGING

Mainly used appenders:
CONSOLE in log4j:- If we use this as appenders in your application, log4j logs the information in the console or command prompt window that is started with startup 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 specify the file name.
Is it helpful? Add Comment View Comments

Most helpful rated by users:

©2017 WithoutBook