Java Code Examples for ch.qos.logback.core.ConsoleAppender#setName()
The following examples show how to use
ch.qos.logback.core.ConsoleAppender#setName() .
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: KonkerLoggerBasicConfigurator.java From konker-platform with Apache License 2.0 | 6 votes |
public static void configure(KonkerLoggerContext lc) { StatusManager sm = lc.getStatusManager(); if(sm != null) { sm.add(new InfoStatus("Setting up default configuration.", lc)); } ConsoleAppender ca = new ConsoleAppender(); ca.setContext(lc); ca.setName("console"); PatternLayoutEncoder pl = new PatternLayoutEncoder(); pl.setContext(lc); pl.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"); pl.start(); ca.setEncoder(pl); ca.start(); KonkerLogger rootLogger = lc.getLogger("ROOT"); rootLogger.addAppender(ca); }
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: 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 4
Source File: LoggingConfigurator.java From logging-java with Apache License 2.0 | 6 votes |
/** * Create a stderr appender. * * @param context The logger context to use. * @return An appender writing to stderr. */ private static Appender<ILoggingEvent> getStdErrAppender(final LoggerContext context, final ReplaceNewLines replaceNewLines) { // Setup format final PatternLayoutEncoder encoder = new PatternLayoutEncoder(); encoder.setContext(context); encoder.setPattern( "%date{HH:mm:ss.SSS} %property{ident}[%property{pid}]: %-5level [%thread] %logger{0}: " + ReplaceNewLines.getMsgPattern(replaceNewLines) + "%n"); encoder.setCharset(Charsets.UTF_8); encoder.start(); // Setup stderr appender final ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>(); appender.setTarget("System.err"); appender.setName("stderr"); appender.setEncoder(encoder); appender.setContext(context); appender.start(); return appender; }
Example 5
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 6
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 7
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 8
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 9
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 10
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 11
Source File: LoggingUtils.java From jhipster with Apache License 2.0 | 5 votes |
/** * <p>addJsonConsoleAppender.</p> * * @param context a {@link ch.qos.logback.classic.LoggerContext} object. * @param customFields a {@link java.lang.String} object. */ public static void addJsonConsoleAppender(LoggerContext context, String customFields) { log.info("Initializing Console loggingProperties"); // More documentation is available at: https://github.com/logstash/logstash-logback-encoder ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>(); consoleAppender.setContext(context); consoleAppender.setEncoder(compositeJsonEncoder(context, customFields)); 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 12
Source File: LoggerUtil.java From bgpcep with Eclipse Public License 1.0 | 5 votes |
private static ConsoleAppender<ILoggingEvent> createConsoleAppender(final LoggerContext loggerContext) { final PatternLayoutEncoder ple = new PatternLayoutEncoder(); ple.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{10} - %msg%n"); ple.setContext(loggerContext); ple.start(); final ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>(); consoleAppender.setContext(loggerContext); consoleAppender.setEncoder(ple); consoleAppender.setName("STDOUT"); consoleAppender.start(); return consoleAppender; }
Example 13
Source File: LogUtils.java From konduit-serving with Apache License 2.0 | 4 votes |
/** * Sets the file appender with the name of "FILE" if needed. If it's already been setup, * it would be ignored. */ public static void setAppendersForRunCommand(String serverId) { String logFilePath = new File(DirectoryFetcher.getCommandLogsDir(), serverId + ".log").getAbsolutePath(); SysOutOverSLF4J.sendSystemOutAndErrToSLF4J(); Logger rootLogger = (Logger) LoggerFactory.getLogger(ROOT_LOGGER); rootLogger.detachAndStopAllAppenders(); ((Logger) LoggerFactory.getLogger("uk.org.lidalia")).setLevel(Level.INFO); ((Logger) LoggerFactory.getLogger("org.nd4j")).setLevel(Level.INFO); ((Logger) LoggerFactory.getLogger("org")).setLevel(Level.INFO); ((Logger) LoggerFactory.getLogger("io")).setLevel(Level.INFO); LoggerContext context = (LoggerContext) org.slf4j.LoggerFactory.getILoggerFactory(); FileAppender<ILoggingEvent> fileAppender = new FileAppender<>(); fileAppender.setName("FILE"); fileAppender.setFile(logFilePath); fileAppender.setAppend(false); fileAppender.setContext(context); PatternLayoutEncoder patternLayoutEncoder = new PatternLayoutEncoder(); patternLayoutEncoder.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"); patternLayoutEncoder.setContext(context); patternLayoutEncoder.start(); fileAppender.setEncoder(patternLayoutEncoder); fileAppender.start(); ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>(); consoleAppender.setName("CONSOLE"); consoleAppender.setContext(context); consoleAppender.setEncoder(patternLayoutEncoder); consoleAppender.start(); rootLogger.addAppender(fileAppender); rootLogger.addAppender(consoleAppender); log.info("Logging file at: {}", logFilePath); }
Example 14
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 15
Source File: LogbackUtils.java From termsuite-core with Apache License 2.0 | 4 votes |
public static OutputStreamAppender<ILoggingEvent> createConsoleAppender() { ConsoleAppender<ILoggingEvent> fa = new ConsoleAppender<ILoggingEvent>(); fa.setName("ConsoleLogger"); return fa; }