Log4J recorder logs in Eclipse

xiaoxiao2021-03-06  112

1. Download Eclipse and Log4J Related Software 2. Create a Java project in Eclipse, such as HelloEClipse, add external Jar log4j.jar file 3 in this process. Introduce the log4j.properties file with Eclipse's import function, and modify it, log4j is as follows in Example / LF / LF5 in the log4j package you downloaded:

# For the general syntax of property based configuration files See the # Document ORG.APache.log4j.propertyConfigurator.

# The root category uses the appender called A1. Since no priority is # specified, the root category assumes the default priority for root # which is DEBUG in log4j. The root category is the only category that # has a default priority. All other categories NEED NOT BE ASSIGNED A # priority in which case the # hierarchy. # If it is a pop-up log4j log recorder # log4j.rootcategory =, A1 # Display log record directly in the Eclipse console log4j.rootcategory =, b1

# A1 is set to be a lf5appender which outputs to a swing # logging console. # Log4j.Appender.a1 = org.apache.log4j.lf5.lf5appender # log4j.Appender.A1.MAXNUMBEROFRECORDS = 1000

Log4j.Appender.b1 = org.apache.log4j.consolerappenderlog4j.Appender.b1.Layout = Org.apache.log4j.patternlayoutLog4j.Appender.b1.Layout.conversionPattern =% - 4R% -5p [% t]% 37C% 3X -% m% nlog4j.Appender.b1.Layout.conversionPattern =% 5P [% T] (% f:% L) -% M% N

4. Write the HelloEClipse code as follows:

import org.apache.log4j *;. class HelloEclipse {static Logger logger = Logger.getLogger (HelloEclipse.class.getName ()); public static void main (String args []) {PropertyConfigurator.configure ( "Log4j.properties") HelloEclipse.logger.info ("Record Test"); int valueoflover = 1; HelloEclipse.logger.info ("ValueOflover" valueoflover);}}

You can see the following log information.

转载请注明原文地址:https://www.9cbs.com/read-103128.html

New Post(0)