org.jboss.logmanager.Logger类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(219)

本文整理了Java中org.jboss.logmanager.Logger类的一些代码示例,展示了Logger类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Logger类的具体详情如下:
包路径:org.jboss.logmanager.Logger
类名称:Logger

Logger介绍

[英]An actual logger instance. This is the end-user interface into the logging system.
[中]一个实际的记录器实例。这是登录系统的最终用户界面。

代码示例

代码示例来源:origin: wildfly/wildfly

  1. private static Logger doLegacyGetLogger(final String name) {
  2. final org.jboss.logmanager.Logger lmLogger = LogContext.getLogContext().getLogger("");
  3. ConcurrentMap<String, Logger> loggers = lmLogger.getAttachment(LEGACY_KEY);
  4. if (loggers == null) {
  5. loggers = new ConcurrentHashMap<String, Logger>();
  6. final ConcurrentMap<String, Logger> appearing = lmLogger.attachIfAbsent(LEGACY_KEY, loggers);
  7. if (appearing != null) {
  8. loggers = appearing;
  9. }
  10. }
  11. Logger l = loggers.get(name);
  12. if (l != null) {
  13. return l;
  14. }
  15. final org.jboss.logmanager.Logger logger = org.jboss.logmanager.Logger.getLogger(name);
  16. l = new JBossLogManagerLogger(name, logger);
  17. final Logger appearing = loggers.putIfAbsent(name, l);
  18. if (appearing == null) {
  19. return l;
  20. }
  21. return appearing;
  22. }

代码示例来源:origin: wildfly/wildfly

  1. protected void doLog(final Level level, final String loggerClassName, final Object message, final Object[] parameters, final Throwable thrown) {
  2. java.util.logging.Level translatedLevel = translate(level);
  3. if (logger.isLoggable(translatedLevel)) {
  4. if (parameters == null) {
  5. logger.log(loggerClassName, translatedLevel, String.valueOf(message), thrown);
  6. } else {
  7. logger.log(loggerClassName, translatedLevel, String.valueOf(message), ExtLogRecord.FormatStyle.MESSAGE_FORMAT, parameters, thrown);
  8. }
  9. }
  10. }

代码示例来源:origin: wildfly/wildfly

  1. private static Logger doGetLogger(final String name) {
  2. Logger l = LogContext.getLogContext().getAttachment(name, KEY);
  3. if (l != null) {
  4. return l;
  5. }
  6. final org.jboss.logmanager.Logger logger = org.jboss.logmanager.Logger.getLogger(name);
  7. l = new JBossLogManagerLogger(name, logger);
  8. Logger a = logger.attachIfAbsent(KEY, l);
  9. if (a == null) {
  10. return l;
  11. } else {
  12. return a;
  13. }
  14. }

代码示例来源:origin: wildfly/wildfly-core

  1. private static void clearLogContext() {
  2. // Remove the configurator and clear the log context
  3. final Configurator configurator = EMBEDDED_LOG_CONTEXT.getLogger("").detach(Configurator.ATTACHMENT_KEY);
  4. // If this was a PropertyConfigurator we can use the LogContextConfiguration API to tear down the LogContext
  5. if (configurator instanceof PropertyConfigurator) {
  6. final LogContextConfiguration logContextConfiguration = ((PropertyConfigurator) configurator).getLogContextConfiguration();
  7. clearLogContext(logContextConfiguration);
  8. } else if (configurator instanceof LogContextConfiguration) {
  9. clearLogContext((LogContextConfiguration) configurator);
  10. } else {
  11. // Remove all the handlers and close them as well as reset the loggers
  12. final List<String> loggerNames = Collections.list(EMBEDDED_LOG_CONTEXT.getLoggerNames());
  13. for (String name : loggerNames) {
  14. final Logger logger = EMBEDDED_LOG_CONTEXT.getLoggerIfExists(name);
  15. if (logger != null) {
  16. final Handler[] handlers = logger.clearHandlers();
  17. if (handlers != null) {
  18. for (Handler handler : handlers) {
  19. handler.close();
  20. }
  21. }
  22. logger.setFilter(null);
  23. logger.setUseParentFilters(false);
  24. logger.setUseParentHandlers(true);
  25. logger.setLevel(Level.INFO);
  26. }
  27. }
  28. }
  29. }

代码示例来源:origin: org.wildfly.core/wildfly-logging

  1. public LogContextStdioContextSelector(final StdioContext defaultContext) {
  2. // Register the STDIO context on the default log context
  3. LogContext.getLogContext().getLogger(CommonAttributes.ROOT_LOGGER_NAME).attachIfAbsent(STDIO_CONTEXT_ATTACHMENT_KEY, defaultContext);
  4. }

代码示例来源:origin: org.jboss.logmanager/commons-logging-jboss-logmanager

  1. private Map<String, Object> getAttributeMap() {
  2. final Logger rootLogger = Logger.getLogger("");
  3. Map<String, Object> map = rootLogger.getAttachment(ATTRIBUTE_KEY);
  4. if (map == null) {
  5. map = Collections.synchronizedMap(new HashMap<String, Object>());
  6. final Map<String, Object> appearing = rootLogger.attachIfAbsent(ATTRIBUTE_KEY, map);
  7. if (appearing != null) {
  8. map = appearing;
  9. }
  10. }
  11. return map;
  12. }
  13. }

代码示例来源:origin: org.jboss.slf4j/slf4j-jboss-logmanager

  1. public Logger getLogger(final String name) {
  2. final org.jboss.logmanager.Logger lmLogger = LogContext.getLogContext().getLogger(name);
  3. final Logger logger = lmLogger.getAttachment(key);
  4. if (logger != null) {
  5. return logger;
  6. }
  7. return doPrivileged(new PrivilegedAction<Logger>() {
  8. public Logger run() {
  9. final Slf4jLogger newLogger = new Slf4jLogger(lmLogger);
  10. final Logger appearingLogger = lmLogger.attachIfAbsent(key, newLogger);
  11. return appearingLogger != null ? appearingLogger : newLogger;
  12. }
  13. });
  14. }
  15. }

代码示例来源:origin: org.jboss.logmanager/log4j-jboss-logmanager

  1. @Override
  2. public Hierarchy run() {
  3. final LogContext lc = logContext == null ? LogContext.getLogContext() : logContext;
  4. final org.jboss.logmanager.Logger jbossRoot = getJBossLogger(lc, JBL_ROOT_NAME);
  5. Hierarchy hierarchy = jbossRoot.getAttachment(HIERARCHY_KEY);
  6. if (hierarchy == null) {
  7. // Always attach the root logger
  8. Logger root = jbossRoot.getAttachment(LOGGER_KEY);
  9. if (root == null) {
  10. root = new RootLogger(JBossLevelMapping.getPriorityFor(jbossRoot.getLevel()));
  11. final Logger appearing = jbossRoot.attachIfAbsent(LOGGER_KEY, root);
  12. if (appearing != null) {
  13. root = appearing;
  14. }
  15. }
  16. hierarchy = new Hierarchy(root);
  17. final Hierarchy appearing = jbossRoot.attachIfAbsent(HIERARCHY_KEY, hierarchy);
  18. if (appearing != null) {
  19. hierarchy = appearing;
  20. }
  21. }
  22. return hierarchy;
  23. }
  24. });

代码示例来源:origin: org.jboss.as/jboss-as-logging

  1. /**
  2. * Gets the property configurator. If the {@link ConfigurationPersistence} does not exist a new one is created.
  3. *
  4. * @param logContext the log context used to find the property configurator or to attach it to.
  5. *
  6. * @return the property configurator
  7. */
  8. public static ConfigurationPersistence getOrCreateConfigurationPersistence(final LogContext logContext) {
  9. final Logger root = logContext.getLogger(CommonAttributes.ROOT_LOGGER_NAME);
  10. ConfigurationPersistence result = (ConfigurationPersistence) root.getAttachment(Configurator.ATTACHMENT_KEY);
  11. if (result == null) {
  12. result = new ConfigurationPersistence(logContext);
  13. ConfigurationPersistence existing = (ConfigurationPersistence) root.attachIfAbsent(Configurator.ATTACHMENT_KEY, result);
  14. if (existing != null) {
  15. result = existing;
  16. }
  17. }
  18. return result;
  19. }

代码示例来源:origin: wildfly/wildfly

  1. public boolean isEnabled(final Level level) {
  2. return logger.isLoggable(translate(level));
  3. }

代码示例来源:origin: apache/activemq-artemis

  1. @Test
  2. public void testMultipleConcurrentDurableSubscribers() throws Exception {
  3. org.jboss.logmanager.Logger.getLogger(StompConnection.class.getName()).setLevel(org.jboss.logmanager.Level.TRACE);
  4. int NUMBER_OF_THREADS = 25;
  5. SubscriberThread[] threads = new SubscriberThread[NUMBER_OF_THREADS];
  6. final CountDownLatch startFlag = new CountDownLatch(1);
  7. final CountDownLatch alignFlag = new CountDownLatch(NUMBER_OF_THREADS);
  8. for (int i = 0; i < threads.length; i++) {
  9. threads[i] = new SubscriberThread("subscriber::" + i, StompClientConnectionFactory.createClientConnection(uri), startFlag, alignFlag);
  10. }
  11. for (SubscriberThread t : threads) {
  12. t.start();
  13. }
  14. alignFlag.await();
  15. startFlag.countDown();
  16. for (SubscriberThread t : threads) {
  17. t.join();
  18. Assert.assertEquals(0, t.errors.get());
  19. }
  20. }

代码示例来源:origin: wildfly/wildfly

  1. protected void doLogf(final Level level, final String loggerClassName, final String format, final Object[] parameters, final Throwable thrown) {
  2. if (parameters == null) {
  3. logger.log(loggerClassName, translate(level), format, thrown);
  4. } else {
  5. logger.log(loggerClassName, translate(level), format, ExtLogRecord.FormatStyle.PRINTF, parameters, thrown);
  6. }
  7. }

代码示例来源:origin: apache/activemq-artemis

  1. private LogContextConfiguration getOrCreateConfiguration(final org.jboss.logmanager.Logger rootLogger) {
  2. Configurator configurator = rootLogger.getAttachment(Configurator.ATTACHMENT_KEY);
  3. if (configurator == null) {
  4. configurator = new PropertyConfigurator(rootLogger.getLogContext());
  5. final Configurator appearing = rootLogger.attachIfAbsent(Configurator.ATTACHMENT_KEY, configurator);
  6. if (appearing != null) {
  7. configurator = appearing;
  8. }
  9. }
  10. if (configurator instanceof PropertyConfigurator) {
  11. return ((PropertyConfigurator) configurator).getLogContextConfiguration();
  12. }
  13. if (configurator instanceof LogContextConfiguration) {
  14. return (LogContextConfiguration) configurator;
  15. }
  16. return null;
  17. }
  18. }

代码示例来源:origin: org.jboss.logging/jboss-logging-logmanager

  1. public LoggerPluginInstance getInstance(String name, String resourceBundleName) {
  2. Logger logger = resourceBundleName == null ? Logger.getLogger(name) : Logger.getLogger(name, resourceBundleName);
  3. LoggerPluginInstance lpi = logger.getAttachment(KEY);
  4. if (lpi == null) {
  5. final SecurityManager sm = System.getSecurityManager();
  6. lpi = new LoggerPluginInstanceImpl(name, resourceBundleName, logger, this);
  7. if (sm != null) {
  8. return AccessController.doPrivileged(new AttachAction(logger, lpi));
  9. } else {
  10. return doAttach(logger, lpi);
  11. }
  12. }
  13. return lpi;
  14. }

代码示例来源:origin: org.jboss.logmanager/log4j-jboss-logmanager

  1. static CopyOnWriteArrayList<Appender> getAppenderList(final Logger logger) {
  2. CopyOnWriteArrayList<Appender> result = logger.getAttachment(APPENDERS_KEY);
  3. if (result == null) {
  4. result = new CopyOnWriteArrayList<Appender>();
  5. final CopyOnWriteArrayList<Appender> current;
  6. if (System.getSecurityManager() == null) {
  7. current = logger.attachIfAbsent(APPENDERS_KEY, result);
  8. } else {
  9. final CopyOnWriteArrayList<Appender> attachment = result;
  10. current = AccessController.doPrivileged(new PrivilegedAction<CopyOnWriteArrayList<Appender>>() {
  11. @Override
  12. public CopyOnWriteArrayList<Appender> run() {
  13. return logger.attachIfAbsent(APPENDERS_KEY, attachment);
  14. }
  15. });
  16. }
  17. if (current != null) {
  18. result = current;
  19. }
  20. }
  21. return result;
  22. }
  23. }

代码示例来源:origin: org.jboss.logging/jboss-logging-logmanager

  1. private static LoggerPluginInstance doAttach(final Logger logger, final LoggerPluginInstance attachment) {
  2. LoggerPluginInstance appeared = logger.attachIfAbsent(KEY, attachment);
  3. if (appeared != null) {
  4. return appeared;
  5. }
  6. return attachment;
  7. }
  8. }

代码示例来源:origin: org.jboss.logmanager/commons-logging-jboss-logmanager

  1. private void log(final Level level, final Object message, final Throwable t) {
  2. final String msg = String.valueOf(message);
  3. final ExtLogRecord record = new ExtLogRecord(level, msg, LOGGER_CLASS_NAME);
  4. record.setThrown(t);
  5. delegate.log(record);
  6. }

代码示例来源:origin: org.jboss.logmanager/jboss-logmanager

  1. public void applyPostCreate(final Void param) {
  2. if (refLogger != null) {
  3. refLogger.setFilter(null);
  4. refLogger.clearHandlers();
  5. refLogger.setLevel(null);
  6. refLogger.setUseParentHandlers(true);
  7. }
  8. }

代码示例来源:origin: org.jboss.logmanager/log4j-jboss-logmanager

  1. @Override
  2. public T run() {
  3. return logger.getAttachment(key);
  4. }
  5. });

代码示例来源:origin: org.jboss.logmanager/jboss-logmanager

  1. @SuppressWarnings({"unchecked"})
  2. public void rollback() {
  3. if (refLogger != null) {
  4. refLogger.setFilter(filter);
  5. if (handlers != null) refLogger.setHandlers(handlers);
  6. refLogger.setLevel(level);
  7. refLogger.setUseParentHandlers(useParentHandlers);
  8. configs.put(name, LoggerConfigurationImpl.this);
  9. }
  10. clearRemoved();
  11. }
  12. };

相关文章