Log4j specific application (continued)

xiaoxiao2021-03-05  25

Now there is a change, requiring the status information in the next class, making a report, that is, there are two log files Gasturbine.log1 and gasturbine.log2, the former is used to display Debug information, the latter is used to specifically display status information, if It is difficult to get only used by a Logger because a logger can correspond to multiple profiles and different formats, but the contents of each file are the same, and now the content is not the same, so consider using two Logger

Step1) Modify the previous profile

< Appender-ref = "appender1" />

Step2) Modify the Logger package class

/ * * 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 Logger infologger = Logger.getLogger ( "component"); 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) {infoLogger.info (o);

} Public static void info (double d) {infoLogger.info (" d);

}

}

STEP3) calls syslog .info

Code segment:

Private void titlelog () {

SB.Append (Simlog.Format)); sb.append (Simlog.Format)); sb.append (Simlog.Format); sb.append (Simlog.Format) "u0")))

Syslog.info (sb.tostring ()); sb.delete (0, sb.Length ());

Attach the result

Part of Gasturbine.log1.txt

2005-04-23 19: 09: 19,921 [main] debug - ======== 0th cycle start ====================19-04-23 19: 09: 19,921 [main] debug - === Step 1 Remove the required variable from the environment === 2005-04-23 19: 09: 19,953 [main] Debug - Entrance Wet air flow: 58.14 kg / s 2005-04-23 19:09: 19,953 [main] debug - Export Wet Air Flow: 70.0 Kg / S 2005-04-23 19: 09: 19,953 [Main] Debug - Entrance Wet Air Temperature: 293.0 K 2005-04-23 19: 09: 19,953 [Main] Debug - Export Wet Air Temperature: 300.0 K 2005-04-23 19: 09: 19,953 [Main] Debug - Inlet Wet Air Pressure: 1913300.0 Pa 2005-04-23 19: 09: 19,953 [Main] Debug - Export Wet Air Pressure : 1713300.0 Pa 2005-04-23 19: 09: 19,953 [main] debug - Wet air moisture content: 0.2 g / kg 2005-04-23 19: 09: 19,953 [main] debug - wet air moisture : 0.6 g / kg .....................................................................

DENA0 DENV0 T0 22.63618773930130297283 0.0045281429536983321.5371879393739398573 0.00435757597157780 .................................

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

New Post(0)