use of org.apache.log4j.Appender in project symmetric-ds by JumpMind.
the class SnapshotUtil method findSymmetricLogFile.
@SuppressWarnings("unchecked")
public static Map<File, Layout> findSymmetricLogFile() {
Enumeration<Appender> appenders = org.apache.log4j.Logger.getRootLogger().getAllAppenders();
while (appenders.hasMoreElements()) {
Appender appender = appenders.nextElement();
if (appender instanceof FileAppender) {
FileAppender fileAppender = (FileAppender) appender;
if (fileAppender != null) {
File file = new File(fileAppender.getFile());
if (file != null && file.exists()) {
Map<File, Layout> matches = new HashMap<File, Layout>();
matches.put(file, fileAppender.getLayout());
return matches;
}
}
}
}
return null;
}
use of org.apache.log4j.Appender in project voltdb by VoltDB.
the class RealVoltDB method scheduleDailyLoggingWorkInNextCheckTime.
/**
* Get the next check time for a private member in log4j library, which is not a reliable idea.
* It adds 30 seconds for the initial delay and uses a periodical thread to schedule the daily logging work
* with this delay.
* @return
*/
void scheduleDailyLoggingWorkInNextCheckTime() {
DailyRollingFileAppender dailyAppender = null;
Enumeration<?> appenders = Logger.getRootLogger().getAllAppenders();
while (appenders.hasMoreElements()) {
Appender appender = (Appender) appenders.nextElement();
if (appender instanceof DailyRollingFileAppender) {
dailyAppender = (DailyRollingFileAppender) appender;
}
}
final DailyRollingFileAppender dailyRollingFileAppender = dailyAppender;
Field field = null;
if (dailyRollingFileAppender != null) {
try {
field = dailyRollingFileAppender.getClass().getDeclaredField("nextCheck");
field.setAccessible(true);
} catch (NoSuchFieldException e) {
hostLog.error("Failed to set daily system info logging: " + e.getMessage());
}
}
final Field nextCheckField = field;
long nextCheck = System.currentTimeMillis();
// the next part may throw exception, current time is the default value
if (dailyRollingFileAppender != null && nextCheckField != null) {
try {
nextCheck = nextCheckField.getLong(dailyRollingFileAppender);
scheduleWork(new DailyLogTask(), nextCheck - System.currentTimeMillis() + 30 * 1000, 0, TimeUnit.MILLISECONDS);
} catch (Exception e) {
hostLog.error("Failed to set daily system info logging: " + e.getMessage());
}
}
}
use of org.apache.log4j.Appender in project Activiti by Activiti.
the class MDCLoggingTest method setCustomLogger.
private void setCustomLogger() {
String PATTERN = "Modified Log *** ProcessDefinitionId=%X{mdcProcessDefinitionID} executionId=%X{mdcExecutionId} mdcProcessInstanceID=%X{mdcProcessInstanceID} mdcBusinessKey=%X{mdcBusinessKey} mdcTaskId=%X{mdcTaskId} %m%n";
console.setLayout(new PatternLayout(PATTERN));
console.setThreshold(Level.DEBUG);
console.activateOptions();
console.setName("MemoryAppender");
appenders = new ArrayList<Appender>();
Enumeration<?> appendersEnum = Logger.getRootLogger().getAllAppenders();
while (appendersEnum.hasMoreElements()) {
Appender object = (Appender) appendersEnum.nextElement();
appenders.add(object);
}
removeAppenders();
Logger.getRootLogger().addAppender(console);
}
use of org.apache.log4j.Appender in project Activiti by Activiti.
the class MDCLoggingTest method removeAppenders.
private void removeAppenders() {
Enumeration<?> appendersEnum = Logger.getRootLogger().getAllAppenders();
while (appendersEnum.hasMoreElements()) {
Appender object = (Appender) appendersEnum.nextElement();
Logger.getRootLogger().removeAppender(object);
}
}
use of org.apache.log4j.Appender in project ats-framework by Axway.
the class RemoteLoggingConfigurator method revert.
@Override
@SuppressWarnings("unchecked")
public void revert() {
if (appenderLogger != null && needsToConfigureDbAppender) {
// there is a DB appender and it is out-of-date
//remove the filter which will deny logging of system events
Logger rootLogger = Logger.getRootLogger();
Enumeration<Appender> appenders = rootLogger.getAllAppenders();
while (appenders.hasMoreElements()) {
Appender appender = appenders.nextElement();
//remove the filter
//FIXME:This is very risky, as someone may have added other filters
//the current implementation of the filter chain in log4j will not allow
//us to easily remove a single filter
appender.clearFilters();
}
Category log;
if ("root".equals(appenderLogger)) {
log = Logger.getRootLogger();
} else {
log = Logger.getLogger(appenderLogger);
}
Appender dbAppender = PassiveDbAppender.getCurrentInstance(ThreadsPerCaller.getCaller());
if (dbAppender != null) {
//close the appender
dbAppender.close();
//remove it
log.removeAppender(dbAppender);
}
}
// in case we must reconfigure the custom loggers, here we should remove them from log4j,
// but log4j does not provide a way to do it - so we do nothing here
}
Aggregations