本文整理匯總了Java中ch.qos.logback.core.Appender.start方法的典型用法代碼示例。如果您正苦於以下問題:Java Appender.start方法的具體用法?Java Appender.start怎麽用?Java Appender.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ch.qos.logback.core.Appender
的用法示例。
在下文中一共展示了Appender.start方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setMetricsMarkerLogbackFilter
import ch.qos.logback.core.Appender; //導入方法依賴的package包/類
private void setMetricsMarkerLogbackFilter(LoggerContext context) {
log.info("Filtering metrics logs from all appenders except the {} appender", LOGSTASH_APPENDER_NAME);
OnMarkerEvaluator onMarkerMetricsEvaluator = new OnMarkerEvaluator();
onMarkerMetricsEvaluator.setContext(context);
onMarkerMetricsEvaluator.addMarker("metrics");
onMarkerMetricsEvaluator.start();
EvaluatorFilter<ILoggingEvent> metricsFilter = new EvaluatorFilter<>();
metricsFilter.setContext(context);
metricsFilter.setEvaluator(onMarkerMetricsEvaluator);
metricsFilter.setOnMatch(FilterReply.DENY);
metricsFilter.start();
for (ch.qos.logback.classic.Logger logger : context.getLoggerList()) {
for (Iterator<Appender<ILoggingEvent>> it = logger.iteratorForAppenders(); it.hasNext();) {
Appender<ILoggingEvent> appender = it.next();
if (!appender.getName().equals(ASYNC_LOGSTASH_APPENDER_NAME)) {
log.debug("Filter metrics logs from the {} appender", appender.getName());
appender.setContext(context);
appender.addFilter(metricsFilter);
appender.start();
}
}
}
}
示例2: logToConsole
import ch.qos.logback.core.Appender; //導入方法依賴的package包/類
/**
* Starts or stops logging to the console.
*
* @param start starts or stops logging to the console.
*/
@SuppressWarnings("rawtypes")
public static void logToConsole(boolean start) {
Logger rootLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
if (rootLogger != null && rootLogger instanceof ch.qos.logback.classic.Logger) {
Appender appender = ((ch.qos.logback.classic.Logger) rootLogger).getAppender(CONSOLE_APPENDER_NAME);
if (appender != null) {
if (start) {
appender.start();
} else {
appender.stop();
}
return;
}
}
logger.warn("Unable to reconfigure Logback console logger (appender name '" + CONSOLE_APPENDER_NAME + "').");
}
示例3: setMetricsMarkerLogbackFilter
import ch.qos.logback.core.Appender; //導入方法依賴的package包/類
private void setMetricsMarkerLogbackFilter(LoggerContext context) {
log.info("Filtering metrics logs from all appenders except the {} appender", LOGSTASH_APPENDER_NAME);
OnMarkerEvaluator onMarkerMetricsEvaluator = new OnMarkerEvaluator();
onMarkerMetricsEvaluator.setContext(context);
onMarkerMetricsEvaluator.addMarker("metrics");
onMarkerMetricsEvaluator.start();
EvaluatorFilter<ILoggingEvent> metricsFilter = new EvaluatorFilter<>();
metricsFilter.setContext(context);
metricsFilter.setEvaluator(onMarkerMetricsEvaluator);
metricsFilter.setOnMatch(FilterReply.DENY);
metricsFilter.start();
for (ch.qos.logback.classic.Logger logger : context.getLoggerList()) {
for (Iterator<Appender<ILoggingEvent>> it = logger.iteratorForAppenders(); it.hasNext(); ) {
Appender<ILoggingEvent> appender = it.next();
if (!appender.getName().equals(ASYNC_LOGSTASH_APPENDER_NAME)) {
log.debug("Filter metrics logs from the {} appender", appender.getName());
appender.setContext(context);
appender.addFilter(metricsFilter);
appender.start();
}
}
}
}
示例4: build
import ch.qos.logback.core.Appender; //導入方法依賴的package包/類
@Override
public Appender<E> build(final LoggerContext context,
final String applicationName,
final LayoutFactory<E> layoutFactory,
final LevelFilterFactory<E> levelFilterFactory,
final AsyncAppenderFactory<E> asyncAppenderFactory) {
final Appender<E> appender = new FifoLogbackAppender<>();
appender.setContext(context);
appender.addFilter(levelFilterFactory.build(threshold));
getFilterFactories().forEach(f -> appender.addFilter(f.build()));
appender.start();
appender.setName(APPENDER_NAME);
return appender;
}
示例5: configure
import ch.qos.logback.core.Appender; //導入方法依賴的package包/類
/**
* Initializes the logger and the requested log level.
*
* @param level Logging level threshold
*/
@SuppressWarnings("unchecked")
public static void configure(final Level level) {
final Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root.setLevel(level);
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(root.getLoggerContext());
encoder.setPattern("%msg%n");
encoder.start();
Iterator<Appender<ILoggingEvent>> iterator = root.iteratorForAppenders();
while (iterator.hasNext()) {
Appender<ILoggingEvent> appender = iterator.next();
if (appender instanceof OutputStreamAppender) {
((OutputStreamAppender) appender).setEncoder(encoder);
}
appender.stop();
appender.start();
}
}
示例6: configureAppender
import ch.qos.logback.core.Appender; //導入方法依賴的package包/類
private Appender<ILoggingEvent> configureAppender(LoggerContext loggerContext, String name, Config config)
throws ReflectiveOperationException {
List<Object> children = new ArrayList<>();
@SuppressWarnings("unchecked")
Class<Appender<ILoggingEvent>> clazz = (Class<Appender<ILoggingEvent>>) Class
.forName(config.getString("class"));
Appender<ILoggingEvent> appender = this.configureObject(loggerContext, clazz, config, children);
appender.setName(name);
for (Object child : children) {
if (child instanceof RollingPolicy) {
((RollingPolicy) child).setParent((FileAppender<?>) appender);
}
if (child instanceof LifeCycle) {
((LifeCycle) child).start();
}
}
appender.start();
return appender;
}
示例7: setVerboseMode
import ch.qos.logback.core.Appender; //導入方法依賴的package包/類
@Override
public void setVerboseMode(boolean on) {
PatternLayoutEncoder patternLayoutEncoder = new PatternLayoutEncoder();
patternLayoutEncoder.setPattern("[%d{HH:mm:ss.SSS}] [%highlight(%level)] %msg%n");
patternLayoutEncoder.setContext(loggerContext);
patternLayoutEncoder.start();
Appender<ILoggingEvent> consoleAppender = new ConsoleAppender();
((OutputStreamAppender) consoleAppender).setEncoder(patternLayoutEncoder);
consoleAppender.setContext(loggerContext);
consoleAppender.start();
loggerContext.getLogger("com.paypal.butterfly.cli").detachAppender("CONSOLE");
loggerContext.getLogger("ROOT").addAppender(consoleAppender);
}
示例8: build
import ch.qos.logback.core.Appender; //導入方法依賴的package包/類
@Override
public Appender<E> build(final LoggerContext context,
final String applicationName,
final LayoutFactory<E> layoutFactory,
final LevelFilterFactory<E> levelFilterFactory,
final AsyncAppenderFactory<E> asyncAppenderFactory) {
final Properties producerConfigProperties = producerConfig.stream()
.map(s -> s.split("="))
.filter(values -> values.length == 2)
.reduce(new Properties(), (props, values) -> {
props.setProperty(values[0], values[1]);
return props;
}, (p1, p2) -> {
Properties merged = new Properties();
merged.putAll(p1);
merged.putAll(p2);
return merged;
});
final Appender<E> appender = new KafkaLogbackAppender<>(producerConfigProperties, topic);
appender.setContext(context);
appender.addFilter(levelFilterFactory.build(threshold));
getFilterFactories().forEach(f -> appender.addFilter(f.build()));
appender.start();
appender.setName(APPENDER_NAME);
return appender;
//return wrapAsync(appender, asyncAppenderFactory);
}
示例9: addGuiAppender
import ch.qos.logback.core.Appender; //導入方法依賴的package包/類
/**
* Add a specific appender meant for GUI log pane.
* To be called only when running with a GUI.
*/
public static void addGuiAppender ()
{
// GUI (filtered in LogGuiAppender)
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(
Logger.ROOT_LOGGER_NAME);
Appender guiAppender = new LogGuiAppender();
guiAppender.setName("GUI");
guiAppender.setContext(loggerContext);
guiAppender.start();
root.addAppender(guiAppender);
}
示例10: testConfiguredAppender
import ch.qos.logback.core.Appender; //導入方法依賴的package包/類
@Test
public void testConfiguredAppender() {
Appender<E> appender = getConfiguredAppender();
appender.start();
assertTrue(appender.isStarted());
appender.stop();
assertFalse(appender.isStarted());
}
示例11: configure
import ch.qos.logback.core.Appender; //導入方法依賴的package包/類
/**
* Configure logging based on a list of builders provided to it. Injects the
* configured logging to replace the default UIMA loggers, and also sets up
* metrics on the logging.
*
* @param builders
* The builders to use to configure the logging
*/
public void configure(List<BaleenLoggerBuilder> builders) {
// Install JUL to SLF4J handling (JUL is default for UIMA)
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
// Configure Logback
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
Logger rootLogger = context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
// Install the level change propagator to reduce the impact of JUL logging
context.addListener(new LevelChangePropagator());
// Remove all the existing appenders
rootLogger.detachAndStopAllAppenders();
for (BaleenLoggerBuilder builder : builders) {
PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setCharset(StandardCharsets.UTF_8);
ple.setContext(context);
ple.setPattern(builder.getPattern());
ple.start();
Appender<ILoggingEvent> appender = builder.build(context, ple);
if (!appender.isStarted()) {
appender.start();
}
rootLogger.addAppender(appender);
}
LOGGER.debug("Adding instrumented metrics for logging");
// Add an instrumented appender so we get the information about logging
// through metrics
InstrumentedAppender instrumentedAppender = new InstrumentedAppender(MetricsFactory.getInstance().getRegistry());
instrumentedAppender.setContext(context);
instrumentedAppender.start();
rootLogger.addAppender(instrumentedAppender);
}
示例12: LogConfigurator
import ch.qos.logback.core.Appender; //導入方法依賴的package包/類
public LogConfigurator(File f) {
Appender appender = null;
if (f != null) {
try {
String line = Files.readFirstLine(f, Charset.defaultCharset()).trim();
switch (line) {
case "rolling":
String logFile = workingDirectory();
message = ("rolling to file://{}" + logFile);
RollingFileAppender r = new RollingFileAppender();
r.setFile(logFile);
r.setAppend(true);
SizeBasedTriggeringPolicy triggeringPolicy = new ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy();
triggeringPolicy.setMaxFileSize(FileSize.valueOf("5MB"));
triggeringPolicy.start();
FixedWindowRollingPolicy policy = new FixedWindowRollingPolicy();
policy.setFileNamePattern("log.%i.gz");
policy.setParent(r);
policy.setContext(LOG.getLoggerContext());
policy.start();
r.setEncoder(logEncoder());
r.setRollingPolicy(policy);
r.setTriggeringPolicy(triggeringPolicy);
appender = r;
break;
//TODO TCP/UDP etc
}
} catch (IOException e) {
logger.error("{}", e);
appender = null;
}
}
if (appender == null) {
//default
ConsoleAppender a = new ConsoleAppender();
a.setEncoder(logEncoder());
appender = a;
message = "ConsoleAppender";
}
LOG.detachAndStopAllAppenders();
appender.setContext(LOG.getLoggerContext());
appender.start();
LOG.addAppender(appender);
this.appender = appender;
}