Log4j's specific use (continued 2)

xiaoxiao2021-03-05  23

Now there is a change in demand, there are several classes in the app to record their respective information, requiring records in different files, and the content is different, as mentioned above, add a few Logger

STEP1) Modify the configuration file

2) STEP2 Modify Logger Package

/ * * Created on 2005-4-23 * * Todo to change the template for this generated file go to * window - preferences - java - code style - code templates * / package gasturbine.model.util;

Import org.apache.log4j.logger; import org.apache.log4j.xml.domconfigurator;

/ ** * @Author pw * * * / public class syslog {static logger logger = logger.getrootlogger (); static {domconfigurator.configure ("classes / log4j.xml");}

Public Static Void Debug (Object O) {Logger.debug (O);

} Public static void debug (double d) {logger.debug (" d);

} Public static void info (Object O, String Name) {logger.getlogger (name) .info (o);} public static void info (double d, string name) {logger.getlogger (name) .info (" " d);

}

}

3) Call of STEP3 client

Code pieces

Syslog.info (sb.toString (), "humidier");

Syslog.info (sb.toString (), "Cooler1");

Syslog.info (sb.toString (), "Cooler2");

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

New Post(0)