Search in sources :

Example 16 with Appender

use of org.apache.log4j.Appender in project symmetric-ds by JumpMind.

the class SnapshotUtil method findSymmetricLogFile.

@SuppressWarnings("unchecked")
public static Map<File, Layout> findSymmetricLogFile() {
    Enumeration<Appender> appenders = org.apache.log4j.Logger.getRootLogger().getAllAppenders();
    while (appenders.hasMoreElements()) {
        Appender appender = appenders.nextElement();
        if (appender instanceof FileAppender) {
            FileAppender fileAppender = (FileAppender) appender;
            if (fileAppender != null) {
                File file = new File(fileAppender.getFile());
                if (file != null && file.exists()) {
                    Map<File, Layout> matches = new HashMap<File, Layout>();
                    matches.put(file, fileAppender.getLayout());
                    return matches;
                }
            }
        }
    }
    return null;
}
Also used : Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender) FileAppender(org.apache.log4j.FileAppender) HashMap(java.util.HashMap) Layout(org.apache.log4j.Layout) File(java.io.File)

Example 17 with Appender

use of org.apache.log4j.Appender in project voltdb by VoltDB.

the class RealVoltDB method scheduleDailyLoggingWorkInNextCheckTime.

/**
     * Get the next check time for a private member in log4j library, which is not a reliable idea.
     * It adds 30 seconds for the initial delay and uses a periodical thread to schedule the daily logging work
     * with this delay.
     * @return
     */
void scheduleDailyLoggingWorkInNextCheckTime() {
    DailyRollingFileAppender dailyAppender = null;
    Enumeration<?> appenders = Logger.getRootLogger().getAllAppenders();
    while (appenders.hasMoreElements()) {
        Appender appender = (Appender) appenders.nextElement();
        if (appender instanceof DailyRollingFileAppender) {
            dailyAppender = (DailyRollingFileAppender) appender;
        }
    }
    final DailyRollingFileAppender dailyRollingFileAppender = dailyAppender;
    Field field = null;
    if (dailyRollingFileAppender != null) {
        try {
            field = dailyRollingFileAppender.getClass().getDeclaredField("nextCheck");
            field.setAccessible(true);
        } catch (NoSuchFieldException e) {
            hostLog.error("Failed to set daily system info logging: " + e.getMessage());
        }
    }
    final Field nextCheckField = field;
    long nextCheck = System.currentTimeMillis();
    // the next part may throw exception, current time is the default value
    if (dailyRollingFileAppender != null && nextCheckField != null) {
        try {
            nextCheck = nextCheckField.getLong(dailyRollingFileAppender);
            scheduleWork(new DailyLogTask(), nextCheck - System.currentTimeMillis() + 30 * 1000, 0, TimeUnit.MILLISECONDS);
        } catch (Exception e) {
            hostLog.error("Failed to set daily system info logging: " + e.getMessage());
        }
    }
}
Also used : DailyRollingFileAppender(org.apache.log4j.DailyRollingFileAppender) Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender) Field(java.lang.reflect.Field) DailyRollingFileAppender(org.apache.log4j.DailyRollingFileAppender) SocketException(java.net.SocketException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JSONException(org.json_voltpatches.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) SettingsException(org.voltdb.settings.SettingsException)

Example 18 with Appender

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

the class MDCLoggingTest method setCustomLogger.

private void setCustomLogger() {
    String PATTERN = "Modified Log *** ProcessDefinitionId=%X{mdcProcessDefinitionID} executionId=%X{mdcExecutionId} mdcProcessInstanceID=%X{mdcProcessInstanceID} mdcBusinessKey=%X{mdcBusinessKey} mdcTaskId=%X{mdcTaskId}  %m%n";
    console.setLayout(new PatternLayout(PATTERN));
    console.setThreshold(Level.DEBUG);
    console.activateOptions();
    console.setName("MemoryAppender");
    appenders = new ArrayList<Appender>();
    Enumeration<?> appendersEnum = Logger.getRootLogger().getAllAppenders();
    while (appendersEnum.hasMoreElements()) {
        Appender object = (Appender) appendersEnum.nextElement();
        appenders.add(object);
    }
    removeAppenders();
    Logger.getRootLogger().addAppender(console);
}
Also used : Appender(org.apache.log4j.Appender) PatternLayout(org.apache.log4j.PatternLayout)

Example 19 with Appender

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

the class MDCLoggingTest method removeAppenders.

private void removeAppenders() {
    Enumeration<?> appendersEnum = Logger.getRootLogger().getAllAppenders();
    while (appendersEnum.hasMoreElements()) {
        Appender object = (Appender) appendersEnum.nextElement();
        Logger.getRootLogger().removeAppender(object);
    }
}
Also used : Appender(org.apache.log4j.Appender)

Example 20 with Appender

use of org.apache.log4j.Appender in project ats-framework by Axway.

the class RemoteLoggingConfigurator method revert.

@Override
@SuppressWarnings("unchecked")
public void revert() {
    if (appenderLogger != null && needsToConfigureDbAppender) {
        // there is a DB appender and it is out-of-date
        //remove the filter which will deny logging of system events
        Logger rootLogger = Logger.getRootLogger();
        Enumeration<Appender> appenders = rootLogger.getAllAppenders();
        while (appenders.hasMoreElements()) {
            Appender appender = appenders.nextElement();
            //remove the filter
            //FIXME:This is very risky, as someone may have added other filters
            //the current implementation of the filter chain in log4j will not allow
            //us to easily remove a single filter
            appender.clearFilters();
        }
        Category log;
        if ("root".equals(appenderLogger)) {
            log = Logger.getRootLogger();
        } else {
            log = Logger.getLogger(appenderLogger);
        }
        Appender dbAppender = PassiveDbAppender.getCurrentInstance(ThreadsPerCaller.getCaller());
        if (dbAppender != null) {
            //close the appender
            dbAppender.close();
            //remove it
            log.removeAppender(dbAppender);
        }
    }
// in case we must reconfigure the custom loggers, here we should remove them from log4j, 
// but log4j does not provide a way to do it - so we do nothing here 
}
Also used : ActiveDbAppender(com.axway.ats.log.appenders.ActiveDbAppender) PassiveDbAppender(com.axway.ats.log.appenders.PassiveDbAppender) Appender(org.apache.log4j.Appender) AbstractDbAppender(com.axway.ats.log.appenders.AbstractDbAppender) Category(org.apache.log4j.Category) 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