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());
}
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());
}
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);
}
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);
}
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);
}
Aggregations