Search in sources :

Example 26 with PatternLayout

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

the class TaskLoggerTest method getStoredLogs.

@Test
public void getStoredLogs() throws Exception {
    taskLogger = new TaskLogger(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L), "myhost");
    final StringWriter stringAppender = new StringWriter();
    AppenderProvider stringAppenderProvider = new AppenderProvider() {

        @Override
        public Appender getAppender() throws LogForwardingException {
            return new WriterAppender(new PatternLayout("%m%n"), stringAppender);
        }
    };
    taskLogger.getStoredLogs(stringAppenderProvider);
    assertEquals("", stringAppender.toString());
    taskLogger.getOutputSink().println("hello");
    taskLogger.getStoredLogs(stringAppenderProvider);
    assertEquals(String.format("hello%n"), stringAppender.toString());
}
Also used : StringWriter(java.io.StringWriter) AppenderProvider(org.ow2.proactive.scheduler.common.util.logforwarder.AppenderProvider) PatternLayout(org.apache.log4j.PatternLayout) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) WriterAppender(org.apache.log4j.WriterAppender) Test(org.junit.Test)

Example 27 with PatternLayout

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

the class TaskLoggerTest method logStreaming.

@Test
public void logStreaming() throws Exception {
    taskLogger = new TaskLogger(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L), "myhost");
    final StringWriter stringAppender = new StringWriter();
    AppenderProvider stringAppenderProvider = new AppenderProvider() {

        @Override
        public Appender getAppender() throws LogForwardingException {
            return new WriterAppender(new PatternLayout("%m%n"), stringAppender);
        }
    };
    taskLogger.activateLogs(stringAppenderProvider);
    assertEquals("", stringAppender.toString());
    taskLogger.getOutputSink().println("hello");
    // async appender, it gets buffered
    assertEquals("", stringAppender.toString());
    for (int i = 0; i < 1000; i++) {
        taskLogger.getOutputSink().println("hello");
    }
    assertNotEquals("", stringAppender.toString());
}
Also used : StringWriter(java.io.StringWriter) AppenderProvider(org.ow2.proactive.scheduler.common.util.logforwarder.AppenderProvider) PatternLayout(org.apache.log4j.PatternLayout) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) WriterAppender(org.apache.log4j.WriterAppender) Test(org.junit.Test)

Example 28 with PatternLayout

use of org.apache.log4j.PatternLayout in project tray by qzind.

the class PrintSocketServer method setupFileLogging.

public static void setupFileLogging() {
    FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
    rollingPolicy.setFileNamePattern(SystemUtilities.getDataDirectory() + File.separator + Constants.LOG_FILE + ".log.%i");
    rollingPolicy.setMaxIndex(Constants.LOG_ROTATIONS);
    SizeBasedTriggeringPolicy triggeringPolicy = new SizeBasedTriggeringPolicy(Constants.LOG_SIZE);
    RollingFileAppender fileAppender = new RollingFileAppender();
    fileAppender.setLayout(new PatternLayout("%d{ISO8601} [%p] %m%n"));
    fileAppender.setThreshold(Level.DEBUG);
    fileAppender.setFile(SystemUtilities.getDataDirectory() + File.separator + Constants.LOG_FILE + ".log");
    fileAppender.setRollingPolicy(rollingPolicy);
    fileAppender.setTriggeringPolicy(triggeringPolicy);
    fileAppender.setEncoding("UTF-8");
    fileAppender.setImmediateFlush(true);
    fileAppender.activateOptions();
    org.apache.log4j.Logger.getRootLogger().addAppender(fileAppender);
}
Also used : FixedWindowRollingPolicy(org.apache.log4j.rolling.FixedWindowRollingPolicy) RollingFileAppender(org.apache.log4j.rolling.RollingFileAppender) PatternLayout(org.apache.log4j.PatternLayout) SizeBasedTriggeringPolicy(org.apache.log4j.rolling.SizeBasedTriggeringPolicy)

Example 29 with PatternLayout

use of org.apache.log4j.PatternLayout in project tray by qzind.

the class LogDialog method initComponents.

public void initComponents() {
    setIconImage(getImage(IconCache.Icon.LOG_ICON));
    LinkLabel logDirLabel = new LinkLabel(SystemUtilities.getDataDirectory() + File.separator);
    logDirLabel.setText("Open Log Location");
    setHeader(logDirLabel);
    logArea = new JTextArea(ROWS, COLS);
    logArea.setEditable(false);
    logArea.setLineWrap(true);
    logArea.setWrapStyleWord(true);
    // TODO:  Fix button panel resizing issues
    clearButton = addPanelButton("Clear", IconCache.Icon.DELETE_ICON, KeyEvent.VK_L);
    clearButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            logArea.setText(null);
        }
    });
    logPane = new JScrollPane(logArea);
    setContent(logPane, true);
    setResizable(true);
    // add new appender to Log4J just for text area
    logStream = new WriterAppender(new PatternLayout("[%p] %d{ISO8601} @ %c:%L%n\t%m%n"), new OutputStream() {

        @Override
        public void write(final int b) throws IOException {
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    logArea.append(String.valueOf((char) b));
                    logPane.getVerticalScrollBar().setValue(logPane.getVerticalScrollBar().getMaximum());
                }
            });
        }
    });
    logStream.setThreshold(Level.TRACE);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) PatternLayout(org.apache.log4j.PatternLayout) OutputStream(java.io.OutputStream) WriterAppender(org.apache.log4j.WriterAppender)

Example 30 with PatternLayout

use of org.apache.log4j.PatternLayout in project QueryAnalysis by Wikidata.

the class LoggingHandler method initConsoleLog.

/**
 * Defines an appender that writes INFO log messages to the console.
 */
public static void initConsoleLog() {
    ConsoleAppender consoleAppender = new ConsoleAppender();
    consoleAppender.setName("ConsoleLogger");
    consoleAppender.setLayout(new PatternLayout(" [%p] %d [%t] %x %c %M - %m%n"));
    LevelRangeFilter levelRangeFilter = new LevelRangeFilter();
    levelRangeFilter.setLevelMax(Level.INFO);
    levelRangeFilter.setLevelMin(Level.INFO);
    consoleAppender.addFilter(levelRangeFilter);
    consoleAppender.activateOptions();
    Logger.getRootLogger().addAppender(consoleAppender);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) PatternLayout(org.apache.log4j.PatternLayout) LevelRangeFilter(org.apache.log4j.varia.LevelRangeFilter)

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