Search in sources :

Example 41 with Appender

use of org.apache.log4j.Appender in project gocd by gocd.

the class LoggingHelper method addConsoleNDCLogRemoverFilter.

private static void addConsoleNDCLogRemoverFilter() {
    Enumeration allAppenders = Logger.getRootLogger().getAllAppenders();
    while (allAppenders.hasMoreElements()) {
        Appender appender = (Appender) allAppenders.nextElement();
        if (isConsoleNdcAppender(appender)) {
            continue;
        }
        Filter filter = getConsoleNDCFilter(appender);
        if (filter != CONSOLE_NDC_REJECT_FILTER) {
            appender.addFilter(CONSOLE_NDC_REJECT_FILTER);
        }
    }
}
Also used : Appender(org.apache.log4j.Appender) RollingFileAppender(org.apache.log4j.RollingFileAppender) Enumeration(java.util.Enumeration) Filter(org.apache.log4j.spi.Filter)

Example 42 with Appender

use of org.apache.log4j.Appender in project gocd by gocd.

the class DefaultPluginLoggingServiceTest method assertPluginLogFile.

private void assertPluginLogFile(String pluginId, String expectedPluginLogFileName) {
    SystemEnvironment systemEnvironment = mock(SystemEnvironment.class);
    DefaultPluginLoggingService loggingService = new DefaultPluginLoggingService(systemEnvironment);
    loggingService.debug(pluginId, "some-logger-name", "message");
    List<Appender> appenders = Collections.list(Logger.getLogger("plugin." + pluginId).getAllAppenders());
    String loggingDirectory = loggingService.getCurrentLogDirectory();
    assertThat(appenders.size(), is(1));
    assertThat(new File(((FileAppender) appenders.get(0)).getFile()), is(new File(loggingDirectory, expectedPluginLogFileName)));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender) FileAppender(org.apache.log4j.FileAppender) File(java.io.File)

Example 43 with Appender

use of org.apache.log4j.Appender in project jmxtrans by jmxtrans.

the class KeyOutWriter method initLogger.

/**
	 * Initializes the logger. This is called when we need to create a new
	 * logger for the given file name.
	 *
	 * @param fileStr
	 * @return a new Logger instance for the given fileStr
	 * @throws IOException
	 */
protected Logger initLogger(String fileStr) throws IOException {
    Appender appender = buildLog4jAppender(fileStr, getMaxLogFileSize(), getMaxLogBackupFiles());
    LoggerFactory loggerFactory = buildLog4jLoggerFactory(appender);
    String loggerKey = buildLoggerName();
    // Create the logger and add to the map of loggers using our factory
    LogManager.getLogger(loggerKey, loggerFactory);
    return log4jLoggerFactory.getLogger(loggerKey);
}
Also used : Appender(org.apache.log4j.Appender) RollingFileAppender(org.apache.log4j.RollingFileAppender) LoggerFactory(org.apache.log4j.spi.LoggerFactory) Log4jLoggerFactory(org.slf4j.impl.Log4jLoggerFactory)

Example 44 with Appender

use of org.apache.log4j.Appender in project jop by jop-devel.

the class LogConfig method stopLogger.

public static void stopLogger() {
    String[] names = { "ACONSOLE", "AERROR", "AINFO" };
    for (String appender : names) {
        Appender app = Logger.getRootLogger().getAppender(appender);
        if (app == null) {
            continue;
        }
        app.close();
        Logger.getRootLogger().removeAppender(app);
    }
}
Also used : Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender)

Example 45 with Appender

use of org.apache.log4j.Appender in project hadoop by apache.

the class TaskLog method syncLogs.

@SuppressWarnings("unchecked")
public static synchronized void syncLogs(String logLocation, TaskAttemptID taskid, boolean isCleanup) throws IOException {
    System.out.flush();
    System.err.flush();
    Enumeration<Logger> allLoggers = LogManager.getCurrentLoggers();
    while (allLoggers.hasMoreElements()) {
        Logger l = allLoggers.nextElement();
        Enumeration<Appender> allAppenders = l.getAllAppenders();
        while (allAppenders.hasMoreElements()) {
            Appender a = allAppenders.nextElement();
            if (a instanceof TaskLogAppender) {
                ((TaskLogAppender) a).flush();
            }
        }
    }
    if (currentTaskid != taskid) {
        currentTaskid = taskid;
        resetPrevLengths(logLocation);
    }
    writeToIndexFile(logLocation, isCleanup);
}
Also used : Appender(org.apache.log4j.Appender) Logger(org.apache.log4j.Logger)

Aggregations

Appender (org.apache.log4j.Appender)54 FileAppender (org.apache.log4j.FileAppender)17 Logger (org.apache.log4j.Logger)15 File (java.io.File)13 ConsoleAppender (org.apache.log4j.ConsoleAppender)11 RollingFileAppender (org.apache.log4j.RollingFileAppender)11 Log4JLogger (org.apache.commons.logging.impl.Log4JLogger)8 Enumeration (java.util.Enumeration)7 AsyncAppender (org.apache.log4j.AsyncAppender)6 PatternLayout (org.apache.log4j.PatternLayout)6 IOException (java.io.IOException)5 ActiveDbAppender (com.axway.ats.log.appenders.ActiveDbAppender)4 PassiveDbAppender (com.axway.ats.log.appenders.PassiveDbAppender)4 MalformedURLException (java.net.MalformedURLException)4 Map (java.util.Map)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 Category (org.apache.log4j.Category)4 DailyRollingFileAppender (org.apache.log4j.DailyRollingFileAppender)4 Layout (org.apache.log4j.Layout)4