From a84006359081d7bf1d006a4790d3fbf5cc0e6842 Mon Sep 17 00:00:00 2001 From: Paul Gregoire Date: Thu, 23 Jun 2016 15:47:37 -0400 Subject: [PATCH] Fix for logger gets --- pom.xml | 2 +- .../org/red5/logging/Red5LoggerFactory.java | 52 ++++--------------- 2 files changed, 12 insertions(+), 42 deletions(-) diff --git a/pom.xml b/pom.xml index d8c0e123..9ee6be6f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.red5 red5-parent - 1.0.8-M2 + 1.0.8-M3 4.0.0 red5-server-common diff --git a/src/main/java/org/red5/logging/Red5LoggerFactory.java b/src/main/java/org/red5/logging/Red5LoggerFactory.java index 345e895e..b8437c33 100644 --- a/src/main/java/org/red5/logging/Red5LoggerFactory.java +++ b/src/main/java/org/red5/logging/Red5LoggerFactory.java @@ -42,6 +42,12 @@ public class Red5LoggerFactory { static { DEBUG = Boolean.valueOf(System.getProperty("logback.debug", "false")); + try { + Logger logger = LoggerFactory.getILoggerFactory().getLogger(Logger.ROOT_LOGGER_NAME); + logger.debug("Red5LoggerFactory instanced by Thread: {}", Thread.currentThread().getName()); + } catch (Throwable t) { + t.printStackTrace(); + } } public static Logger getLogger(Class clazz) { @@ -127,7 +133,8 @@ public static Logger getLogger(Class clazz) { } logger = Red5LoggerFactory.getLogger(clazz, contextName); */ - } else { + } + if (logger == null) { logger = LoggerFactory.getLogger(clazz); } return logger; @@ -135,41 +142,7 @@ public static Logger getLogger(Class clazz) { @SuppressWarnings({ "rawtypes" }) public static Logger getLogger(Class clazz, String contextName) { - if (DEBUG) { - System.out.printf("getLogger for: %s in context: %s thread: %s%n", clazz.getName(), contextName, Thread.currentThread().getName()); - } - Logger logger = null; - if (useLogback) { - // disallow null context names - if (contextName == null) { - contextName = CoreConstants.DEFAULT_CONTEXT_NAME; - } - try { - ContextSelector selector = Red5LoggerFactory.getContextSelector(); - // get the context for the given context name or default if null - LoggerContext context = selector.getLoggerContext(contextName); - // and if we get here, create context - if (context == null) { - System.err.printf("No context named %s was found!%n", contextName); - } - // get the logger from the context or default context - if (context != null) { - logger = context.getLogger(clazz); - //System.out.printf("Application name: %s in context: %s%n", context.getProperty(KEY_APP_NAME), contextName); - } - } catch (Exception e) { - // no logback, use whatever logger is in-place - System.err.printf("Exception %s%n", e.getMessage()); - e.printStackTrace(); - } - if (logger == null) { - // no logback, use whatever logger is in-place - logger = LoggerFactory.getILoggerFactory().getLogger(Logger.ROOT_LOGGER_NAME); - } - } else { - logger = LoggerFactory.getLogger(clazz); - } - return logger; + return getLogger(clazz.getName(), contextName); } public static Logger getLogger(String name, String contextName) { @@ -200,11 +173,8 @@ public static Logger getLogger(String name, String contextName) { System.err.printf("Exception %s%n", e.getMessage()); e.printStackTrace(); } - if (logger == null) { - // no logback, use whatever logger is in-place - logger = LoggerFactory.getILoggerFactory().getLogger(name); - } - } else { + } + if (logger == null) { logger = LoggerFactory.getLogger(name); } return logger;