Java Code Examples for ch.qos.logback.classic.Logger#getAppender()

The following examples show how to use ch.qos.logback.classic.Logger#getAppender() . 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: IrisAgentLogging.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
public static String getInMemoryLogs(boolean compress) {
   Logger logger = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
   IrisAgentAppender appender = (com.iris.agent.logging.IrisAgentAppender)logger.getAppender("MEMORY");
   if (appender == null) {
      return "";
   }

   String logs = appender.getLogs();
   if (!compress) {
      return logs;
   }

   byte[] data = logs.getBytes(StandardCharsets.UTF_8);
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   try (GZIPOutputStream os = new GZIPOutputStream(baos)) {
      os.write(data);
   } catch (Exception ex) {
   }

   byte[] compressed = baos.toByteArray();
   return Base64.encodeBase64String(compressed);
}
 
Example 2
Source File: LocalMainCommand.java    From terracotta-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
  Logger rootLogger = (Logger) LoggerFactory.getLogger(ROOT_LOGGER_NAME);

  if (verbose) {
    ConsoleAppender<ILoggingEvent> appender = (ConsoleAppender<ILoggingEvent>) rootLogger.getAppender("STDOUT");
    PatternLayoutEncoder ple = new PatternLayoutEncoder();
    ple.setPattern("%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p %c{1}:%L - %msg%n");
    ple.setContext(appender.getContext());
    ple.start();

    appender.setEncoder(ple);
    rootLogger.setLevel(Level.TRACE);
    rootLogger.getLoggerContext().getLoggerList().forEach(logger -> logger.setLevel(Level.TRACE));
  }
}
 
Example 3
Source File: LogUtils.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the file where the logs are.
 * @return the logs file.
 */
public static File getEndpointLogsFile() {
    Logger rootLogger = (Logger) LoggerFactory.getLogger(ROOT_LOGGER);
    FileAppender<ILoggingEvent> fileAppender = (FileAppender<ILoggingEvent>) rootLogger.getAppender("FILE");

    if(fileAppender != null) {
        return new File(fileAppender.getFile());
    } else {
        return null;
    }
}
 
Example 4
Source File: FlumeLoggerLoader.java    From chassis with Apache License 2.0 5 votes vote down vote up
public synchronized void installFlumeAppender() {
	LoggerContext logContext = (LoggerContext) LoggerFactory.getILoggerFactory();
	appender.setContext(logContext);
	appender.start();

	Logger logger = logContext.getLogger(Logger.ROOT_LOGGER_NAME);

	if (logger.getAppender(appender.getName()) == null) {
		logger.addAppender(appender);
	}
}
 
Example 5
Source File: FlumeLoggerLoader.java    From chassis with Apache License 2.0 5 votes vote down vote up
public synchronized void uninstallFlumeAppender() {
	LoggerContext logContext = (LoggerContext) LoggerFactory.getILoggerFactory();
	appender.setContext(logContext);
	appender.stop();
	
	Logger logger = logContext.getLogger(Logger.ROOT_LOGGER_NAME);
	
	if (logger.getAppender(appender.getName()) != null) {
		logger.detachAppender(appender);
	}
}
 
Example 6
Source File: LoggingConfiguratorTest.java    From logging-java with Apache License 2.0 5 votes vote down vote up
private void assertDefault(final String ident, final Level level) {
  final Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
  final ConsoleAppender<?> stderr = (ConsoleAppender<?>) rootLogger.getAppender("stderr");
  assertTrue(stderr.getEncoder() instanceof PatternLayoutEncoder);
  assertEquals(level, rootLogger.getLevel());
  final LoggerContext context = rootLogger.getLoggerContext();
  assertEquals(ident, context.getProperty("ident"));
}
 
Example 7
Source File: FlickrUploader.java    From flickr-uploader with GNU General Public License v2.0 5 votes vote down vote up
public static void flushLogs() {
    try {
        Logger logbackLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
        LoggerContext lc = logbackLogger.getLoggerContext();
        Logger rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
        Appender<ILoggingEvent> appender = rootLogger.getAppender("file");
        appender.stop();
        appender.start();
    } catch (Throwable e) {
        Log.e("Flickr Uploader", e.getMessage(), e);
    }
}
 
Example 8
Source File: LogbackCapturingAppender.java    From hivemq-community-edition with Apache License 2.0 4 votes vote down vote up
private void detachDefaultConsoleAppender() {
    final Logger rootLogger = getRootLogger();
    final Appender<ILoggingEvent> consoleAppender = rootLogger.getAppender("console");
    rootLogger.detachAppender(consoleAppender);
}
 
Example 9
Source File: IrisAgentLogging.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
public static IrisAgentAppender getInMemoryAppender() {
   Logger logger = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
   return (com.iris.agent.logging.IrisAgentAppender)logger.getAppender("MEMORY");
}
 
Example 10
Source File: VerboseHandler.java    From swagger-brake with Apache License 2.0 4 votes vote down vote up
private Appender<ILoggingEvent> getVerboseAppender() {
    Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    return rootLogger.getAppender("VERBOSE_STDOUT");
}
 
Example 11
Source File: LogbackCapturingAppender.java    From wisp with Apache License 2.0 4 votes vote down vote up
private void detachDefaultConsoleAppender() {
    Logger rootLogger = getRootLogger();
    Appender<ILoggingEvent> consoleAppender = rootLogger.getAppender("console");
    rootLogger.detachAppender(consoleAppender);
}
 
Example 12
Source File: GelfUdpAppenderTest.java    From logback-gelf with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void stopLogger(final Logger logger) {
    final GelfUdpAppender gelfAppender = (GelfUdpAppender) logger.getAppender("GELF");
    gelfAppender.stop();
}
 
Example 13
Source File: GelfTcpAppenderTest.java    From logback-gelf with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void stopLogger(final Logger logger) {
    final GelfTcpAppender gelfAppender = (GelfTcpAppender) logger.getAppender("GELF");
    gelfAppender.stop();
}
 
Example 14
Source File: GelfTcpTlsAppenderTest.java    From logback-gelf with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void stopLogger(final Logger logger) {
    final GelfTcpTlsAppender gelfAppender = (GelfTcpTlsAppender) logger.getAppender("GELF");
    gelfAppender.stop();
}
 
Example 15
Source File: LoggingConfiguratorTest.java    From logging-java with Apache License 2.0 4 votes vote down vote up
private void assertLogstashEncoder(final Level level) {
  final Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
  final ConsoleAppender<?> stdout = (ConsoleAppender<?>) rootLogger.getAppender("stdout");
  assertTrue(stdout.getEncoder() instanceof CustomLogstashEncoder);
  assertEquals(level, rootLogger.getLevel());
}