本文整理汇总了Java中org.apache.log4j.LogManager.getCurrentLoggers方法的典型用法代码示例。如果您正苦于以下问题:Java LogManager.getCurrentLoggers方法的具体用法?Java LogManager.getCurrentLoggers怎么用?Java LogManager.getCurrentLoggers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.log4j.LogManager
的用法示例。
在下文中一共展示了LogManager.getCurrentLoggers方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isLog4JConfigured
import org.apache.log4j.LogManager; //导入方法依赖的package包/类
/**
* Returns true if it appears that log4j have been previously configured. This code checks to see if there are any appenders defined for log4j
* which is the definitive way to tell if log4j is already initialized. See http://wiki.apache.org/logging-log4j/UsefulCode
*
* @return true if Log4J is configured, false otherwise.
*/
private static boolean isLog4JConfigured() {
final Enumeration<?> appenders = Logger.getRootLogger().getAllAppenders();
if (appenders.hasMoreElements()) {
return true;
} else {
final Enumeration<?> loggers = LogManager.getCurrentLoggers();
while (loggers.hasMoreElements()) {
final Logger c = (Logger) loggers.nextElement();
if (c.getAllAppenders().hasMoreElements()) {
return true;
}
}
}
return false;
}
示例2: syncLogs
import org.apache.log4j.LogManager; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public synchronized static void syncLogs(String logLocation,
TaskAttemptID taskid,
boolean isCleanup)
throws IOException {
System.out.flush();
System.err.flush();
Enumeration<Logger> allLoggers = LogManager.getCurrentLoggers();
while (allLoggers.hasMoreElements()) {
Logger l = allLoggers.nextElement();
Enumeration<Appender> allAppenders = l.getAllAppenders();
while (allAppenders.hasMoreElements()) {
Appender a = allAppenders.nextElement();
if (a instanceof TaskLogAppender) {
((TaskLogAppender)a).flush();
}
}
}
if (currentTaskid != taskid) {
currentTaskid = taskid;
resetPrevLengths(logLocation);
}
writeToIndexFile(logLocation, isCleanup);
}
示例3: load
import org.apache.log4j.LogManager; //导入方法依赖的package包/类
@Override
@PreAuthorize("checkPermission('ApplicationConfig')")
public SimpleEditInterface load(SessionContext context, Session hibSession) {
List<ListItem> levels = new ArrayList<ListItem>();
levels.add(new ListItem(String.valueOf(Level.ALL_INT), MESSAGES.levelAll()));
levels.add(new ListItem(String.valueOf(Level.TRACE_INT), MESSAGES.levelTrace()));
levels.add(new ListItem(String.valueOf(Level.DEBUG_INT), MESSAGES.levelDebug()));
levels.add(new ListItem(String.valueOf(Level.INFO_INT), MESSAGES.levelInfo()));
levels.add(new ListItem(String.valueOf(Level.WARN_INT), MESSAGES.levelWarning()));
levels.add(new ListItem(String.valueOf(Level.ERROR_INT), MESSAGES.levelError()));
levels.add(new ListItem(String.valueOf(Level.FATAL_INT), MESSAGES.levelFatal()));
levels.add(new ListItem(String.valueOf(Level.OFF_INT), MESSAGES.levelOff()));
SimpleEditInterface data = new SimpleEditInterface(
new Field(MESSAGES.fieldLogger(), FieldType.text, 400, 1024, Flag.UNIQUE),
new Field(MESSAGES.fieldLevel(), FieldType.list, 100, levels, Flag.NOT_EMPTY));
data.setSortBy(0, 1);
long id = 0;
SimpleEditInterface.Record root = data.addRecord(id++, false);
root.setField(0, " root", false);
root.setField(1, String.valueOf(LogManager.getRootLogger().getLevel().toInt()));
for (Enumeration e = LogManager.getCurrentLoggers(); e.hasMoreElements(); ) {
Logger logger = (Logger)e.nextElement();
if (logger.getLevel() == null) continue;
ApplicationConfig config = ApplicationConfig.getConfig("log4j.logger." + logger.getName());
SimpleEditInterface.Record record = data.addRecord(id++, ApplicationProperties.getDefaultProperties().getProperty("log4j.logger." + logger.getName()) == null && config != null);
record.setField(0, logger.getName(), false);
record.setField(1, String.valueOf(logger.getLevel().toInt()));
}
data.setEditable(context.hasPermission(Right.ApplicationConfig));
return data;
}
示例4: destroy
import org.apache.log4j.LogManager; //导入方法依赖的package包/类
@Override
public void destroy() {
for (Enumeration e = LogManager.getCurrentLoggers(); e.hasMoreElements(); ) {
Logger logger = (Logger)e.nextElement();
logger.removeAppender("mlog");
}
LogManager.getRootLogger().removeAppender("mlog");
}
示例5: start
import org.apache.log4j.LogManager; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void start() {
String file = ConfigUtils.getProperty(LOG4J_FILE);
if (file != null && file.length() > 0) {
String level = ConfigUtils.getProperty(LOG4J_LEVEL);
if (level == null || level.length() == 0) {
level = DEFAULT_LOG4J_LEVEL;
}
Properties properties = new Properties();
properties.setProperty("log4j.rootLogger", level + ",application");
properties.setProperty("log4j.appender.application", "org.apache.log4j.DailyRollingFileAppender");
properties.setProperty("log4j.appender.application.File", file);
properties.setProperty("log4j.appender.application.Append", "true");
properties.setProperty("log4j.appender.application.DatePattern", "'.'yyyy-MM-dd");
properties.setProperty("log4j.appender.application.layout", "org.apache.log4j.PatternLayout");
properties.setProperty("log4j.appender.application.layout.ConversionPattern", "%d [%t] %-5p %C{6} (%F:%L) - %m%n");
PropertyConfigurator.configure(properties);
}
String subdirectory = ConfigUtils.getProperty(LOG4J_SUBDIRECTORY);
if (subdirectory != null && subdirectory.length() > 0) {
Enumeration<org.apache.log4j.Logger> ls = LogManager.getCurrentLoggers();
while (ls.hasMoreElements()) {
org.apache.log4j.Logger l = ls.nextElement();
if (l != null) {
Enumeration<Appender> as = l.getAllAppenders();
while (as.hasMoreElements()) {
Appender a = as.nextElement();
if (a instanceof FileAppender) {
FileAppender fa = (FileAppender)a;
String f = fa.getFile();
if (f != null && f.length() > 0) {
int i = f.replace('\\', '/').lastIndexOf('/');
String path;
if (i == -1) {
path = subdirectory;
} else {
path = f.substring(0, i);
if (! path.endsWith(subdirectory)) {
path = path + "/" + subdirectory;
}
f = f.substring(i + 1);
}
fa.setFile(path + "/" + f);
fa.activateOptions();
}
}
}
}
}
}
}