Skip to content

Commit 66ae678

Browse files
authored
Merge pull request #615 from optimaster/fix-logback-on-classpath
Fix loading of environment-dependent Logback config file on classpath.
2 parents 4de62e7 + e31303c commit 66ae678

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 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,12 @@ 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+
URL cpconf = Jooby.class.getResource("/logback." + env + ".xml");
31993202
ImmutableList.Builder<File> files = ImmutableList.builder();
32003203
File userdir = new File(System.getProperty("user.dir"));
32013204
File confdir = new File(userdir, "conf");
3202-
if (conf.hasPath("application.env")) {
3203-
String env = conf.getString("application.env");
3205+
if (env != null) {
32043206
files.add(new File(userdir, "logback." + env + ".xml"));
32053207
files.add(new File(confdir, "logback." + env + ".xml"));
32063208
}
@@ -3211,7 +3213,7 @@ static String logback(final Config conf) {
32113213
.filter(f -> f.exists())
32123214
.map(f -> f.getAbsolutePath())
32133215
.findFirst()
3214-
.orElse("logback.xml");
3216+
.orElse((cpconf != null) ? cpconf.toString() : "logback.xml");
32153217
}
32163218
return logback;
32173219
}

0 commit comments

Comments
 (0)