Skip to content

Commit 6d8e969

Browse files
Fix loading of environment-dependent Logback config file on classpath.
1 parent 0685cac commit 6d8e969

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

jooby/src/main/java/org/jooby/Jooby.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
import java.io.File;
5959
import java.lang.reflect.Type;
60+
import java.net.URL;
6061
import java.nio.charset.Charset;
6162
import java.nio.file.Path;
6263
import java.nio.file.Paths;
@@ -3196,11 +3197,17 @@ static String logback(final Config conf) {
31963197
if (conf.hasPath("logback.configurationFile")) {
31973198
logback = conf.getString("logback.configurationFile");
31983199
} else {
3200+
String env = conf.hasPath("application.env") ? conf.getString("application.env") : null;
3201+
if (env != null) {
3202+
URL classpathLogback = Thread.currentThread().getContextClassLoader().getResource("logback." + env + ".xml");
3203+
if (classpathLogback != null) {
3204+
return classpathLogback.toString();
3205+
}
3206+
}
31993207
ImmutableList.Builder<File> files = ImmutableList.builder();
32003208
File userdir = new File(System.getProperty("user.dir"));
32013209
File confdir = new File(userdir, "conf");
3202-
if (conf.hasPath("application.env")) {
3203-
String env = conf.getString("application.env");
3210+
if (env != null) {
32043211
files.add(new File(userdir, "logback." + env + ".xml"));
32053212
files.add(new File(confdir, "logback." + env + ".xml"));
32063213
}

0 commit comments

Comments
 (0)