Nous avons résolu ce problème en redirigeant System.err avant de charger la configuration et vérifier si des erreurs ont été enregistrées dans le flux:
class ConfigurationLoader {
class Log4jConfigStderrStream extends ByteArrayOutputStream {
private int lineCount;
private StringBuilder output;
private PrintStream underlying;
public Log4jConfigStderrStream(PrintStream underlying) {
this.lineCount = 0;
this.output = new StringBuilder("");
this.underlying = underlying;
}
@Override
public void flush() throws IOException {
String[] buffer;
synchronized (this) {
buffer = this.toString().split("\n");
super.flush();
super.reset();
for (int i = 0; i < buffer.length; i++) {
String line = buffer[i].replace("\n", "").replace("\r",
"");
if (line.length() > 0) {
this.lineCount++;
this.output.append(line);
this.output.append("\n");
}
}
}
}
public String getOutput() {
return this.output.toString();
}
public PrintStream getUnderlying() {
return this.underlying;
}
public boolean hasErrors() {
return this.lineCount == 0 ? false : true;
}
}
private String output;
public void flushOutput() {
if (!"".equals(this.output))
System.err.print(this.output);
}
public boolean loadConfiguration(String filename) {
Log4jConfigStderrStream confErr;
confErr = new Log4jConfigStderrStream(System.err);
System.setErr(new PrintStream(confErr, true));
LogManager.resetConfiguration();
DOMConfigurator.configure(filename);
System.setErr(confErr.getUnderlying());
this.output = confErr.getOutput();
return !confErr.hasErrors();
}
}
Oui, cela est emmerdant, Je suis d'accord. Je ne pense pas que tu puisses faire ça, cependant. – skaffman
J'ai fait un peu de googling et rien ne s'est passé. J'espérais que le débordement de pile pourrait me donner une réponse mais je devrais juste compter sur la bonne entrée d'utilisateur si elles décident de changer le dossier. Merci pour votre réponse! :) – user459811