Search in sources :

Example 11 with Appender

use of org.apache.log4j.Appender in project honeycomb by altamiracorp.

the class Bootstrap method ensureLoggingPathsCorrect.

private static void ensureLoggingPathsCorrect() {
    Enumeration<?> allAppenders = Logger.getRootLogger().getAllAppenders();
    while (allAppenders.hasMoreElements()) {
        Appender appender = (Appender) allAppenders.nextElement();
        if (appender instanceof FileAppender) {
            FileAppender fileAppender = (FileAppender) appender;
            String file = fileAppender.getFile();
            if (file == null) {
                continue;
            }
            File f = new File(file);
            System.err.println("Testing: " + f.getName());
            if (f.exists()) {
                if (!f.canWrite()) {
                    System.err.println("Cannot write to " + f.getName());
                }
            } else {
                String createFailure = "Could not create logging file " + f.getName();
                try {
                    if (!f.createNewFile()) {
                        System.err.println(createFailure);
                        throw new RuntimeException(createFailure);
                    }
                } catch (IOException e) {
                    System.err.println(createFailure);
                    throw new RuntimeException(createFailure, e);
                }
            }
        }
    }
}
Also used : Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender) FileAppender(org.apache.log4j.FileAppender) IOException(java.io.IOException) File(java.io.File)

Example 12 with Appender

use of org.apache.log4j.Appender in project databus by linkedin.

the class TestFilterToSQL method setUp.

@BeforeClass
public void setUp() throws IOException, DatabusException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
    Logger.getRootLogger().removeAllAppenders();
    Appender defApp = new ConsoleAppender(new SimpleLayout());
    Logger.getRootLogger().addAppender(defApp);
    Logger.getRootLogger().setLevel(Level.INFO);
    BootstrapServerConfig configBuilder = new BootstrapServerConfig();
    BootstrapServerStaticConfig staticConfig = configBuilder.build();
    processor = new BootstrapProcessor(staticConfig, null);
    partConf = new KeyFilterConfigHolder.Config();
}
Also used : Appender(org.apache.log4j.Appender) ConsoleAppender(org.apache.log4j.ConsoleAppender) ConsoleAppender(org.apache.log4j.ConsoleAppender) BootstrapServerConfig(com.linkedin.databus.bootstrap.server.BootstrapServerConfig) BootstrapProcessor(com.linkedin.databus.bootstrap.server.BootstrapProcessor) KeyFilterConfigHolder(com.linkedin.databus2.core.filter.KeyFilterConfigHolder) SimpleLayout(org.apache.log4j.SimpleLayout) BootstrapServerStaticConfig(com.linkedin.databus.bootstrap.server.BootstrapServerStaticConfig) BeforeClass(org.testng.annotations.BeforeClass)

Example 13 with Appender

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

the class AgentConsoleLogThread method run.

public void run() {
    BufferedReader reader = new BufferedReader(new InputStreamReader(consoleError));
    Appender consoleFileAppender = LoggingHelper.createConsoleFileAppender(ndc, consoleFileName);
    Logger.getRootLogger().addAppender(consoleFileAppender);
    NDC.push(ndc.toString());
    while (true) {
        if (!keepRunning && flushedAfterStop) {
            break;
        }
        try {
            logConsoleError(reader);
            Thread.sleep(1000);
        } catch (Exception e) {
            LOG.error("Error occured while capturing console output from agent process: ", e);
            break;
        }
    }
    NDC.pop();
    Logger.getRootLogger().removeAppender(consoleFileAppender);
}
Also used : Appender(org.apache.log4j.Appender) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 14 with Appender

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

the class FileLocationProvider method asJson.

@Override
public Map<String, Object> asJson() {
    LinkedHashMap<String, Object> json = new LinkedHashMap<>();
    json.put("loc.config.dir", systemEnvironment.configDir().getAbsolutePath());
    List<Logger> loggers = new ArrayList<>();
    Logger rootLogger = Logger.getRootLogger();
    loggers.add(rootLogger);
    Enumeration currentLoggers = rootLogger.getLoggerRepository().getCurrentLoggers();
    while (currentLoggers.hasMoreElements()) {
        loggers.add((Logger) currentLoggers.nextElement());
    }
    int index = 0;
    for (Logger logger : loggers) {
        Enumeration appenders = logger.getAllAppenders();
        while (appenders.hasMoreElements()) {
            Appender appender = (Appender) appenders.nextElement();
            if (!isFileAppender(appender)) {
                continue;
            }
            FileAppender fileAppender = (FileAppender) appender;
            File logFile = new File(fileAppender.getFile());
            json.put("loc.log.root." + index, new File(logFile.getAbsolutePath()).getParent());
            json.put("loc.log.basename." + index, logFile.getName());
            ++index;
        }
    }
    return json;
}
Also used : Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender) FileAppender(org.apache.log4j.FileAppender) Logger(org.apache.log4j.Logger) File(java.io.File)

Example 15 with Appender

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

the class AbstractCommandLauncher method configureLogging.

protected void configureLogging(CommandLine line) throws MalformedURLException {
    /* Optionally remove existing handlers attached to j.u.l root logger */
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    /*
         * Add SLF4JBridgeHandler to j.u.l's root logger, should be done once
         * during the initialization phase of your application
         */
    SLF4JBridgeHandler.install();
    URL log4jUrl = new URL(System.getProperty("log4j.configuration", "file:" + AppUtils.getSymHome() + "/conf/log4j-blank.xml"));
    File log4jFile = new File(new File(log4jUrl.getFile()).getParent(), "log4j.xml");
    if (line.hasOption(OPTION_DEBUG)) {
        log4jFile = new File(log4jFile.getParent(), "log4j-debug.xml");
    }
    if (log4jFile.exists()) {
        DOMConfigurator.configure(log4jFile.getAbsolutePath());
    }
    if (line.hasOption(OPTION_VERBOSE_CONSOLE)) {
        Appender consoleAppender = org.apache.log4j.Logger.getRootLogger().getAppender("CONSOLE");
        if (consoleAppender != null) {
            Layout layout = consoleAppender.getLayout();
            if (layout instanceof PatternLayout) {
                ((PatternLayout) layout).setConversionPattern("%d %-5p [%c{2}] [%t] %m%n");
            }
        }
    }
    if (line.hasOption(OPTION_NO_LOG_CONSOLE)) {
        org.apache.log4j.Logger.getRootLogger().removeAppender("CONSOLE");
    }
    if (line.hasOption(OPTION_NO_LOG_FILE)) {
        org.apache.log4j.Logger.getRootLogger().removeAppender("ROLLING");
    } else {
        Appender appender = org.apache.log4j.Logger.getRootLogger().getAppender("ROLLING");
        if (appender instanceof FileAppender) {
            FileAppender fileAppender = (FileAppender) appender;
            if (line.hasOption(OPTION_PROPERTIES_FILE)) {
                File file = new File(line.getOptionValue(OPTION_PROPERTIES_FILE));
                String name = file.getName();
                int index = name.lastIndexOf(".");
                if (index > 0) {
                    name = name.substring(0, index);
                }
                fileAppender.setFile(fileAppender.getFile().replace("symmetric.log", name + ".log"));
                fileAppender.activateOptions();
            }
            System.err.println(String.format("Log output will be written to %s", fileAppender.getFile()));
        }
    }
}
Also used : Appender(org.apache.log4j.Appender) FileAppender(org.apache.log4j.FileAppender) FileAppender(org.apache.log4j.FileAppender) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout) PatternLayout(org.apache.log4j.PatternLayout) File(java.io.File) URL(java.net.URL)

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