Skip to content

Commit

Permalink
Fix auto reconfig for <configuration scan="true">
Browse files Browse the repository at this point in the history
The main config URL was not set when auto-config used assets/logback.xml,
so <configuration scan="true"> had no effect. This patch ensures the URL
is set by passing the URL to assets/logback.xml (instead of a stream
to it).

Fixes #182
  • Loading branch information
tony19 committed Sep 5, 2018
1 parent d1927a7 commit 6a809b0
Showing 1 changed file with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package ch.qos.logback.classic.util;

import java.io.File;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

Expand Down Expand Up @@ -87,26 +86,26 @@ private URL findConfigFileFromSystemProperties(boolean updateStatus) {

/**
* Finds a configuration file in the application's assets directory
* @return the file; or {@code null} if not found
* @return the URL of the file; or {@code null} if not found
*/
private InputStream findConfigFileURLFromAssets(boolean updateStatus) {
private URL findConfigFileURLFromAssets(boolean updateStatus) {
return getResource(AUTOCONFIG_FILE, this.classLoader, updateStatus);
}

/**
* Uses the given classloader to search for a resource
* @return the input stream to the resource; or {@code null} if not found
* @return the URL to the resource; or {@code null} if not found
*/
private InputStream getResource(String filename, ClassLoader myClassLoader, boolean updateStatus) {
InputStream stream = myClassLoader.getResourceAsStream(filename);
private URL getResource(String filename, ClassLoader myClassLoader, boolean updateStatus) {
URL url = myClassLoader.getResource(filename);
if (updateStatus) {
String resourcePath = null;
if (stream != null) {
if (url != null) {
resourcePath = filename;
}
statusOnResourceSearch(filename, myClassLoader, resourcePath);
}
return stream;
return url;
}

/**
Expand Down Expand Up @@ -140,9 +139,9 @@ public void autoConfig() throws JoranException {

// search assets
if (!configured) {
InputStream assetsConfigXml = findConfigFileURLFromAssets(verbose);
if (assetsConfigXml != null) {
configurator.doConfigure(assetsConfigXml);
URL assetsConfigUrl = findConfigFileURLFromAssets(verbose);
if (assetsConfigUrl != null) {
configurator.doConfigure(assetsConfigUrl);
configured = true;
}
}
Expand Down

0 comments on commit 6a809b0

Please sign in to comment.