use of org.apache.log4j.ConsoleAppender in project ignite by apache.
the class Log4JLogger method addConsoleAppenderIfNeeded.
/**
* Adds console appender when needed with some default logging settings.
*
* @param logLevel Optional log level.
* @param implInitC Optional log implementation init closure.
*/
private void addConsoleAppenderIfNeeded(@Nullable Level logLevel, @Nullable IgniteClosure<Boolean, Logger> implInitC) {
if (inited) {
if (implInitC != null)
// Do not init.
impl = implInitC.apply(false);
return;
}
synchronized (mux) {
if (inited) {
if (implInitC != null)
// Do not init.
impl = implInitC.apply(false);
return;
}
if (implInitC != null)
// Init logger impl.
impl = implInitC.apply(true);
boolean quiet = Boolean.valueOf(System.getProperty(IGNITE_QUIET, "true"));
boolean consoleAppenderFound = false;
Category rootCategory = null;
ConsoleAppender errAppender = null;
for (Category l = impl; l != null; ) {
if (!consoleAppenderFound) {
for (Enumeration appenders = l.getAllAppenders(); appenders.hasMoreElements(); ) {
Appender appender = (Appender) appenders.nextElement();
if (appender instanceof ConsoleAppender) {
if ("CONSOLE_ERR".equals(appender.getName())) {
// Treat CONSOLE_ERR appender as a system one and don't count it.
errAppender = (ConsoleAppender) appender;
continue;
}
consoleAppenderFound = true;
break;
}
}
}
if (l.getParent() == null) {
rootCategory = l;
break;
} else
l = l.getParent();
}
if (consoleAppenderFound && quiet)
// User configured console appender, but log is quiet.
quiet = false;
if (!consoleAppenderFound && !quiet && Boolean.valueOf(System.getProperty(IGNITE_CONSOLE_APPENDER, "true"))) {
// Console appender not found => we've looked through all categories up to root.
assert rootCategory != null;
// to configuration and did not set IGNITE_CONSOLE_APPENDER to false.
if (errAppender != null) {
rootCategory.addAppender(createConsoleAppender(Level.INFO));
if (errAppender.getThreshold() == Level.ERROR)
errAppender.setThreshold(Level.WARN);
} else
// No error console appender => create console appender with no level limit.
rootCategory.addAppender(createConsoleAppender(Level.OFF));
if (logLevel != null)
impl.setLevel(logLevel);
}
// If still don't have appenders, disable logging.
if (!isConfigured())
impl.setLevel(Level.OFF);
quiet0 = quiet;
inited = true;
}
}
use of org.apache.log4j.ConsoleAppender in project ddf by codice.
the class XmlAttributeSecurityPolicyPluginTest method setUp.
@Before
public void setUp() {
org.apache.log4j.Logger.getRootLogger().addAppender(new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN)));
metacard.setMetadata(TEST_METADATA);
plugin = new XmlAttributeSecurityPolicyPlugin();
List<String> attributeUnions = Arrays.asList("controls", "marker");
List<String> attributeIntersections = Arrays.asList("countries");
List<String> xmlElements = Arrays.asList("title", "creator", "security");
plugin.setXmlElements(xmlElements);
plugin.setSecurityAttributeUnions(attributeUnions);
plugin.setSecurityAttributeIntersections(attributeIntersections);
}
Aggregations