Log4j 면접 질문과 답변
Question: How do you define logging for your application?Answer: 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. lets say you have web-application need to be added log4j. In this case, log4j jars are copied to WEB-INF/lib folder of your web application. 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> |
복습용 저장
이 항목을 북마크하거나, 어렵게 표시하거나, 복습 세트에 넣을 수 있습니다.
도움이 되었나요? 예 아니요
Most helpful rated by users:
- What is Log4j?
- What are the different logging levels?
- Describe about logger levels in log4j.
- What are the three main components in log4j?
- What is the importance of logging applications?