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);
}
}
}
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)));
}
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);
}
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);
}
}
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);
}
Aggregations