本文整理匯總了Java中org.apache.log4j.Category.getAllAppenders方法的典型用法代碼示例。如果您正苦於以下問題:Java Category.getAllAppenders方法的具體用法?Java Category.getAllAppenders怎麽用?Java Category.getAllAppenders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.log4j.Category
的用法示例。
在下文中一共展示了Category.getAllAppenders方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setup
import org.apache.log4j.Category; //導入方法依賴的package包/類
@BeforeClass
public static void setup() throws Exception
{
logger.debug("Logger repository before LoggerUtil.changeLoggersLevel() {}", LogManager.getLoggerRepository());
LoggerUtil.changeLoggersLevel(Maps.<String, String>newHashMap());
logger.debug("Logger repository after LoggerUtil.changeLoggersLevel() {}", LogManager.getLoggerRepository());
log4jLogger.setLevel(Level.TRACE);
Category category = log4jLogger;
while (category != null) {
Enumeration appenders = category.getAllAppenders();
while (appenders.hasMoreElements()) {
Object o = appenders.nextElement();
if (o instanceof AppenderSkeleton) {
AppenderSkeleton appender = (AppenderSkeleton)o;
if (!appenderLevelMap.containsKey(appender)) {
appenderLevelMap.put(appender, appender.getThreshold());
appender.setThreshold(Level.INFO);
}
}
}
if (category.getAdditivity()) {
category = category.getParent();
} else {
category = null;
}
}
}
示例2: printOptions
import org.apache.log4j.Category; //導入方法依賴的package包/類
protected
void printOptions(PrintWriter out, Category cat) {
Enumeration appenders = cat.getAllAppenders();
Level prio = cat.getLevel();
String appenderString = (prio == null ? "" : prio.toString());
while (appenders.hasMoreElements()) {
Appender app = (Appender) appenders.nextElement();
String name;
if ((name = (String) appenderNames.get(app)) == null) {
// first assign name to the appender
if ((name = app.getName()) == null || isGenAppName(name)) {
name = genAppName();
}
appenderNames.put(app, name);
printOptions(out, app, "log4j.appender."+name);
if (app.getLayout() != null) {
printOptions(out, app.getLayout(), "log4j.appender."+name+".layout");
}
}
appenderString += ", " + name;
}
String catKey = (cat == Logger.getRootLogger())
? "log4j.rootLogger"
: "log4j.logger." + cat.getName();
if (appenderString != "") {
out.println(catKey + "=" + appenderString);
}
if (!cat.getAdditivity() && cat != Logger.getRootLogger()) {
out.println("log4j.additivity." + cat.getName() + "=false");
}
}
示例3: printOptions
import org.apache.log4j.Category; //導入方法依賴的package包/類
/**
* @since 1.2.15
*/
protected
void printOptions(PrintWriter out, Category cat) {
Enumeration appenders = cat.getAllAppenders();
Level prio = cat.getLevel();
String appenderString = (prio == null ? "" : prio.toString());
while (appenders.hasMoreElements()) {
Appender app = (Appender) appenders.nextElement();
String name;
if ((name = (String) appenderNames.get(app)) == null) {
// first assign name to the appender
if ((name = app.getName()) == null || isGenAppName(name)) {
name = genAppName();
}
appenderNames.put(app, name);
printOptions(out, app, "log4j.appender."+name);
if (app.getLayout() != null) {
printOptions(out, app.getLayout(), "log4j.appender."+name+".layout");
}
}
appenderString += ", " + name;
}
String catKey = (cat == Logger.getRootLogger())
? "log4j.rootLogger"
: "log4j.logger." + cat.getName();
if (appenderString != "") {
out.println(catKey + "=" + appenderString);
}
if (!cat.getAdditivity() && cat != Logger.getRootLogger()) {
out.println("log4j.additivity." + cat.getName() + "=false");
}
}
示例4: RemoteLoggingConfigurator
import org.apache.log4j.Category; //導入方法依賴的package包/類
/**
* Constructor - when created try to find if a DB appender has been configured on the local system
*/
@SuppressWarnings( "unchecked")
public RemoteLoggingConfigurator( String atsAgent ) {
/*
* This code is run on:
* - Test Executor side prior to calling an agent for first time in this testcase
* - Agent side prior to calling another chained agent for first time in this testcase
*
* we use this code to remember the logging configuration which we will pass to some agent
*/
this.atsAgent = atsAgent;
// look for the DB appender
Category log = Logger.getLogger("com.axway.ats");
boolean dbAppenderIsProcessed = false;
while (log != null && !dbAppenderIsProcessed) {
Enumeration<Appender> appenders = log.getAllAppenders();
while (appenders.hasMoreElements()) {
Appender appender = appenders.nextElement();
if (appender.getClass() == ActiveDbAppender.class // running on Test Executor side
|| appender.getClass() == PassiveDbAppender.class // running on Agent side
) {
//we found the appender, read all properties
appenderConfiguration = ((AbstractDbAppender) appender).getAppenderConfig();
appenderLogger = log.getName();
int atsDbLogLevel = DEFAULT_LOG_LEVEL;
if (atsDbLoggerLevelsFromTests.containsKey(this.atsAgent)) {
// user specified in the test the log level for this agent
atsDbLogLevel = atsDbLoggerLevelsFromTests.get(this.atsAgent).toInt();
} else if (log.getLevel() != null) {
// user specified the log level in log4j configuration file
atsDbLogLevel = log.getLevel().toInt();
}
//set the effective logging level for threshold if new one is set
if (appenderConfiguration.getLoggingThreshold() == null
|| appenderConfiguration.getLoggingThreshold().toInt() != atsDbLogLevel) {
/*
* Log4j is deprecating the Priority class used by setLoggingThreshold,
* but we cannot make an instance of this class as its constructor is not public.
*
* So here we first change the log level on the Test Executor,
* then get the Priority object, then restore back the value on the Test Executor
*/
final Level currentLevelBackup = log.getLevel();
log.setLevel(Level.toLevel(atsDbLogLevel));
appenderConfiguration.setLoggingThreshold(log.getEffectiveLevel());
log.setLevel(currentLevelBackup);
}
//exit the loop
dbAppenderIsProcessed = true;
break;
}
}
log = log.getParent();
}
// look for any user loggers
Enumeration<Logger> allLoggers = Logger.getRootLogger().getLoggerRepository().getCurrentLoggers();
while (allLoggers.hasMoreElements()) {
Logger logger = allLoggers.nextElement();
Level level = logger.getLevel();
if (level != null) {
// user explicitly specified a level for this logger
otherLoggerLevels.put(logger.getName(), level.toInt());
}
}
}