public URL findURLOfDefaultConfigurationFile(boolean updateStatus) {
ClassLoader myClassLoader = Loader.getClassLoaderOfObject(this);
URL url = findConfigFileURLFromSystemProperties(myClassLoader, updateStatus);
if (url != null) {
return url;
}
url = getResource(TEST_AUTOCONFIG_FILE, myClassLoader, updateStatus);
if (url != null) {
return url;
}
url = getResource(GROOVY_AUTOCONFIG_FILE, myClassLoader, updateStatus);
if (url != null) {
return url;
}
return getResource(AUTOCONFIG_FILE, myClassLoader, updateStatus);
}
public class ContextInitializer {
final public static String GROOVY_AUTOCONFIG_FILE = "logback.groovy";
final public static String AUTOCONFIG_FILE = "logback.xml";
final public static String TEST_AUTOCONFIG_FILE = "logback-test.xml";
final public static String CONFIG_FILE_PROPERTY = "logback.configurationFile";
URL url = findConfigFileURLFromSystemProperties(myClassLoader, updateStatus);
if (url != null) {
return url;
}
点进去之后可以看到
private URL findConfigFileURLFromSystemProperties(ClassLoader classLoader, boolean updateStatus) {
String logbackConfigFile = OptionHelper.getSystemProperty(CONFIG_FILE_PROPERTY);
final public static String CONFIG_FILE_PROPERTY = "logback.configurationFile";</div>
<div>OptionHelper.getSystemProperty中的内容是</div>
public static String getSystemProperty(String key) {
try {
return System.getProperty(key);
} catch (SecurityException e) {
return null;
}
}
可以看出是从 System.getProperty()中获取的,而key是静态变量。
private static final Logger log;
static {
System.setProperty("logback.configurationFile","./logback.xml");
log = LoggerFactory.getLogger(MonitorApplication.class);
}
private static final Logger log = LoggerFactory.getLogger(MonitorApplication.class);;
static {
System.setProperty("logback.configurationFile","./logback.xml");
}
public static void main(String[] args) {}
public class MonitorApplication {
private static final Logger log = LoggerFactory.getLogger(MonitorApplication.class);