Log4j. properties configuration file
Content of the code
log4j.rootLogger=info, ServerDailyRollingFile, stdout log4j.appender.ServerDailyRollingFile=org.apache.log4j.DailyRollingFileAppender log4j.appender.ServerDailyRollingFile.DatePattern='.'yyyy-MM-dd log4j.appender.ServerDailyRollingFile.File=logs/notify-subscription.log log4j.appender.ServerDailyRollingFile.layout=org.apache.log4j.PatternLayout log4j.appender.ServerDailyRollingFile.layout.ConversionPattern=%d - %m%n log4j.appender.ServerDailyRollingFile.Append=true log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss} %p [%c] %m%nCopy the code
Pay attention to
As you can see, the log4j.properties is automatically read because there is a static block in logManager.java for org.apache.log4j where
-
Gets system properties to see if the user has override set. This is not set by default.
-
If not, try to find if log4j.xml is available and load if it is.
-
If not, try to find log4j.properites and load them if they do.
Among them, the “try to find” mentioned in 2 and 3 May be in which directory to find? Translation, the effect is not good, or the original text is clear: > Search for resource using the thread context class loader under Java2. If that fails, Search for resource using the class loader that loaded this class (loader). Under JDK 1.1, only the the class loader that loaded this class (Loader) is used.Try one last time with ClassLoader.getSystemResource(resource), That is using the system class loader in JDK 1.2 and virtual machine’s built-in class loader in JDK 1.1.
So, if you put log4j. XML or log4j.properties in these directories, log4j will "automatically load" into them instead of manually writing the loading code in the program.Copy the code