Search in sources :

Example 6 with PatternLayout

use of org.apache.log4j.PatternLayout in project cpsolver by UniTime.

the class Test method setupLogging.

/**
     * Setup log4j logging
     * 
     * @param logFile  log file
     * @param debug true if debug messages should be logged (use -Ddebug=true to enable debug message)
     */
public static void setupLogging(File logFile, boolean debug) {
    Logger root = Logger.getRootLogger();
    ConsoleAppender console = new ConsoleAppender(new PatternLayout("[%t] %m%n"));
    console.setThreshold(Level.INFO);
    root.addAppender(console);
    if (logFile != null) {
        try {
            FileAppender file = new FileAppender(new PatternLayout("%d{dd-MMM-yy HH:mm:ss.SSS} [%t] %-5p %c{2}> %m%n"), logFile.getPath(), false);
            file.setThreshold(Level.DEBUG);
            root.addAppender(file);
        } catch (IOException e) {
            sLogger.fatal("Unable to configure logging, reason: " + e.getMessage(), e);
        }
    }
    if (!debug)
        root.setLevel(Level.INFO);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) FileAppender(org.apache.log4j.FileAppender) PatternLayout(org.apache.log4j.PatternLayout) IOException(java.io.IOException) Logger(org.apache.log4j.Logger)

Example 7 with PatternLayout

use of org.apache.log4j.PatternLayout in project cpsolver by UniTime.

the class Test method setupLogging.

/**
     * Setup log4j logging
     * 
     * @param logFile  log file
     */
public static void setupLogging(File logFile) {
    Logger root = Logger.getRootLogger();
    ConsoleAppender console = new ConsoleAppender(new PatternLayout("[%t] %m%n"));
    console.setThreshold(Level.INFO);
    root.addAppender(console);
    if (logFile != null) {
        try {
            FileAppender file = new FileAppender(new PatternLayout("%d{dd-MMM-yy HH:mm:ss.SSS} [%t] %-5p %c{2}> %m%n"), logFile.getPath(), false);
            file.setThreshold(Level.DEBUG);
            root.addAppender(file);
        } catch (IOException e) {
            sLog.fatal("Unable to configure logging, reason: " + e.getMessage(), e);
        }
    }
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) FileAppender(org.apache.log4j.FileAppender) PatternLayout(org.apache.log4j.PatternLayout) IOException(java.io.IOException) Logger(org.apache.log4j.Logger)

Example 8 with PatternLayout

use of org.apache.log4j.PatternLayout in project intellij-community by JetBrains.

the class Runner method initLogger.

public static void initLogger() {
    if (logger == null) {
        long requiredFreeSpace = 1000000;
        String logFolder = getDir(requiredFreeSpace);
        FileAppender update = new FileAppender();
        update.setFile(new File(logFolder, "idea_updater.log").getAbsolutePath());
        update.setLayout(new PatternLayout("%d{dd MMM yyyy HH:mm:ss} %-5p %C{1}.%M - %m%n"));
        update.setThreshold(Level.ALL);
        update.setAppend(true);
        update.activateOptions();
        FileAppender updateError = new FileAppender();
        updateError.setFile(new File(logFolder, "idea_updater_error.log").getAbsolutePath());
        updateError.setLayout(new PatternLayout("%d{dd MMM yyyy HH:mm:ss} %-5p %C{1}.%M - %m%n"));
        updateError.setThreshold(Level.ERROR);
        updateError.setAppend(false);
        updateError.activateOptions();
        logger = Logger.getLogger("com.intellij.updater");
        logger.addAppender(updateError);
        logger.addAppender(update);
        logger.setLevel(Level.ALL);
        logger.info("--- Updater started ---");
    }
}
Also used : FileAppender(org.apache.log4j.FileAppender) PatternLayout(org.apache.log4j.PatternLayout) ZipFile(java.util.zip.ZipFile)

Example 9 with PatternLayout

use of org.apache.log4j.PatternLayout 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 10 with PatternLayout

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

the class SymRollingFileAppenderTest method getAppenderForTest.

protected SymRollingFileAppender getAppenderForTest(ByteArrayOutputStream os) throws Exception {
    SymRollingFileAppender appender = new SymRollingFileAppender();
    PatternLayout layout = new PatternLayout("%d %p [%X{engineName}] [%c{1}] [%t] %m%n");
    appender.setLayout(layout);
    appender.setOutputStream(os);
    return appender;
}
Also used : PatternLayout(org.apache.log4j.PatternLayout)

Aggregations

PatternLayout (org.apache.log4j.PatternLayout)106 ConsoleAppender (org.apache.log4j.ConsoleAppender)49 Logger (org.apache.log4j.Logger)30 IOException (java.io.IOException)20 Appender (org.apache.log4j.Appender)20 FileAppender (org.apache.log4j.FileAppender)17 File (java.io.File)14 Layout (org.apache.log4j.Layout)14 RollingFileAppender (org.apache.log4j.RollingFileAppender)12 Test (org.junit.Test)12 WriterAppender (org.apache.log4j.WriterAppender)9 CommandLineParser (org.apache.commons.cli.CommandLineParser)7 GnuParser (org.apache.commons.cli.GnuParser)7 ParseException (org.apache.commons.cli.ParseException)7 DailyRollingFileAppender (org.apache.log4j.DailyRollingFileAppender)7 FileInputStream (java.io.FileInputStream)6 Properties (java.util.Properties)6 CommandLine (org.apache.commons.cli.CommandLine)6 Option (org.apache.commons.cli.Option)6 Options (org.apache.commons.cli.Options)6