Skip to content

Instantly share code, notes, and snippets.

@framon
Created September 5, 2019 16:24
Show Gist options
  • Save framon/78a083d0d5c17a5f9f740d84696a3585 to your computer and use it in GitHub Desktop.
Save framon/78a083d0d5c17a5f9f740d84696a3585 to your computer and use it in GitHub Desktop.
ContextListener do Logback e acesso a propriedades
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.LoggerContextListener;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.spi.ContextAwareBase;
import ch.qos.logback.core.spi.LifeCycle;
public class CustomContextListener extends ContextAwareBase implements LoggerContextListener, LifeCycle {
private static final String PROPERTY = "property.name";
private boolean started = false;
@Override
public void start() {
if (started) {
return;
}
Context context = getContext();
String property = context.getProperty(PROPERTY);
addInfo("Property value=" + property);
started = true;
}
@Override
public void stop() {
}
@Override
public boolean isStarted() {
return started;
}
@Override
public boolean isResetResistant() {
return false;
}
@Override
public void onStart(LoggerContext context) {
}
@Override
public void onReset(LoggerContext context) {
}
@Override
public void onStop(LoggerContext context) {
}
@Override
public void onLevelChange(Logger logger, Level level) {
}
}
<property resource="app.properties"/>
<property scope="context" name="property.name" value="${app.property.name}"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment