Refine search
private static Logger doLegacyGetLogger(final String name) { final org.jboss.logmanager.Logger lmLogger = LogContext.getLogContext().getLogger(""); ConcurrentMap<String, Logger> loggers = lmLogger.getAttachment(LEGACY_KEY); if (loggers == null) { loggers = new ConcurrentHashMap<String, Logger>(); final ConcurrentMap<String, Logger> appearing = lmLogger.attachIfAbsent(LEGACY_KEY, loggers); if (appearing != null) { loggers = appearing; } } Logger l = loggers.get(name); if (l != null) { return l; } final org.jboss.logmanager.Logger logger = org.jboss.logmanager.Logger.getLogger(name); l = new JBossLogManagerLogger(name, logger); final Logger appearing = loggers.putIfAbsent(name, l); if (appearing == null) { return l; } return appearing; }
protected void doLog(final Level level, final String loggerClassName, final Object message, final Object[] parameters, final Throwable thrown) { java.util.logging.Level translatedLevel = translate(level); if (logger.isLoggable(translatedLevel)) { if (parameters == null) { logger.log(loggerClassName, translatedLevel, String.valueOf(message), thrown); } else { logger.log(loggerClassName, translatedLevel, String.valueOf(message), ExtLogRecord.FormatStyle.MESSAGE_FORMAT, parameters, thrown); } } }
private static Logger doGetLogger(final String name) { Logger l = LogContext.getLogContext().getAttachment(name, KEY); if (l != null) { return l; } final org.jboss.logmanager.Logger logger = org.jboss.logmanager.Logger.getLogger(name); l = new JBossLogManagerLogger(name, logger); Logger a = logger.attachIfAbsent(KEY, l); if (a == null) { return l; } else { return a; } }
private static void clearLogContext() { // Remove the configurator and clear the log context final Configurator configurator = EMBEDDED_LOG_CONTEXT.getLogger("").detach(Configurator.ATTACHMENT_KEY); // If this was a PropertyConfigurator we can use the LogContextConfiguration API to tear down the LogContext if (configurator instanceof PropertyConfigurator) { final LogContextConfiguration logContextConfiguration = ((PropertyConfigurator) configurator).getLogContextConfiguration(); clearLogContext(logContextConfiguration); } else if (configurator instanceof LogContextConfiguration) { clearLogContext((LogContextConfiguration) configurator); } else { // Remove all the handlers and close them as well as reset the loggers final List<String> loggerNames = Collections.list(EMBEDDED_LOG_CONTEXT.getLoggerNames()); for (String name : loggerNames) { final Logger logger = EMBEDDED_LOG_CONTEXT.getLoggerIfExists(name); if (logger != null) { final Handler[] handlers = logger.clearHandlers(); if (handlers != null) { for (Handler handler : handlers) { handler.close(); } } logger.setFilter(null); logger.setUseParentFilters(false); logger.setUseParentHandlers(true); logger.setLevel(Level.INFO); } } } }
public LogContextStdioContextSelector(final StdioContext defaultContext) { // Register the STDIO context on the default log context LogContext.getLogContext().getLogger(CommonAttributes.ROOT_LOGGER_NAME).attachIfAbsent(STDIO_CONTEXT_ATTACHMENT_KEY, defaultContext); }
private Map<String, Object> getAttributeMap() { final Logger rootLogger = Logger.getLogger(""); Map<String, Object> map = rootLogger.getAttachment(ATTRIBUTE_KEY); if (map == null) { map = Collections.synchronizedMap(new HashMap<String, Object>()); final Map<String, Object> appearing = rootLogger.attachIfAbsent(ATTRIBUTE_KEY, map); if (appearing != null) { map = appearing; } } return map; } }
public Logger getLogger(final String name) { final org.jboss.logmanager.Logger lmLogger = LogContext.getLogContext().getLogger(name); final Logger logger = lmLogger.getAttachment(key); if (logger != null) { return logger; } return doPrivileged(new PrivilegedAction<Logger>() { public Logger run() { final Slf4jLogger newLogger = new Slf4jLogger(lmLogger); final Logger appearingLogger = lmLogger.attachIfAbsent(key, newLogger); return appearingLogger != null ? appearingLogger : newLogger; } }); } }
@Override public Hierarchy run() { final LogContext lc = logContext == null ? LogContext.getLogContext() : logContext; final org.jboss.logmanager.Logger jbossRoot = getJBossLogger(lc, JBL_ROOT_NAME); Hierarchy hierarchy = jbossRoot.getAttachment(HIERARCHY_KEY); if (hierarchy == null) { // Always attach the root logger Logger root = jbossRoot.getAttachment(LOGGER_KEY); if (root == null) { root = new RootLogger(JBossLevelMapping.getPriorityFor(jbossRoot.getLevel())); final Logger appearing = jbossRoot.attachIfAbsent(LOGGER_KEY, root); if (appearing != null) { root = appearing; } } hierarchy = new Hierarchy(root); final Hierarchy appearing = jbossRoot.attachIfAbsent(HIERARCHY_KEY, hierarchy); if (appearing != null) { hierarchy = appearing; } } return hierarchy; } });
/** * Gets the property configurator. If the {@link ConfigurationPersistence} does not exist a new one is created. * * @param logContext the log context used to find the property configurator or to attach it to. * * @return the property configurator */ public static ConfigurationPersistence getOrCreateConfigurationPersistence(final LogContext logContext) { final Logger root = logContext.getLogger(CommonAttributes.ROOT_LOGGER_NAME); ConfigurationPersistence result = (ConfigurationPersistence) root.getAttachment(Configurator.ATTACHMENT_KEY); if (result == null) { result = new ConfigurationPersistence(logContext); ConfigurationPersistence existing = (ConfigurationPersistence) root.attachIfAbsent(Configurator.ATTACHMENT_KEY, result); if (existing != null) { result = existing; } } return result; }
public boolean isEnabled(final Level level) { return logger.isLoggable(translate(level)); }
@Test public void testMultipleConcurrentDurableSubscribers() throws Exception { org.jboss.logmanager.Logger.getLogger(StompConnection.class.getName()).setLevel(org.jboss.logmanager.Level.TRACE); int NUMBER_OF_THREADS = 25; SubscriberThread[] threads = new SubscriberThread[NUMBER_OF_THREADS]; final CountDownLatch startFlag = new CountDownLatch(1); final CountDownLatch alignFlag = new CountDownLatch(NUMBER_OF_THREADS); for (int i = 0; i < threads.length; i++) { threads[i] = new SubscriberThread("subscriber::" + i, StompClientConnectionFactory.createClientConnection(uri), startFlag, alignFlag); } for (SubscriberThread t : threads) { t.start(); } alignFlag.await(); startFlag.countDown(); for (SubscriberThread t : threads) { t.join(); Assert.assertEquals(0, t.errors.get()); } }
protected void doLogf(final Level level, final String loggerClassName, final String format, final Object[] parameters, final Throwable thrown) { if (parameters == null) { logger.log(loggerClassName, translate(level), format, thrown); } else { logger.log(loggerClassName, translate(level), format, ExtLogRecord.FormatStyle.PRINTF, parameters, thrown); } }
private LogContextConfiguration getOrCreateConfiguration(final org.jboss.logmanager.Logger rootLogger) { Configurator configurator = rootLogger.getAttachment(Configurator.ATTACHMENT_KEY); if (configurator == null) { configurator = new PropertyConfigurator(rootLogger.getLogContext()); final Configurator appearing = rootLogger.attachIfAbsent(Configurator.ATTACHMENT_KEY, configurator); if (appearing != null) { configurator = appearing; } } if (configurator instanceof PropertyConfigurator) { return ((PropertyConfigurator) configurator).getLogContextConfiguration(); } if (configurator instanceof LogContextConfiguration) { return (LogContextConfiguration) configurator; } return null; } }
public LoggerPluginInstance getInstance(String name, String resourceBundleName) { Logger logger = resourceBundleName == null ? Logger.getLogger(name) : Logger.getLogger(name, resourceBundleName); LoggerPluginInstance lpi = logger.getAttachment(KEY); if (lpi == null) { final SecurityManager sm = System.getSecurityManager(); lpi = new LoggerPluginInstanceImpl(name, resourceBundleName, logger, this); if (sm != null) { return AccessController.doPrivileged(new AttachAction(logger, lpi)); } else { return doAttach(logger, lpi); } } return lpi; }
static CopyOnWriteArrayList<Appender> getAppenderList(final Logger logger) { CopyOnWriteArrayList<Appender> result = logger.getAttachment(APPENDERS_KEY); if (result == null) { result = new CopyOnWriteArrayList<Appender>(); final CopyOnWriteArrayList<Appender> current; if (System.getSecurityManager() == null) { current = logger.attachIfAbsent(APPENDERS_KEY, result); } else { final CopyOnWriteArrayList<Appender> attachment = result; current = AccessController.doPrivileged(new PrivilegedAction<CopyOnWriteArrayList<Appender>>() { @Override public CopyOnWriteArrayList<Appender> run() { return logger.attachIfAbsent(APPENDERS_KEY, attachment); } }); } if (current != null) { result = current; } } return result; } }
private static LoggerPluginInstance doAttach(final Logger logger, final LoggerPluginInstance attachment) { LoggerPluginInstance appeared = logger.attachIfAbsent(KEY, attachment); if (appeared != null) { return appeared; } return attachment; } }
private void log(final Level level, final Object message, final Throwable t) { final String msg = String.valueOf(message); final ExtLogRecord record = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME); record.setThrown(t); delegate.log(record); }
public void applyPostCreate(final Void param) { if (refLogger != null) { refLogger.setFilter(null); refLogger.clearHandlers(); refLogger.setLevel(null); refLogger.setUseParentHandlers(true); } }
@Override public T run() { return logger.getAttachment(key); } });
@SuppressWarnings({"unchecked"}) public void rollback() { if (refLogger != null) { refLogger.setFilter(filter); if (handlers != null) refLogger.setHandlers(handlers); refLogger.setLevel(level); refLogger.setUseParentHandlers(useParentHandlers); configs.put(name, LoggerConfigurationImpl.this); } clearRemoved(); } };