16 Kasım 2023 Perşembe

Log4j2 Ayar Dosyası

Giriş
Log4J2 için kullanılan ayar dosyası belirli bir önceliğe göre aranıyor. Öncelik sıralaması burada tanımlı. Açıklaması şöyle
1. Log4j will inspect the "log4j2.configurationFile" system property and, if set, will attempt to load the configuration using the ConfigurationFactory that matches the file extension. Note that this is not restricted to a location on the local file system and may contain a URL.
2. If no system property is set the properties ConfigurationFactory will look for log4j2-test.properties in the classpath.
3. If no such file is found the YAML ConfigurationFactory will look for log4j2-test.yaml or log4j2-test.yml in the classpath.
4. If no such file is found the JSON ConfigurationFactory will look for log4j2-test.json or log4j2-test.jsn in the classpath.
5. If no such file is found the XML ConfigurationFactory will look for log4j2-test.xml in the classpath.
6. If a test file cannot be located the properties ConfigurationFactory will look for log4j2.properties on the classpath.
7. If a properties file cannot be located the YAML ConfigurationFactory will look for log4j2.yaml or log4j2.yml on the classpath.
8 . If a YAML file cannot be located the JSON ConfigurationFactory will look for log4j2.json or log4j2.jsn on the classpath.
9. If a JSON file cannot be located the XML ConfigurationFactory will try to locate log4j2.xml on the classpath.
10. If no configuration file could be located the DefaultConfiguration will be used. This will cause logging output to go to the console.
1. DefaultConfiguration
Açıklaması şöyle
Log4j 2 provides a default configuration that will be used if no custom configuration file is provided. This default configuration is designed to work in most situations, but it may not meet all of your specific logging needs.
2. XML veya YAML Dosyası
Açıklaması şöyle
If you choose to configure Log4j 2 using a log4j2.xml or log4j2.yml file, you can place the file in your application's classpath (in our case main/java/resources), in the root of your application's jar file, or in a directory specified by the log4j.configurationFile system property.

3. Kendi Dosyam
log4j2.configurationFile ile belirtilir.

Örnek - properties dosyası
Şöyle yaparız
java ... -Dlog4j2.configurationFile=mylog.properties
Kodla şöyle yaparız
public static void main(String[] args) {
  System.setProperty("log4j2.configurationFile", "file:///.../mylog.properties");
  
}

Hiç yorum yok:

Yorum Gönder