Java Code Examples for org.apache.log4j.LogManager#getCurrentLoggers()
The following examples show how to use
org.apache.log4j.LogManager#getCurrentLoggers() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaskLog.java From hadoop-gpu with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public synchronized static void syncLogs(TaskAttemptID firstTaskid, 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(firstTaskid); } writeToIndexFile(firstTaskid, isCleanup); }
Example 2
Source File: AdminService.java From zeppelin with Apache License 2.0 | 6 votes |
public List<org.apache.log4j.Logger> getLoggers() { Enumeration loggers = LogManager.getCurrentLoggers(); return StreamSupport.stream( Spliterators.spliteratorUnknownSize( new Iterator<org.apache.log4j.Logger>() { @Override public boolean hasNext() { return loggers.hasMoreElements(); } @Override public org.apache.log4j.Logger next() { return org.apache.log4j.Logger.class.cast(loggers.nextElement()); } }, Spliterator.ORDERED), false) .collect(Collectors.toList()); }
Example 3
Source File: TaskLog.java From big-c with Apache License 2.0 | 6 votes |
@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); }
Example 4
Source File: TaskLog.java From hadoop with Apache License 2.0 | 6 votes |
@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); }
Example 5
Source File: LoggersApiDelegate.java From ballerina-message-broker with Apache License 2.0 | 6 votes |
public Response getFilteredLoggers(Subject subject, String name) { try { authHandler.handle(ResourceAuthScope.LOGGERS_GET, subject); List<LoggerMetadata> loggerArray = new ArrayList<>(); Pattern namePatten = Pattern.compile(name.replaceAll("\\*", ".*")); Enumeration loggers = LogManager.getCurrentLoggers(); while (loggers.hasMoreElements()) { Logger logger = (Logger) loggers.nextElement(); if (namePatten.matcher(logger.getName()).matches()) { loggerArray.add(toLoggerMetadata(logger)); } } return Response.ok().entity(loggerArray).build(); } catch (AuthException e) { throw new NotAuthorizedException(e.getMessage(), e); } }
Example 6
Source File: LoggersApiDelegate.java From ballerina-message-broker with Apache License 2.0 | 5 votes |
public Response getLoggers(Subject subject) { try { authHandler.handle(ResourceAuthScope.LOGGERS_GET, subject); List<LoggerMetadata> loggerArray = new ArrayList<>(); Enumeration loggers = LogManager.getCurrentLoggers(); while (loggers.hasMoreElements()) { loggerArray.add(toLoggerMetadata((Logger) loggers.nextElement())); } return Response.ok().entity(loggerArray).build(); } catch (AuthException e) { throw new NotAuthorizedException(e.getMessage(), e); } }
Example 7
Source File: MessageLogFilter.java From unitime with Apache License 2.0 | 5 votes |
@Override public void destroy() { for (Enumeration e = LogManager.getCurrentLoggers(); e.hasMoreElements(); ) { Logger logger = (Logger)e.nextElement(); logger.removeAppender("mlog"); } LogManager.getRootLogger().removeAppender("mlog"); }
Example 8
Source File: Log4jLevelSetter.java From summerframework with Apache License 2.0 | 5 votes |
@Override public void setLoggerLevel(String name, String level) { Enumeration enumeration = LogManager.getCurrentLoggers(); while (enumeration.hasMoreElements()) { org.apache.log4j.Logger logger = (org.apache.log4j.Logger)enumeration.nextElement(); if (name.equals(logger.getName())) { logger.setLevel(org.apache.log4j.Level.toLevel(level)); } } }
Example 9
Source File: TaskLog.java From RDFS with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public synchronized static void syncLogs(TaskAttemptID firstTaskid, 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(); } } } // set start and end for (LogName logName : LOGS_TRACKED_BY_INDEX_FILES) { if (currentTaskid != taskid) { // Set start = current-end logLengths.get(logName)[0] = Long.valueOf(getTaskLogFile(firstTaskid, logName).length()); } // Set current end logLengths.get(logName)[1] = Long.valueOf(getTaskLogFile(firstTaskid, logName).length()); } if (currentTaskid != taskid) { if (currentTaskid != null) { LOG.info("Starting logging for a new task " + taskid + " in the same JVM as that of the first task " + firstTaskid); } currentTaskid = taskid; } writeToIndexFile(firstTaskid, taskid, isCleanup, logLengths); }
Example 10
Source File: OpenCypherGremlinDatabase.java From jetbrains-plugin-graph-database-support with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private static void disableGremlinLog() { final String gremlinDriver = "org.apache.tinkerpop.gremlin.driver"; Properties props = new Properties(); props.setProperty("log4j.logger." + gremlinDriver, Level.OFF.toString()); PropertyConfigurator.configure(props); Enumeration<Logger> loggers = LogManager.getCurrentLoggers(); Collections.list(loggers) .stream() .filter(logger -> logger.getName().startsWith(gremlinDriver)) .forEach(logger -> logger.setLevel(Level.OFF)); }
Example 11
Source File: PropertyPrinter.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Prints the configuration of the default log4j hierarchy as a Java * properties file on the specified Writer. * * <p>N.B. print() can be invoked only once! */ public void print(PrintWriter out) { printOptions(out, Logger.getRootLogger()); Enumeration cats = LogManager.getCurrentLoggers(); while (cats.hasMoreElements()) { printOptions(out, (Logger) cats.nextElement()); } }
Example 12
Source File: LoggerUtil.java From attic-apex-core with Apache License 2.0 | 5 votes |
public static synchronized ImmutableMap<String, String> getClassesMatching(@Nonnull String searchKey) { Pattern searchPattern = Pattern.compile(searchKey); Map<String, String> matchedClasses = Maps.newHashMap(); @SuppressWarnings("unchecked") Enumeration<Logger> loggerEnumeration = LogManager.getCurrentLoggers(); while (loggerEnumeration.hasMoreElements()) { Logger logger = loggerEnumeration.nextElement(); if (searchPattern.matcher(logger.getName()).matches()) { Level level = logger.getLevel(); matchedClasses.put(logger.getName(), level == null ? "" : level.toString()); } } return ImmutableMap.copyOf(matchedClasses); }
Example 13
Source File: Util.java From database with GNU General Public License v2.0 | 5 votes |
/** Checks whether Log4J is properly configuring by searching for appenders in all loggers. * * @return whether Log4J is configured (or, at least, an educated guess). */ public static boolean log4JIsConfigured() { if ( Logger.getRootLogger().getAllAppenders().hasMoreElements() ) return true; Enumeration<?> loggers = LogManager.getCurrentLoggers(); while ( loggers.hasMoreElements() ) { Logger logger = (Logger)loggers.nextElement(); if ( logger.getAllAppenders().hasMoreElements() ) return true; } return false; }
Example 14
Source File: Loggers.java From unitime with Apache License 2.0 | 5 votes |
@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; }
Example 15
Source File: Log4jContainer.java From dubbox with Apache License 2.0 | 4 votes |
@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(); } } } } } } }
Example 16
Source File: Log4jContainer.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
@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(); } } } } } } }
Example 17
Source File: Log4jContainer.java From dubbox with Apache License 2.0 | 4 votes |
@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(); } } } } } } }
Example 18
Source File: LoggerUtil.java From attic-apex-core with Apache License 2.0 | 4 votes |
public static synchronized void changeLoggersLevel(@Nonnull Map<String, String> targetChanges) { /* remove existing patterns which are subsets of new patterns. for eg. if x.y.z.* will be removed if * there is x.y.* in the target changes. */ for (Map.Entry<String, String> changeEntry : targetChanges.entrySet()) { Iterator<Map.Entry<String, Pattern>> patternsIterator = patterns.entrySet().iterator(); while ((patternsIterator.hasNext())) { Map.Entry<String, Pattern> entry = patternsIterator.next(); String finer = entry.getKey(); String wider = changeEntry.getKey(); if (finer.length() < wider.length()) { continue; } boolean remove = false; for (int i = 0; i < wider.length(); i++) { if (wider.charAt(i) == '*') { remove = true; break; } if (wider.charAt(i) != finer.charAt(i)) { break; } else if (i == wider.length() - 1) { remove = true; } } if (remove) { patternsIterator.remove(); patternLevel.remove(finer); } } } for (Map.Entry<String, String> loggerEntry : targetChanges.entrySet()) { String target = loggerEntry.getKey(); patternLevel.put(target, Level.toLevel(loggerEntry.getValue())); patterns.put(target, Pattern.compile(target)); } if (!patternLevel.isEmpty()) { @SuppressWarnings("unchecked") Enumeration<Logger> loggerEnumeration = LogManager.getCurrentLoggers(); while (loggerEnumeration.hasMoreElements()) { Logger classLogger = loggerEnumeration.nextElement(); Level oldLevel = classLogger.getLevel(); Level newLevel = getLevelFor(classLogger.getName()); if (newLevel != null && (oldLevel == null || !newLevel.equals(oldLevel))) { logger.info("changing level of {} to {}", classLogger.getName(), newLevel); classLogger.setLevel(newLevel); } } } }
Example 19
Source File: LoggerUtil.java From Bats with Apache License 2.0 | 4 votes |
public static synchronized void changeLoggersLevel(@Nonnull Map<String, String> targetChanges) { /* remove existing patterns which are subsets of new patterns. for eg. if x.y.z.* will be removed if * there is x.y.* in the target changes. */ for (Map.Entry<String, String> changeEntry : targetChanges.entrySet()) { Iterator<Map.Entry<String, Pattern>> patternsIterator = patterns.entrySet().iterator(); while ((patternsIterator.hasNext())) { Map.Entry<String, Pattern> entry = patternsIterator.next(); String finer = entry.getKey(); String wider = changeEntry.getKey(); if (finer.length() < wider.length()) { continue; } boolean remove = false; for (int i = 0; i < wider.length(); i++) { if (wider.charAt(i) == '*') { remove = true; break; } if (wider.charAt(i) != finer.charAt(i)) { break; } else if (i == wider.length() - 1) { remove = true; } } if (remove) { patternsIterator.remove(); patternLevel.remove(finer); } } } for (Map.Entry<String, String> loggerEntry : targetChanges.entrySet()) { String target = loggerEntry.getKey(); patternLevel.put(target, Level.toLevel(loggerEntry.getValue())); patterns.put(target, Pattern.compile(target)); } if (!patternLevel.isEmpty()) { @SuppressWarnings("unchecked") Enumeration<Logger> loggerEnumeration = LogManager.getCurrentLoggers(); while (loggerEnumeration.hasMoreElements()) { Logger classLogger = loggerEnumeration.nextElement(); Level oldLevel = classLogger.getLevel(); Level newLevel = getLevelFor(classLogger.getName()); if (newLevel != null && (oldLevel == null || !newLevel.equals(oldLevel))) { logger.info("changing level of {} to {}", classLogger.getName(), newLevel); classLogger.setLevel(newLevel); } } } }
Example 20
Source File: Log4jContainer.java From dubbox with Apache License 2.0 | 4 votes |
@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(); } } } } } } }