Created
September 5, 2019 16:24
-
-
Save framon/78a083d0d5c17a5f9f740d84696a3585 to your computer and use it in GitHub Desktop.
ContextListener do Logback e acesso a propriedades
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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