Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure logger4j.properties and log4j.xml

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to configure logger4j.properties and log4j.xml". In daily operation, I believe many people have doubts about how to configure logger4j.properties and log4j.xml. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to configure logger4j.properties and log4j.xml". Next, please follow the editor to study!

Log4j.xml 's

Configuration of log4j.xml in web.xml

Log4jConfigLocation classpath:log4j-server.xml log4jRefreshInterval 3000 org.springframework.web.util.Log4jConfigListener

Log4j.properties configuration

# configuration files that output logs by packet classification # # # log4j.rootLogger = debug for all log packages AppendConsole# the following two configurations specify the special handling of the package For the two specified log levels, if not specified, the parent logger (rootLogger) is specified to overwrite the parent logger # set dao package log configuration log4j.logger.com.xun.log4j.dao = debug, appendDao# set service package log configuration log4j.logger.com.xun.log4j.service = info, appendService# console configuration log4j.appender.appendConsole = org.apache.log4j.ConsoleAppender#Threshold: set the log level of this appender This overrides the log level defined globally (in rootLogger) log4j.appender.appendConsole.Threshold = error# sets the log output encoding to UTF-8, if not specified Log4j.appender.appendConsole.encoding = UTF-8log4j.appender.appendConsole.layout = org.apache.log4j.SimpleLayout#appendDao configuration log4j.appender.appendDao = org.apache.log4j.FileAppenderlog4j.appender.appendDao.layout = org.apache.log4j.PatternLayoutlog4j.appender.appendDao.layout.ConversionPattern = [% d {yyyy-MM-dd HH:mm:ss}]-- [% t] [% p] -% l -% m%n%nlog4j will be recorded in the code of the current operating system. .appendDao.append = falselog4j.appender.appendDao.File = e:/test/log4j/dao.txt#appendServicelog4j.appender.appendService = org.apache.log4j.FileAppenderlog4j.appender.appendService.layout = org.apache.log4j.PatternLayoutlog4j.appender.appendService.layout.ConversionPattern = [% d {yyyy-MM-dd HH:mm:ss}]-- [% t] [% p] -% l -% m%n%nlog4j.appender.appendService.Append = falselog4j.appender.appendService.File = e:/test/ Log4j/service.txt// method 1: automatically and quickly use the Log4J default environment / / BasicConfigurator.configure () / / method 2: read the properties file (custom location), but note the loading path of the file here / / PropertyConfigurator.configure ("E:/workspace-idea/study-demo/log4j-test/src/main/resources/log4j/log4j.properties"); / / PropertyConfigurator.configure (HowUseLog4JDemo.class.getClassLoader () .getResource ("log4j/log4j.properties") .getFile ()) / / method 3: read the XML file / / DOMConfigurator.configure ("xxx"); at this point, the study on "how to configure logger4j.properties and log4j.xml" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report