Java Code Examples for ch.qos.logback.core.ConsoleAppender#start()
The following examples show how to use
ch.qos.logback.core.ConsoleAppender#start() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogbackFactory.java From bither-desktop-java with Apache License 2.0 | 6 votes |
public static ConsoleAppender<ILoggingEvent> buildConsoleAppender(LoggingConfiguration.ConsoleConfiguration console, LoggerContext context, String logFormat) { final LogFormatter formatter = new LogFormatter(context, console.getTimeZone()); if (logFormat != null) { formatter.setPattern(logFormat); } formatter.start(); final ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>(); appender.setContext(context); appender.setLayout(formatter); addThresholdFilter(appender, console.getThreshold()); appender.start(); return appender; }
Example 2
Source File: StructuredLogging.java From flo with Apache License 2.0 | 6 votes |
public static void configureStructuredLogging(Level level) { final Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); final LoggerContext context = rootLogger.getLoggerContext(); context.reset(); final StructuredLoggingEncoder encoder = new StructuredLoggingEncoder(); encoder.start(); final ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>(); appender.setTarget("System.err"); appender.setName("stderr"); appender.setEncoder(encoder); appender.setContext(context); appender.start(); rootLogger.addAppender(appender); rootLogger.setLevel(fromLocationAwareLoggerInteger(level.toInt())); SLF4JBridgeHandler.install(); }
Example 3
Source File: LogAppender.java From nuls-v2 with MIT License | 6 votes |
@SuppressWarnings("unchecked") public static Appender<ILoggingEvent> createConsoleAppender(Level level){ ConsoleAppender appender = new ConsoleAppender(); LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); appender.setContext(context); //这里设置级别过滤器 LogFilter levelController = new LogFilter(); ThresholdFilter levelFilter = levelController.getThresholdFilter(level); levelFilter.start(); appender.addFilter(levelFilter); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); //设置上下文,每个logger都关联到logger上下文,默认上下文名称为default。 //但可以使用<contextName>设置成其他名字,用于区分不同应用程序的记录。一旦设置,不能修改。 encoder.setContext(context); //设置格式 encoder.setPattern("%d %p [%t] - %msg%n"); encoder.start(); //加入下面两个节点 appender.setEncoder(encoder); appender.start(); return appender; }
Example 4
Source File: LogbackLoggingConfigurer.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
private void doFailSafeConfiguration() { // Not really fail-safe, just less likely to fail final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); context.reset(); Logger rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME); rootLogger.setLevel(Level.INFO); ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>(); rootLogger.addAppender(appender); appender.setContext(context); appender.setTarget("System.err"); PatternLayout layout = new PatternLayout(); appender.setLayout(layout); layout.setPattern("%msg%n%ex"); layout.setContext(context); layout.start(); appender.start(); }
Example 5
Source File: LogbackLoggingConfigurer.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
private void doFailSafeConfiguration() { // Not really fail-safe, just less likely to fail final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); context.reset(); Logger rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME); rootLogger.setLevel(Level.INFO); ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>(); rootLogger.addAppender(appender); appender.setContext(context); appender.setTarget("System.err"); PatternLayout layout = new PatternLayout(); appender.setLayout(layout); layout.setPattern("%msg%n%ex"); layout.setContext(context); layout.start(); appender.start(); }
Example 6
Source File: LoggingConfigurator.java From logging-java with Apache License 2.0 | 6 votes |
/** * Configure logging with the LogstashEncoder library. * (https://github.com/logstash/logstash-logback-encoder) * * An appender is configured to send the log messages to stdout. It is expected something like * a Docker container will capture these logs for further processing. * */ public static void configureLogstashEncoderDefaults(final Level level) { final Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); final LoggerContext context = rootLogger.getLoggerContext(); context.reset(); final CustomLogstashEncoder encoder = new CustomLogstashEncoder().setupStackdriver(); encoder.setContext(context); encoder.start(); final ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>(); appender.setTarget("System.out"); appender.setName("stdout"); appender.setEncoder(encoder); appender.setContext(context); appender.start(); rootLogger.addAppender(appender); rootLogger.setLevel(level.logbackLevel); UncaughtExceptionLogger.setDefaultUncaughtExceptionHandler(); }
Example 7
Source File: LogbackConfiguration.java From milkman with MIT License | 5 votes |
private void setupConsoleAppender(LoggerContext loggerContext) { ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<ILoggingEvent>(); ca.setContext(loggerContext); ca.setName("STDOUT"); var filter = new ThresholdFilter(); filter.setLevel("INFO"); filter.start(); ca.addFilter(filter); LayoutWrappingEncoder<ILoggingEvent> encoder = new LayoutWrappingEncoder<ILoggingEvent>(); encoder.setContext(loggerContext); // same as // PatternLayout layout = new PatternLayout(); // layout.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"); TTLLLayout layout = new TTLLLayout(); layout.setContext(loggerContext); layout.start(); encoder.setLayout(layout); ca.setEncoder(encoder); ca.start(); Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME); rootLogger.addAppender(ca); }
Example 8
Source File: LoggingConfig.java From mirror with Apache License 2.0 | 5 votes |
public synchronized static void init() { if (started) { return; } started = true; // setup java.util.logging (which grpc-java uses) to go to slf4j SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); LevelChangePropagator p = new LevelChangePropagator(); p.setContext(context); p.start(); context.addListener(p); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); encoder.setContext(context); encoder.setPattern(pattern); encoder.start(); ConsoleAppender<ILoggingEvent> console = new ConsoleAppender<>(); console.setContext(context); console.setEncoder(encoder); console.start(); Logger root = getLogger(Logger.ROOT_LOGGER_NAME); root.detachAndStopAllAppenders(); root.addAppender(console); root.setLevel(Level.INFO); getLogger("io.grpc").setLevel(Level.INFO); // silence a noisy DNS warning when we cannot resolve the other host getLogger("io.grpc.internal.ManagedChannelImpl").setLevel(Level.ERROR); // silence "ConnectivityStateManager is already disabled" warning getLogger("io.grpc.internal.ChannelExecutor").setLevel(Level.ERROR); getLogger("mirror").setLevel(Level.INFO); }
Example 9
Source File: AgentOutputAppender.java From gocd with Apache License 2.0 | 5 votes |
void writeTo(Outstream target) { ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>(); appender.setTarget(target.target.getName()); appender.setEncoder(LogHelper.encoder("%date{ISO8601} [" + target.marker + "] - %msg%n")); appender.start(); appenders.add(appender); }
Example 10
Source File: DefaultPluginLoggingService.java From gocd with Apache License 2.0 | 5 votes |
private void initializeLoggerForPluginId(String pluginId) { if (alreadyInitialized(pluginId)) { return; } synchronized (pluginId.intern()) { if (alreadyInitialized(pluginId)) { return; } synchronized (appenderCreationLock) { FileAppender<ILoggingEvent> pluginAppender = getAppender(pluginId); ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(PLUGIN_LOGGER_PREFIX + "." + pluginId); logger.setAdditive(false); logger.setLevel(systemEnvironment.pluginLoggingLevel(pluginId)); logger.addAppender(pluginAppender); if (systemEnvironment.consoleOutToStdout()) { ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>(); consoleAppender.setEncoder(LogHelper.encoder("%d{ISO8601} %5p [%t] %c{1}:%L [plugin-" + pluginId + "] - %m%n")); logger.setAdditive(false); logger.setLevel(systemEnvironment.pluginLoggingLevel(pluginId)); consoleAppender.start(); logger.addAppender(consoleAppender); } loggingServiceLogger.debug("Plugin with ID: " + pluginId + " will log to: " + pluginAppender.rawFileProperty()); } } }
Example 11
Source File: EnvCommand.java From emissary with Apache License 2.0 | 5 votes |
@Override public void run(JCommander jc) { String endpoint = getScheme() + "://" + getHost() + ":" + getPort() + "/api/env"; if (getBashable()) { ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) org.slf4j.LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME); root.detachAndStopAllAppenders(); setup(); LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); PatternLayoutEncoder ple = new PatternLayoutEncoder(); ple.setPattern("%msg%n"); ple.setContext(lc); ple.start(); ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>(); consoleAppender.setEncoder(ple); consoleAppender.setContext(lc); consoleAppender.start(); root.addAppender(consoleAppender); root.setLevel(Level.INFO); root.setAdditive(false); // still gotta hide org.eclipse.jetty.util.log INFO ch.qos.logback.classic.Logger jettyUtilLogger = lc.getLogger("org.eclipse.jetty.util.log"); jettyUtilLogger.setLevel(Level.WARN); // also add .sh to the endpoint endpoint = endpoint + ".sh"; LOG.info("# generated from env command at {}", endpoint); } else { setup(); // go ahead an log it } EmissaryClient client = new EmissaryClient(); LOG.info(client.send(new HttpGet(endpoint)).getContentString()); }
Example 12
Source File: DefaultLogbackReInitializer.java From sofa-common-tools with Apache License 2.0 | 5 votes |
private ConsoleAppender consoleAppender(LoggerContext loggerContext, Properties properties) { SystemPropertiesGetter propertiesGetter = new SystemPropertiesGetter(properties); ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>(); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); String logPattern = propertiesGetter.getProperty( SOFA_MIDDLEWARE_LOG_CONSOLE_LOGBACK_PATTERN, SOFA_MIDDLEWARE_LOG_CONSOLE_LOGBACK_PATTERN_DEFAULT); encoder.setPattern(OptionHelper.substVars(logPattern, loggerContext)); encoder.setContext(loggerContext); encoder.start(); appender.setEncoder(encoder); appender.setName("CONSOLE"); appender.start(); return appender; }
Example 13
Source File: CombinatorialMaterializerTest.java From tasmo with Apache License 2.0 | 5 votes |
@BeforeClass public void logger() { Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); LoggerContext loggerContext = rootLogger.getLoggerContext(); loggerContext.reset(); if (verbose) { PatternLayoutEncoder encoder = new PatternLayoutEncoder(); encoder.setContext(loggerContext); encoder.setPattern("[%thread]: %message%n"); encoder.start(); ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>(); appender.setContext(loggerContext); appender.setEncoder(encoder); appender.start(); rootLogger.addAppender(appender); ((Logger) LoggerFactory.getLogger("com.jivesoftware.os.tasmo")).setLevel(Level.TRACE); ((Logger) LoggerFactory.getLogger("com.jivesoftware.os.tasmo.lib.concur.ConcurrencyAndExistanceCommitChange")).setLevel(Level.TRACE); ((Logger) LoggerFactory.getLogger("com.jivesoftware.os.tasmo.reference.lib.ReferenceStore")).setLevel(Level.TRACE); ((Logger) LoggerFactory.getLogger("com.jivesoftware.os.tasmo.view.reader.service.writer.WriteToViewValueStore")).setLevel(Level.TRACE); } else { rootLogger.setLevel(Level.OFF); } }
Example 14
Source File: LogUtils.java From konduit-serving with Apache License 2.0 | 5 votes |
/** * Sets the appenders for command line. */ public static void setAppendersForCommandLine() { Logger rootLogger = (Logger) LoggerFactory.getLogger(ROOT_LOGGER); LoggerContext context = (LoggerContext) org.slf4j.LoggerFactory.getILoggerFactory(); rootLogger.detachAndStopAllAppenders(); ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>(); PatternLayoutEncoder consolePatternLayoutEncoder = new PatternLayoutEncoder(); consolePatternLayoutEncoder.setPattern("%msg%n"); consolePatternLayoutEncoder.setContext(context); consolePatternLayoutEncoder.start(); consoleAppender.setEncoder(consolePatternLayoutEncoder); consoleAppender.start(); rootLogger.addAppender(consoleAppender); ((Logger) LoggerFactory.getLogger("uk.org.lidalia")).setLevel(Level.ERROR); ((Logger) LoggerFactory.getLogger("org.nd4j")).setLevel(Level.ERROR); ((Logger) LoggerFactory.getLogger("org")).setLevel(Level.ERROR); ((Logger) LoggerFactory.getLogger("io")).setLevel(Level.ERROR); ((Logger) LoggerFactory.getLogger("ai")).setLevel(Level.INFO); }
Example 15
Source File: LoggingConfiguration.java From java-microservices-examples with Apache License 2.0 | 5 votes |
private void addJsonConsoleAppender(LoggerContext context) { log.info("Initializing Console logging"); // More documentation is available at: https://github.com/logstash/logstash-logback-encoder ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>(); consoleAppender.setContext(context); consoleAppender.setEncoder(compositeJsonEncoder(context)); consoleAppender.setName(CONSOLE_APPENDER_NAME); consoleAppender.start(); context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME).detachAppender(CONSOLE_APPENDER_NAME); context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME).addAppender(consoleAppender); }
Example 16
Source File: LoggingConfiguration.java From java-microservices-examples with Apache License 2.0 | 5 votes |
private void addJsonConsoleAppender(LoggerContext context) { log.info("Initializing Console logging"); // More documentation is available at: https://github.com/logstash/logstash-logback-encoder ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>(); consoleAppender.setContext(context); consoleAppender.setEncoder(compositeJsonEncoder(context)); consoleAppender.setName(CONSOLE_APPENDER_NAME); consoleAppender.start(); context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME).detachAppender(CONSOLE_APPENDER_NAME); context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME).addAppender(consoleAppender); }
Example 17
Source File: LoggingConfiguration.java From java-microservices-examples with Apache License 2.0 | 5 votes |
private void addJsonConsoleAppender(LoggerContext context) { log.info("Initializing Console logging"); // More documentation is available at: https://github.com/logstash/logstash-logback-encoder ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>(); consoleAppender.setContext(context); consoleAppender.setEncoder(compositeJsonEncoder(context)); consoleAppender.setName(CONSOLE_APPENDER_NAME); consoleAppender.start(); context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME).detachAppender(CONSOLE_APPENDER_NAME); context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME).addAppender(consoleAppender); }
Example 18
Source File: LoggingConfiguration.java From alchemy with Apache License 2.0 | 5 votes |
private void addJsonConsoleAppender(LoggerContext context) { log.info("Initializing Console logging"); // More documentation is available at: https://github.com/logstash/logstash-logback-encoder ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>(); consoleAppender.setContext(context); consoleAppender.setEncoder(compositeJsonEncoder(context)); consoleAppender.setName(CONSOLE_APPENDER_NAME); consoleAppender.start(); context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME).detachAppender(CONSOLE_APPENDER_NAME); context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME).addAppender(consoleAppender); }
Example 19
Source File: AionLoggerFactory.java From aion with MIT License | 4 votes |
private static List<Appender<ILoggingEvent>> constructAppenders( boolean shouldLogToFile, String _logDirectory) { List<Appender<ILoggingEvent>> appenders = new ArrayList<>(); String logDirectory = DEFAULT_LOG_DIR; if (_logDirectory != null && !_logDirectory.trim().isEmpty()) logDirectory = _logDirectory; PatternLayoutEncoder encoder = new PatternLayoutEncoder(); encoder.setContext(context); encoder.setPattern(DEFAULT_LOG_PATTERN); encoder.start(); ConsoleAppender<ILoggingEvent> consoleSync = new ConsoleAppender<>(); consoleSync.setContext(context); consoleSync.setName("consoleSyncAppender"); // for logger debugging consoleSync.setEncoder(encoder); consoleSync.start(); AsyncAppender consoleAsync = new AsyncAppender(); consoleAsync.setContext(context); consoleAsync.setName("consoleAsyncAppender"); // for logger debugging consoleAsync.addAppender(consoleSync); consoleAsync.setIncludeCallerData(ASYNC_LOGGER_INCLUDE_CALLER_DATA); consoleAsync.setNeverBlock(ASYNC_LOGGER_NEVER_BLOCK); consoleAsync.setMaxFlushTime(ASYNC_LOGGER_MAX_FLUSH_TIME_MS); consoleAsync.setDiscardingThreshold(ASYNC_LOGGER_DISCARDING_THRESHOLD); consoleAsync.setQueueSize(ASYNC_LOGGER_QUEUE_SIZE); consoleAsync.start(); appenders.add(consoleAsync); if (!shouldLogToFile) return appenders; RollingFileAppender<ILoggingEvent> fileSync = new RollingFileAppender<>(); SizeBasedTriggeringPolicy<ILoggingEvent> tp = new SizeBasedTriggeringPolicy<>(); tp.setContext(context); tp.start(); SizeAndTimeBasedRollingPolicy rp = new SizeAndTimeBasedRollingPolicy(); rp.setContext(context); // roll-over each day // notice that we don't use the OS-agnostic File.separator here since logback is converts // the FileNamePattern // to a unix-style path using ch.qos.logback.core.rolling.helper.FileFilterUtil.slashify FileNamePattern fnp = new FileNamePattern( logDirectory + "/%d{yyyy/MM, aux}/aion.%d{yyyy-MM-dd}.%i.log", context); rp.setFileNamePattern(fnp.getPattern()); // max rollover file size = 100MB rp.setMaxFileSize(FileSize.valueOf("100mb")); rp.setParent(fileSync); rp.start(); fileSync.setName("fileSyncAppender"); // for logger debugging fileSync.setContext(context); fileSync.setTriggeringPolicy(tp); fileSync.setRollingPolicy(rp); fileSync.setFile(logDirectory + File.separator + DEFAULT_LOG_FILE_CURRENT); fileSync.setEncoder(encoder); fileSync.setAppend(true); fileSync.start(); AsyncAppender fileAsync = new AsyncAppender(); fileAsync.setContext(context); fileAsync.setName("fileAsyncAppender"); // for logger debugging fileAsync.addAppender(fileSync); fileAsync.setIncludeCallerData(ASYNC_LOGGER_INCLUDE_CALLER_DATA); fileAsync.setNeverBlock(ASYNC_LOGGER_NEVER_BLOCK); fileAsync.setMaxFlushTime(ASYNC_LOGGER_MAX_FLUSH_TIME_MS); fileAsync.setDiscardingThreshold(ASYNC_LOGGER_DISCARDING_THRESHOLD); fileAsync.setQueueSize(ASYNC_LOGGER_QUEUE_SIZE); fileAsync.start(); appenders.add(fileAsync); return appenders; }
Example 20
Source File: Logger.java From metrics_publish_java with MIT License | 4 votes |
/** * Initialize Logback */ private static void initLogback() { // reset logger context LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); context.reset(); // shared console appender ConsoleAppender.setContext(context); ConsoleAppender.setTarget("System.out"); PatternLayoutEncoder consoleEncoder = new PatternLayoutEncoder(); consoleEncoder.setContext(context); consoleEncoder.setPattern(LogPattern); consoleEncoder.start(); ConsoleAppender.setEncoder(consoleEncoder); ConsoleAppender.start(); // rolling file String logFile = getFilePath() + File.separatorChar + getFileName(); FileAppender.setContext(context); FileAppender.setFile(logFile); // log pattern PatternLayoutEncoder fileEncoder = new PatternLayoutEncoder(); fileEncoder.setContext(context); fileEncoder.setPattern(LogPattern); fileEncoder.start(); FileAppender.setEncoder(fileEncoder); // rolling policy FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy(); rollingPolicy.setContext(context); rollingPolicy.setParent(FileAppender); rollingPolicy.setFileNamePattern(logFile + "%i.zip"); rollingPolicy.setMinIndex(1); rollingPolicy.setMaxIndex(1); rollingPolicy.start(); // file max size - if fileLimit is 0, set max file size to maximum allowed long fileLimit = getFileLimitInKBytes() != 0 ? getFileLimitInKBytes() * 1024 : Long.MAX_VALUE; SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>(String.valueOf(fileLimit)); triggeringPolicy.start(); FileAppender.setRollingPolicy(rollingPolicy); FileAppender.setTriggeringPolicy(triggeringPolicy); FileAppender.start(); }