use of org.apache.log4j.Category in project ats-framework by Axway.
the class RemoteLoggingConfigurator method apply.
@Override
@SuppressWarnings("unchecked")
public void apply() {
if (needsToConfigureDbAppender) {
//first get all appenders in the root category and apply 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();
if (!(appender instanceof AbstractDbAppender)) {
// apply this filter on all appenders which are not coming from ATS
appender.addFilter(new NoSystemLevelEventsFilter());
}
}
final String caller = ThreadsPerCaller.getCaller();
//create the new appender
PassiveDbAppender attachedAppender = new PassiveDbAppender(caller);
attachedAppender.setAppenderConfig(appenderConfiguration);
//use a default pattern, as we log in the db
attachedAppender.setLayout(new PatternLayout("%c{2}: %m%n"));
attachedAppender.activateOptions();
//attach the appender to the logging system
Category log;
if ("root".equals(appenderLogger)) {
log = Logger.getRootLogger();
} else {
log = Logger.getLogger(appenderLogger);
}
log.setLevel(Level.toLevel(appenderConfiguration.getLoggingThreshold().toInt()));
log.addAppender(attachedAppender);
}
if (needsToConfigureUserLoggers) {
for (Entry<String, Integer> userLogger : otherLoggerLevels.entrySet()) {
/*
* We want to set the level of this logger.
* It is not important if this logger is already attached to log4j system or
* not as the next code will obtain it(in case logger exists) or will create it
* and then will set its level
*/
Logger.getLogger(userLogger.getKey()).setLevel(Level.toLevel(userLogger.getValue()));
}
}
}
use of org.apache.log4j.Category in project zm-mailbox by Zimbra.
the class ZimbraPatternLayout method main.
public static void main(String[] args) {
Layout layout = new ZimbraPatternLayout("[%z] - %m%n");
Category cat = Category.getInstance("some.cat");
cat.addAppender(new ConsoleAppender(layout, ConsoleAppender.SYSTEM_OUT));
ZimbraLog.addAccountNameToContext("my@account.com");
ZimbraLog.addMboxToContext(99);
cat.debug("Hello, log");
cat.info("Hello again...");
ZimbraLog.clearContext();
cat.info("No more context");
}
use of org.apache.log4j.Category 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;
}
}
Aggregations