Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Practice InterviewNew Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

Log4j Interview Questions and Answers

Ques. 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? Yes No

Most helpful rated by users:

©2019 WithoutBook