use of org.apache.log4j.spi.LoggerRepository in project uavstack by uavorg.
the class Log4jHookProxy method figureOutLog4jConfig.
/**
* figure out the log4j's configuration: for example, appenders' file path, buff io, etc...
*
* @param context
* @param webapploader
*/
@SuppressWarnings({ "rawtypes", "static-access" })
private void figureOutLog4jConfig(HookContext context, ClassLoader webapploader) {
Logger logger4j = Logger.getLogger(Log4jHookProxy.class);
InterceptContext interceptContext = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);
if (interceptContext == null) {
logger.warn("No InterceptContext available, can't figure out Log4j configuration.", null);
return;
}
@SuppressWarnings("unchecked") LinkedList<LogProfileInfo> list = (LinkedList<LogProfileInfo>) interceptContext.get(HookConstants.LOG_PROFILE_LIST);
if (null == list) {
list = new LinkedList<LogProfileInfo>();
interceptContext.put(HookConstants.LOG_PROFILE_LIST, list);
}
String appid = (String) (interceptContext.get(InterceptConstants.CONTEXTPATH));
// figureout root logger
list.addAll(figureoutLogConfiguration(logger4j.getRootLogger(), appid));
// figureour norootlogger
LoggerRepository lr = null;
try {
lr = logger4j.getLoggerRepository();
} catch (NoSuchMethodError err) {
// for log4j-over-slf4j, doesn't have this method
return;
}
Enumeration logEnum = lr.getCurrentLoggers();
while (logEnum != null && logEnum.hasMoreElements()) {
Logger sLogger = (Logger) logEnum.nextElement();
list.addAll(figureoutLogConfiguration(sLogger, appid));
}
}
use of org.apache.log4j.spi.LoggerRepository in project JMRI by JMRI.
the class Log4JTreePane method initComponents.
/**
* 2nd stage of initialization, invoked after the constructor is complete.
*/
@SuppressWarnings("unchecked")
@Override
public void initComponents() throws Exception {
LoggerRepository repo = Logger.getRootLogger().getLoggerRepository();
List<String> list = new ArrayList<String>();
for (java.util.Enumeration<Logger> e = repo.getCurrentLoggers(); e.hasMoreElements(); ) {
Logger l = e.nextElement();
list.add(l.getName() + " - " + (l.getLevel() != null ? "[" + l.getLevel().toString() + "]" : "{" + Logger.getRootLogger().getLevel().toString() + "}"));
}
java.util.Collections.sort(list);
StringBuilder result = new StringBuilder();
for (String s : list) {
result.append(s).append("\n");
}
JTextArea text = new JTextArea();
text.setText(result.toString());
JScrollPane scroll = new JScrollPane(text);
add(scroll);
// start scrolled to top
text.setCaretPosition(0);
JScrollBar b = scroll.getVerticalScrollBar();
b.setValue(b.getMaximum());
}
use of org.apache.log4j.spi.LoggerRepository in project OpenOLAT by OpenOLAT.
the class ThreadLocalLogLevelManager method install.
/**
* Installs the ThreadLogManager in this system.
* <p>
* Note that this can fail if some other framework
* has done a call to LogManager.setRepositorySelector
* with a guard already.
* @see org.apache.log4j.LogManager#setRepositorySelector(org.apache.log4j.spi.RepositorySelector, Object)
* @param logMessageModifier optional implementation of LogMessageModifier
* which allows messages to be modified should they be affected by
* a threadlocal loglevel overwrite. This allows for example for
* messages to be prepended with a token so that they can be easier
* found in the log
*/
void install(final LogMessageModifier logMessageModifier) {
try {
final LoggerFactory loggerFactory = new LoggerFactory() {
@SuppressWarnings("synthetic-access")
@Override
public Logger makeNewLoggerInstance(String name) {
return new ThreadLocalAwareLogger(name, threadLocalLogLevel_, logMessageModifier);
}
};
final Logger originalRootLogger = LogManager.getRootLogger();
final LoggerRepository parentRepository = originalRootLogger.getLoggerRepository();
final LoggerRepository repository = new ThreadLocalAwareLoggerRepository(originalRootLogger, parentRepository, loggerFactory);
LogManager.setRepositorySelector(new RepositorySelector() {
@Override
public LoggerRepository getLoggerRepository() {
return repository;
}
}, guard);
} catch (IllegalArgumentException | SecurityException re) {
// thrown by LogManager.setRepositorySelector
Logger.getLogger(ThreadLocalLogLevelManager.class).error("Could not install ThreadLocalLogLevelManager");
}
}
use of org.apache.log4j.spi.LoggerRepository in project parseq by linkedin.
the class TestUtil method withDisabledLogging.
public static void withDisabledLogging(final Runnable r) {
// Note: this assumes we're using Log4J and needs to be fixed up if this changes.
final LoggerRepository loggerRepo = LogManager.getLoggerRepository();
final Level oldLevel = loggerRepo.getThreshold();
loggerRepo.setThreshold(Level.OFF);
try {
r.run();
} finally {
loggerRepo.setThreshold(oldLevel);
}
}
Aggregations