use of org.apache.log4j.RollingFileAppender 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{ABSOLUTE}][%-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{ABSOLUTE}][%-5p][%t][%c{1}] %m%n"));
file.activateOptions();
log4j.addAppender(file);
}
}
use of org.apache.log4j.RollingFileAppender 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{ABSOLUTE}][%-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.RollingFileAppender in project ignite by apache.
the class GridSingleExecutionTest method initLogger.
/**
* Initializes logger.
*
* @param log Log file name.
* @return Logger.
* @throws IgniteCheckedException If file initialization failed.
*/
private static 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{ABSOLUTE}][%-5p][%t][%c{1}] %m%n";
try {
fileApp = new RollingFileAppender(new PatternLayout(fmt), fileName);
fileApp.setMaxBackupIndex(0);
fileApp.rollOver();
} 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.INFO);
lvlFilter.setLevelMax(Level.INFO);
conApp.addFilter(lvlFilter);
impl.addAppender(conApp);
// Configure output that should go to System.err
conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_ERR);
conApp.setThreshold(Level.WARN);
impl.addAppender(conApp);
impl.setLevel(Level.INFO);
Logger.getLogger("org.apache.ignite").setLevel(Level.DEBUG);
return new GridTestLog4jLogger(false);
}
use of org.apache.log4j.RollingFileAppender in project JMRI by JMRI.
the class Log4JUtil method startupInfo.
@SuppressWarnings("unchecked")
public static String startupInfo(String program) {
log.info(jmriLog);
Enumeration<org.apache.log4j.Logger> e = org.apache.log4j.Logger.getRootLogger().getAllAppenders();
while (e.hasMoreElements()) {
Appender a = (Appender) e.nextElement();
if (a instanceof RollingFileAppender) {
log.info("This log is appended to file: " + ((RollingFileAppender) a).getFile());
} else if (a instanceof FileAppender) {
log.info("This log is stored in file: " + ((FileAppender) a).getFile());
}
}
return (program + " version " + jmri.Version.name() + " starts under Java " + System.getProperty("java.version", "<unknown>") + " on " + System.getProperty("os.name", "<unknown>") + " " + System.getProperty("os.arch", "<unknown>") + " v" + System.getProperty("os.version", "<unknown>") + " at " + (new java.util.Date()));
}
use of org.apache.log4j.RollingFileAppender in project dhis2-core by dhis2.
the class Log4JLogConfigInitializer method getRollingFileAppender.
/**
* Returns a rolling file appender.
*
* @param file the file to output to, including path and filename.
*/
private RollingFileAppender getRollingFileAppender(String file) {
RollingFileAppender appender = new RollingFileAppender();
appender.setThreshold(Level.INFO);
appender.setFile(file);
appender.setMaxFileSize(MAX_FILE_SIZE);
appender.setLayout(PATTERN_LAYOUT);
appender.activateOptions();
return appender;
}
Aggregations