Search in sources :

Example 16 with Layout

use of org.apache.log4j.Layout in project traccar by tananaev.

the class Log method setupLogger.

public static void setupLogger(Config config) throws IOException {
    Layout layout = new PatternLayout("%d{" + DATE_FORMAT + "} %5p: %m%n");
    Appender appender = new DailyRollingFileAppender(layout, config.getString("logger.file"), "'.'yyyyMMdd");
    LogManager.resetConfiguration();
    LogManager.getRootLogger().addAppender(new NullAppender());
    logger = Logger.getLogger(LOGGER_NAME);
    logger.addAppender(appender);
    logger.setLevel(Level.toLevel(config.getString("logger.level"), Level.ALL));
    // Workaround for "Bug 745866 - (EDG-45) Possible netty logging config problem"
    InternalLoggerFactory.setDefaultFactory(new InternalLoggerFactory() {

        @Override
        public InternalLogger newInstance(String string) {
            return new NettyInternalLogger();
        }
    });
    Log.logSystemInfo();
    Log.info("Version: " + getAppVersion());
}
Also used : NullAppender(org.apache.log4j.varia.NullAppender) DailyRollingFileAppender(org.apache.log4j.DailyRollingFileAppender) Appender(org.apache.log4j.Appender) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout) NullAppender(org.apache.log4j.varia.NullAppender) PatternLayout(org.apache.log4j.PatternLayout) InternalLoggerFactory(org.jboss.netty.logging.InternalLoggerFactory) DailyRollingFileAppender(org.apache.log4j.DailyRollingFileAppender) InternalLogger(org.jboss.netty.logging.InternalLogger) AbstractInternalLogger(org.jboss.netty.logging.AbstractInternalLogger)

Example 17 with Layout

use of org.apache.log4j.Layout in project scheduling by ow2-proactive.

the class Log4JTaskLogs method getStdoutLogs.

/**
 * @see org.ow2.proactive.scheduler.common.task.TaskLogs#getStdoutLogs(boolean
 *      timeStamp)
 */
public synchronized String getStdoutLogs(boolean timeStamp) {
    restoreEvents();
    StringBuffer logs = new StringBuffer();
    Layout l = getTaskLogLayout();
    for (LoggingEvent e : this.allEvents) {
        if (Log4JTaskLogs.STDOUT_LEVEL.equals(e.getLevel())) {
            appendEventToLogs(e, logs, l, timeStamp);
        }
    }
    return logs.toString();
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout)

Example 18 with Layout

use of org.apache.log4j.Layout in project scheduling by ow2-proactive.

the class Log4JTaskLogs method getAllLogs.

/**
 * @see org.ow2.proactive.scheduler.common.task.TaskLogs#getAllLogs(boolean
 *      timeStamp)
 */
public synchronized String getAllLogs(boolean timeStamp) {
    restoreEvents();
    StringBuffer logs = new StringBuffer(this.allEvents.size());
    Layout l = getTaskLogLayout();
    for (LoggingEvent e : this.allEvents) {
        appendEventToLogs(e, logs, l, timeStamp);
    }
    return logs.toString();
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout)

Example 19 with Layout

use of org.apache.log4j.Layout in project scheduling by ow2-proactive.

the class Log4JTaskLogs method getStderrLogs.

/**
 * @see org.ow2.proactive.scheduler.common.task.TaskLogs#getStderrLogs(boolean
 *      timeStamp)
 */
public synchronized String getStderrLogs(boolean timeStamp) {
    restoreEvents();
    StringBuffer logs = new StringBuffer();
    Layout l = getTaskLogLayout();
    for (LoggingEvent e : this.allEvents) {
        if (Log4JTaskLogs.STDERR_LEVEL.equals(e.getLevel())) {
            appendEventToLogs(e, logs, l, timeStamp);
        }
    }
    return logs.toString();
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout)

Aggregations

Layout (org.apache.log4j.Layout)19 PatternLayout (org.apache.log4j.PatternLayout)12 WriterAppender (org.apache.log4j.WriterAppender)9 Test (org.junit.Test)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 Appender (org.apache.log4j.Appender)6 Logger (org.apache.log4j.Logger)6 LineNumberReader (java.io.LineNumberReader)5 StringReader (java.io.StringReader)5 Pattern (java.util.regex.Pattern)4 LoggingEvent (org.apache.log4j.spi.LoggingEvent)4 File (java.io.File)3 FileAppender (org.apache.log4j.FileAppender)3 SimpleLayout (org.apache.log4j.SimpleLayout)3 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 Category (org.apache.log4j.Category)2 NullAppender (org.apache.log4j.varia.NullAppender)2 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1