In log4j, the configuration files that are usually displayed in the console and write log4j.properties are as follows: Public final static int;
# Record the level of the log, only when you want to write> = gived level (Info, Debug, Warn, Error, Fatal) # Console Console Output Name # file file name log4j.rootlogger = error, Console, File
# 控制 输 输出 l = org.apache.console = org.apache.log4j.consolerappenderlog4j.Appender.Console.Layout = Org.Apache.log4j.simpleLayout
############ file operation format # log4j backup file name log4j.Appender.file.file = log / synclog.txt ## Specify how you can flexible control output, output colony log4j.Appender.File . retog4j.patternLayOoutlog4j.Appender.File.Layout.conversionPattern =% T% p% m% N
# After reaching a certain amount. Automatic backup log4j.Appender.file = org.apache.log4j.rollingfileAppenderlog4j.Appender.File.MaxFileSize = 5000000Log4j.Appender.File.MaxBackupIndex = 100
#, 每 每...................................
## Designation Continue Write File # log4j.Appender.file = org.apache.log4j.writerappender # log4j.appender.file.os = org.apache.log4j.writerappender
Log.java configuration files are as follows: package com.hode.log4j; import org.apache.log4j. *; Import java.util.calendar;
Public factory log {public final static int debu = 2; public final static int warn = 3; public final static int rt error = 4; public final static int fitual = 5 Download Adobe Reader Download Adobe Reader Download Adobe Reader Download Adobe Reader Download Adobe Readers PUBLIC FINAL =
// Create a log case, the record variable is the logger static logger logger = logger.getlogger ("Logger");
// Create a log case, the recording variable is the logger1 static logger logger1 = logger.getlogger ("logger1");
public static void writeLog (String str, int Type) {PropertyConfigurator.configure ( "config / log4j.properties"); Calendar dtm = Calendar.getInstance (); str = dtm.getTime () "" str; logger1.setLevel ((Level) Level.info; Switch (Type) {CASE INFO: Logger.info (STR); Logger1.info (STR); Break; Case Debug: Logger.debug (STR); Logger1.debug (STR); Break; Case Warn: Logger.warn (Str); Logger1.warn (STR); Break; Case Error: Logger.Error (STR); Logger1.Error (STR); Break; Case Fatal: Logger.FATAL (STR); Logger1.fatal (str); Break;}} public static void main (string [] args) {log.writelog ("##### 1111", log.warn);}} If 2 created cases are Like, then the file written is 2 Static Logger logg ER = logger.getlogger ("logger"); static logger logger1 = logger.getlogger ("logger"); then logger1, Logger executes if 2 created cases are different, then the written file is 1 Static Logger Logger = Logger.getlogger ("Logger"); static logger logger1 = logger.getlogger ("logger1");
So logger1 is executed, logger is not executed