use of org.apache.log4j.PatternLayout in project ignite by apache.
the class GridCacheAbstractLoadTest method initLogger.
/**
* Initializes logger.
*
* @param log Log file name.
* @return Logger.
* @throws IgniteCheckedException If file initialization failed.
*/
protected IgniteLogger initLogger(String log) throws IgniteCheckedException {
Logger impl = Logger.getRootLogger();
impl.removeAllAppenders();
String fileName = U.getIgniteHome() + "/work/log/" + log;
// Configure output that should go to System.out
RollingFileAppender fileApp;
String fmt = "[%d{ISO8601}][%-5p][%t][%c{1}] %m%n";
try {
fileApp = new RollingFileAppender(new PatternLayout(fmt), fileName);
fileApp.setMaxBackupIndex(0);
fileApp.setAppend(false);
// fileApp.rollOver();
fileApp.activateOptions();
} catch (IOException e) {
throw new IgniteCheckedException("Unable to initialize file appender.", e);
}
LevelRangeFilter lvlFilter = new LevelRangeFilter();
lvlFilter.setLevelMin(Level.DEBUG);
fileApp.addFilter(lvlFilter);
impl.addAppender(fileApp);
// Configure output that should go to System.out
ConsoleAppender conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
lvlFilter = new LevelRangeFilter();
lvlFilter.setLevelMin(Level.DEBUG);
lvlFilter.setLevelMax(Level.INFO);
conApp.addFilter(lvlFilter);
conApp.activateOptions();
impl.addAppender(conApp);
// Configure output that should go to System.err
conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_ERR);
conApp.setThreshold(Level.WARN);
conApp.activateOptions();
impl.addAppender(conApp);
impl.setLevel(Level.INFO);
return new GridTestLog4jLogger(false);
}
use of org.apache.log4j.PatternLayout in project ignite by apache.
the class GridAbstractTest method resetLog4j.
/**
* Resets log4j programmatically.
*
* @param log4jLevel Level.
* @param logToFile If {@code true}, then log to file under "work/log" folder.
* @param cat Category.
* @param cats Additional categories.
*/
@SuppressWarnings({ "deprecation" })
protected void resetLog4j(Level log4jLevel, boolean logToFile, String cat, String... cats) throws IgniteCheckedException {
for (String c : F.concat(false, cat, F.asList(cats))) Logger.getLogger(c).setLevel(log4jLevel);
if (logToFile) {
Logger log4j = Logger.getRootLogger();
log4j.removeAllAppenders();
// Console appender.
ConsoleAppender c = new ConsoleAppender();
c.setName("CONSOLE_ERR");
c.setTarget("System.err");
c.setThreshold(Priority.WARN);
c.setLayout(new PatternLayout("[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"));
c.activateOptions();
log4j.addAppender(c);
// File appender.
RollingFileAppender file = new RollingFileAppender();
file.setName("FILE");
file.setThreshold(log4jLevel);
file.setFile(home() + "/work/log/ignite.log");
file.setAppend(false);
file.setMaxFileSize("10MB");
file.setMaxBackupIndex(10);
file.setLayout(new PatternLayout("[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"));
file.activateOptions();
log4j.addAppender(file);
}
}
use of org.apache.log4j.PatternLayout in project ignite by apache.
the class GridTestLog4jLogger method createConsoleAppender.
/**
* Creates console appender with some reasonable default logging settings.
*
* @param maxLevel Max logging level.
* @return New console appender.
*/
private Appender createConsoleAppender(Level maxLevel) {
String fmt = "[%d{ISO8601}][%-5p][%t][%c{1}] %m%n";
// Configure output that should go to System.out
Appender app = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
LevelRangeFilter lvlFilter = new LevelRangeFilter();
lvlFilter.setLevelMin(Level.TRACE);
lvlFilter.setLevelMax(maxLevel);
app.addFilter(lvlFilter);
return app;
}
use of org.apache.log4j.PatternLayout in project leopard by tanhaichao.
the class LogDaoLog4jImpl method getAppender.
protected Appender getAppender(String filename, org.apache.log4j.Level log4jLevel, boolean bufferedIO) {
String key = filename + ":" + log4jLevel.toInt() + ":" + bufferedIO;
DailyAutoRollingFileAppender appender = appenderMap.get(key);
if (appender != null) {
return appender;
}
String conversionPattern = "%d{yyyy-MM-dd HH:mm:ss} - [%c] - %m%n";
org.apache.log4j.PatternLayout layout = new PatternLayout();
layout.setConversionPattern(conversionPattern);
appender = new DailyAutoRollingFileAppender();
// DailyRollingFileAppender newAppender = new DailyRollingFileAppender();
appender.setThreshold(log4jLevel);
appender.setLayout(layout);
appender.setDatePattern(".yyyyMMdd");
appender.setFile(filename);
// 8192
appender.setBufferSize(10);
appender.setBufferedIO(bufferedIO);
appender.activateOptions();
appenderMap.put(key, appender);
return appender;
}
use of org.apache.log4j.PatternLayout in project metron by apache.
the class UnitTestHelper method verboseLogging.
public static void verboseLogging(String pattern, Level level) {
// create appender
ConsoleAppender console = new ConsoleAppender();
// configure the appender
console.setLayout(new PatternLayout(pattern));
console.setThreshold(level);
console.activateOptions();
// add appender to any Logger (here is root)
Logger.getRootLogger().addAppender(console);
}
Aggregations