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

The following examples show how to use ch.qos.logback.classic.Logger#detachAppender() . 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: VerboseHandler.java    From swagger-brake with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(String optionValue, Options options) {
    if (optionValue == null) {
        return;
    }

    if (optionValue.isEmpty()) {
        org.slf4j.Logger slf4jLogger = LoggerFactory.getLogger("io.redskap.swagger.brake");
        if (slf4jLogger instanceof Logger) {
            Logger logger = (Logger) slf4jLogger;
            logger.setLevel(Level.DEBUG);
            Appender<ILoggingEvent> verboseAppender = getVerboseAppender();
            if (verboseAppender != null) {
                logger.detachAppender("INFO_STDOUT");
                logger.addAppender(verboseAppender);
            }
        }
    }
}
 
Example 2
Source File: IrisAgentLogging.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public static void setupInitialLogging() {
   Logger rootLog = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);

   String rootType = System.getenv("IRIS_AGENT_LOGTYPE");
   if ("dev".equalsIgnoreCase(rootType)) {
      rootLog.detachAppender("STDOUT");
   } else {
      rootLog.detachAppender("DEV");
   }

   resetLogLevels();
}
 
Example 3
Source File: LogUtils.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the file appender with the name of "FILE" if needed. If it's already been setup,
 * it would be ignored.
 */
public static void setFileAppenderIfNeeded() {
    SysOutOverSLF4J.sendSystemOutAndErrToSLF4J();

    File previousLogsFile = getEndpointLogsFile();

    File newLogsFile = new File(DirectoryFetcher.getEndpointLogsDir(), Constants.MAIN_ENDPOINT_LOGS_FILE);

    if(!newLogsFile.equals(previousLogsFile)) {
        Logger rootLogger = (Logger) LoggerFactory.getLogger(ROOT_LOGGER);

        LoggerContext context = (LoggerContext) org.slf4j.LoggerFactory.getILoggerFactory();

        if(previousLogsFile != null) {
            rootLogger.detachAppender("FILE");
        }

        FileAppender<ILoggingEvent> fileAppender = new FileAppender<>();
        fileAppender.setName("FILE");
        fileAppender.setFile(newLogsFile.getAbsolutePath());
        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();

        rootLogger.addAppender(fileAppender);
    }
}
 
Example 4
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 5
Source File: LogUtil.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Terminate the specific file logging.
 *
 * @param name appender name (typically the book radix)
 */
public static void removeAppender (String name)
{
    Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(
            Logger.ROOT_LOGGER_NAME);
    root.detachAppender(name);
}
 
Example 6
Source File: LogbackListAppender.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 将此appender从root logger中移除.
 */
public void removeFromRootLogger() {
	Logger logger = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
	logger.detachAppender(this);
}
 
Example 7
Source File: AnimalActivityUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@After
public void teardown() {
    final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    logger.detachAppender(mockAppender);
}
 
Example 8
Source File: AnimalUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@After
public void teardown() {
    final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    logger.detachAppender(mockAppender);
}
 
Example 9
Source File: GlobalExceptionHandlerUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@After
public void teardown() {
    final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    logger.detachAppender(mockAppender);
}
 
Example 10
Source File: WildcardMapTest.java    From pom-manipulation-ext with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown()
{
    Logger root = (Logger) LoggerFactory.getLogger(WildcardMap.class);
    root.detachAppender(m_listAppender);
}
 
Example 11
Source File: OrientMetadataRebuilderTest.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@After
public void teardown() {
  Logger logger = (Logger)LoggerFactory.getLogger(ROOT_LOGGER_NAME);
  logger.detachAppender(mockAppender);
}
 
Example 12
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 13
Source File: LogbackListAppender.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 将此appender从logger中移除.
 */
public void removeFromLogger(Class<?> loggerClass) {
	Logger logger = (Logger) LoggerFactory.getLogger(loggerClass);
	logger.detachAppender(this);
}
 
Example 14
Source File: LogbackListAppender.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 将此appender从logger中移除.
 */
public void removeFromLogger(String loggerName) {
	Logger logger = (Logger) LoggerFactory.getLogger(loggerName);
	logger.detachAppender(this);
}
 
Example 15
Source File: LogbackListAppender.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 将此appender从root logger中移除.
 */
public void removeFromRootLogger() {
	Logger logger = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
	logger.detachAppender(this);
}
 
Example 16
Source File: LogbackListAppender.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 将此appender从logger中移除.
 */
public void removeFromLogger(Class<?> loggerClass) {
	Logger logger = (Logger) LoggerFactory.getLogger(loggerClass);
	logger.detachAppender(this);
}
 
Example 17
Source File: LogbackListAppender.java    From vjtools with Apache License 2.0 4 votes vote down vote up
/**
 * 将此appender从logger中移除.
 */
public void removeFromLogger(String loggerName) {
	Logger logger = (Logger) LoggerFactory.getLogger(loggerName);
	logger.detachAppender(this);
}
 
Example 18
Source File: DogUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@After
public void teardown() {
    final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    logger.detachAppender(mockAppender);
}
 
Example 19
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 20
Source File: ConfigurationFileProviderTest.java    From hivemq-community-edition with Apache License 2.0 3 votes vote down vote up
@After
public void tearDown() throws Exception {

    final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);

    logger.detachAppender(mockAppender);
}