ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [14/24] incubator-ignite git commit: # ignite-788: core logger
Date Mon, 20 Jul 2015 14:55:17 GMT
# ignite-788: core logger


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/b75c24bb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/b75c24bb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/b75c24bb

Branch: refs/heads/ignite-788-last-review
Commit: b75c24bb53b3d4614b6c3fe400a2e6fafda32491
Parents: 708da7c
Author: ashutak <ashutak@gridgain.com>
Authored: Thu Jul 16 14:18:01 2015 +0300
Committer: ashutak <ashutak@gridgain.com>
Committed: Thu Jul 16 14:18:01 2015 +0300

----------------------------------------------------------------------
 .../ignite/logger/log4j2/Log4J2Logger.java      | 42 ++++++++++----------
 1 file changed, 20 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b75c24bb/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/Log4J2Logger.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/Log4J2Logger.java
b/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/Log4J2Logger.java
index 5ccbc04..a8b7a31 100644
--- a/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/Log4J2Logger.java
+++ b/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/Log4J2Logger.java
@@ -24,8 +24,8 @@ import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.lang.*;
 import org.apache.ignite.logger.*;
 import org.apache.logging.log4j.*;
-import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.*;
+import org.apache.logging.log4j.core.Logger;
 import org.apache.logging.log4j.core.appender.*;
 import org.apache.logging.log4j.core.appender.routing.*;
 import org.apache.logging.log4j.core.config.*;
@@ -70,10 +70,6 @@ import static org.apache.ignite.IgniteSystemProperties.*;
  */
 public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
     /** */
-    // TODO review.
-    public static final String LOGGER_NAME = LogManager.ROOT_LOGGER_NAME;
-
-    /** */
     public static final String NODE_ID = "nodeId";
 
     /** */
@@ -125,7 +121,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
      *      constructor.
      */
     public Log4J2Logger(boolean init) {
-        impl = LogManager.getRootLogger();
+        impl = (Logger)LogManager.getRootLogger();
 
         if (init) {
             // Implementation has already been inited, passing NULL.
@@ -178,9 +174,9 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
         addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() {
             @Override public Logger apply(Boolean init) {
                 if (init)
-                    Configurator.initialize(LOGGER_NAME, cfgUrl.toString());
+                    Configurator.initialize(LogManager.ROOT_LOGGER_NAME, cfgUrl.toString());
 
-                return LogManager.getRootLogger();
+                return (Logger)LogManager.getRootLogger();
             }
         });
 
@@ -205,9 +201,9 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
         addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() {
             @Override public Logger apply(Boolean init) {
                 if (init)
-                    Configurator.initialize(LOGGER_NAME, path);
+                    Configurator.initialize(LogManager.ROOT_LOGGER_NAME, path);
 
-                return LogManager.getRootLogger();
+                return (Logger)LogManager.getRootLogger();
             }
         });
 
@@ -229,9 +225,9 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
         addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() {
             @Override public Logger apply(Boolean init) {
                 if (init)
-                    Configurator.initialize(LOGGER_NAME, cfgUrl.toString());
+                    Configurator.initialize(LogManager.ROOT_LOGGER_NAME, cfgUrl.toString());
 
-                return LogManager.getRootLogger();
+                return (Logger)LogManager.getRootLogger();
             }
         });
 
@@ -245,7 +241,10 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware
{
      */
     // TODO review
     public static boolean isConfigured() {
-        return LogManager.getLogger(LOGGER_NAME) != null;
+        Logger log =
+            (Logger)LogManager.getLogger(LogManager.ROOT_LOGGER_NAME);
+
+        return !log.getAppenders().isEmpty();
     }
 
     /**
@@ -265,8 +264,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
 
     /** {@inheritDoc} */
     @Nullable @Override public String fileName() {
-        for (org.apache.logging.log4j.core.Logger log = (org.apache.logging.log4j.core.Logger)impl;
-            log != null; log = log.getParent()) {
+        for (Logger log = impl; log != null; log = log.getParent()) {
             for (Appender a : log.getAppenders().values()) {
                 if (a instanceof FileAppender)
                     return ((FileAppender)a).getFileName();
@@ -336,11 +334,11 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware
{
             boolean quiet = Boolean.valueOf(System.getProperty(IGNITE_QUIET, "true"));
 
             boolean consoleAppenderFound = false;
-            org.apache.logging.log4j.core.Logger rootLogger = null;
+            Logger rootLogger = null;
             ConsoleAppender errAppender = null;
 
             // TODO impl should be core logger.
-            for (org.apache.logging.log4j.core.Logger log = (org.apache.logging.log4j.core.Logger)impl;
log != null; ) {
+            for (Logger log = impl; log != null; ) {
                 if (!consoleAppenderFound) {
                     for (Appender appender : log.getAppenders().values()) {
                         if (appender instanceof ConsoleAppender) {
@@ -389,7 +387,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
                     rootLogger.addAppender(createConsoleAppender(Level.OFF));
 
                 if (logLevel != null)
-                    ((org.apache.logging.log4j.core.Logger)impl).setLevel(logLevel);
+                    impl.setLevel(logLevel);
             }
 
             quiet0 = quiet;
@@ -441,7 +439,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
         this.nodeId = nodeId;
 
         // Set nodeId as system variable to be used at configuration.
-        System.setProperty("nodeId", U.id8(nodeId));
+        System.setProperty(NODE_ID, U.id8(nodeId));
 
         ((LoggerContext) LogManager.getContext(false)).reconfigure();
 
@@ -466,12 +464,12 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware
{
      */
     @Override public Log4J2Logger getLogger(Object ctgr) {
         if (ctgr == null)
-            return new Log4J2Logger(LogManager.getRootLogger());
+            return new Log4J2Logger((Logger)LogManager.getRootLogger());
 
         if (ctgr instanceof Class)
-            return new Log4J2Logger(LogManager.getLogger(((Class<?>)ctgr).getName()));
+            return new Log4J2Logger((Logger)LogManager.getLogger(((Class<?>)ctgr).getName()));
 
-        return new Log4J2Logger(LogManager.getLogger(ctgr.toString()));
+        return new Log4J2Logger((Logger)LogManager.getLogger(ctgr.toString()));
     }
 
     /** {@inheritDoc} */


Mime
View raw message