Log printout in eclipse environment

1. First configure the jdk

Choose Preferences----

Find the location of your own jdk

2. Configure Tomcat


Find your own tomcat location

3. Right click the project, build path -------- > configure build path


4. Import log4j-1.2.14.jar

Right click log4j-1.2.14.jar file build path ----- > add to build path

Create a log4j.log file in the root directory of the project, and import the log4j.properties file in the src directory

The code of log4j.properties file is as follows

#log4j.rootLogger = DEBUG, a1
log4j.rootLogger = INFO, A1
#log4j.rootLogger = ERROR, A1
#log4j.appender.A1 = org.apache.log4j.ConsoleAppender
 log4j.appender.A1 = org.apache.log4j.FileAppender
 log4j.appender.A1 = org.apache.log4j.RollingFileAppender
 log4j.appender.A1.File =log4j.log
 log4j.appender.A1.layout = org.apache.log4j.PatternLayout
 #log4j.appender.A1.layout.ConversionPattern = %-4r [%t] %-5p %c %x - %m%n
 log4j.appender.A1.layout.ConversionPattern = [%d] [%t] %m%n

Create a package org.jsoft.log

Create a TestLog class under the package

package org.jsoft.log;

import org.apache.log4j.*;
 * @author Administrator
 * @version 2018-1-9 9:14:11 am
public class TestLog {
    public static void main(String[] args) {
        //Acquisition recorder
        new TestLog().getLog();
    public void getLog(){
        Logger l = Logger.getLogger(TestLog.class);
        l.info("You moved my people");

Run. You can see that the log is printed out in log4j.log

WARN No appenders could be found for logger (org.jsoft.log.TestLog).

This error occurred because the log4j.properties file was not imported

Keywords: Java log4j Apache JDK Tomcat

Added by hadeosdin on Sat, 02 May 2020 12:22:02 +0300