ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [19/24] incubator-ignite git commit: # ignite-788: cosnole messages (works fine)
Date Mon, 20 Jul 2015 14:55:22 GMT
# ignite-788: cosnole messages (works fine)


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

Branch: refs/heads/ignite-788-last-review
Commit: f2264e0b36a8e5288b38f8da7932c6a9477b6bd4
Parents: 53b4e2a
Author: ashutak <ashutak@gridgain.com>
Authored: Fri Jul 17 19:52:56 2015 +0300
Committer: ashutak <ashutak@gridgain.com>
Committed: Fri Jul 17 19:52:56 2015 +0300

----------------------------------------------------------------------
 .../src/test/config/log4j2-verbose-test.xml     |  6 ++
 .../ignite/logger/log4j2/ContextTestTmp.java    | 81 ++------------------
 .../ignite/logger/log4j2/Log4J2Logger.java      | 30 +++++---
 3 files changed, 29 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f2264e0b/modules/core/src/test/config/log4j2-verbose-test.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/config/log4j2-verbose-test.xml b/modules/core/src/test/config/log4j2-verbose-test.xml
index 8abb07f..81df209 100644
--- a/modules/core/src/test/config/log4j2-verbose-test.xml
+++ b/modules/core/src/test/config/log4j2-verbose-test.xml
@@ -19,6 +19,11 @@
 
 <Configuration>
     <Appenders>
+        <Console name="CONSOLE_ERR" target="SYSTEM_ERR">
+            <PatternLayout pattern="[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n"/>
+            <ThresholdFilter level="OFF" onMatch="DENY" onMismatch="ACCEPT"/>
+        </Console>
+
         <Routing name="FILE">
             <Routes pattern="$${sys:nodeId}">
                 <Route>
@@ -37,6 +42,7 @@
 
     <Loggers>
         <Root level="INFO">
+            <AppenderRef ref="CONSOLE_ERR" level="INFO"/>
             <AppenderRef ref="FILE" level="DEBUG"/>
         </Root>
     </Loggers>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f2264e0b/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/ContextTestTmp.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/ContextTestTmp.java
b/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/ContextTestTmp.java
index cb91303..b4c9eb2 100644
--- a/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/ContextTestTmp.java
+++ b/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/ContextTestTmp.java
@@ -19,14 +19,8 @@ package org.apache.ignite.logger.log4j2;
 
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.logging.log4j.*;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.*;
-import org.apache.logging.log4j.core.appender.*;
-import org.apache.logging.log4j.core.config.*;
-import org.apache.logging.log4j.core.layout.*;
 
 import java.net.*;
-import java.nio.charset.*;
 
 /**
  * TODO: Add class description.
@@ -41,56 +35,13 @@ public class ContextTestTmp {
 
         final URL cfgUrl = U.resolveIgniteUrl("modules/core/src/test/config/log4j2-verbose-test.xml");
 
-        String loggerName = LogManager.ROOT_LOGGER_NAME;
-
-        Configurator.initialize(loggerName, cfgUrl.toString());
-
-        LoggerContext context= (LoggerContext) LogManager.getContext();
-        Configuration config= context.getConfiguration();
-
-        PatternLayout layout= PatternLayout.createLayout("%m%n", null, null, Charset.defaultCharset(),false,false,null,null);
-        Appender appender=ConsoleAppender.createAppender(layout, null, null, "CONSOLE_APPENDER",
null, null);
-        appender.start();
-        AppenderRef ref= AppenderRef.createAppenderRef("CONSOLE_APPENDER",null,null);
-        AppenderRef[] refs = new AppenderRef[] {ref};
-        LoggerConfig loggerConfig= LoggerConfig.createLogger("false", Level.INFO,"CONSOLE_LOGGER","CONSOLE_LOGGER",refs,null,null,null);
-        loggerConfig.addAppender(appender,null,null);
-
-        config.addAppender(appender);
-        config.addLogger("CONSOLE_LOGGER", loggerConfig);
-        context.updateLoggers(config);
-
-        Logger logger=LogManager.getContext().getLogger("CONSOLE_LOGGER");
-        logger.info("HELLO_WORLD");
+        org.apache.logging.log4j.core.Logger logger = Log4J2Logger.createConsoleLogger(null,
null);
 
         logTest(logger);
-        logTest(LogManager.getRootLogger());
-
-        System.out.println("FInish");
-    }
-
-    private static void doIt(org.apache.logging.log4j.core.Logger log){
-        ConsoleAppender console = ConsoleAppender.createAppender(PatternLayout.createDefaultLayout(),
null,
-            "SYSTEM_OUT", "consoleApp", null, null);
-
-        final LoggerContext ctx = (LoggerContext)LogManager.getContext(false);
-
-        final Configuration cfg = ctx.getConfiguration();
-
-        console.start();
-
-        cfg.addAppender(console);
-
-        AppenderRef ref = AppenderRef.createAppenderRef("consoleApp", null, null);
 
-        LoggerConfig loggerConfig = LoggerConfig.createLogger("true", Level.ALL, LogManager.ROOT_LOGGER_NAME,
-            "true", new AppenderRef[] {ref}, null, cfg, null );
+        logTest(LogManager.getContext().getLogger(LogManager.ROOT_LOGGER_NAME));
 
-        loggerConfig.addAppender(console, null, null);
-
-        cfg.addLogger(LogManager.ROOT_LOGGER_NAME, loggerConfig);
-
-        ctx.updateLoggers();
+        logTest(LogManager.getContext().getLogger("Some_another_class"));
     }
 
     private static void logTest(Logger logger) {
@@ -102,30 +53,8 @@ public class ContextTestTmp {
         logger.log(Level.DEBUG, "*******************");
         logger.log(Level.TRACE, "*******************");
         logger.log(Level.ALL, "*******************");
-    }
-
-    private static void addConsoleAppender(final Logger logger, final Level maxLevel) {
-        ConsoleAppender appender = ConsoleAppender.createAppender(PatternLayout.createDefaultLayout(),
null,
-            "SYSTEM_OUT", CONSOLE_APPENDER, null, null);
-
-        final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
-
-        final Configuration cfg = ctx.getConfiguration();
-
-        appender.start();
-
-        cfg.addAppender(appender);
-
-        LoggerConfig loggerConfig = cfg.getLoggerConfig(logger.getName());
-
-        AppenderRef ref = AppenderRef.createAppenderRef(CONSOLE_APPENDER, maxLevel, null);
-
-        loggerConfig.getAppenderRefs().add(ref);
-
-        loggerConfig.addAppender(appender, maxLevel, null);
-
-        cfg.addLogger(logger.getName(), loggerConfig);
 
-        ctx.updateLoggers();
+        System.out.println();
+        System.out.println();
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f2264e0b/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 ef8e73a..4dc5e6f 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
@@ -75,6 +75,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
 
     /** */
     public static final String CONSOLE_APPENDER = "autoConfiguredIgniteConsoleAppender";
+    public static final String CONSOLE_LOGGER_NAME = LogManager.ROOT_LOGGER_NAME;
 
     /** */
     private static volatile boolean inited;
@@ -319,14 +320,14 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware
{
                 // User launched ignite in verbose mode and did not add console appender
with INFO level
                 // to configuration and did not set IGNITE_CONSOLE_APPENDER to false.
                 if (errAppender != null) {
-                    consoleLogger = createConsoleLogger(rootLogger, Level.INFO);
+                    consoleLogger = createConsoleLogger(rootLogger, Level.ALL);
 
 //                    if (errAppender.getThreshold() == Level.ERROR)
 //                        errAppender.setThreshold(Level.WARN);
                 }
                 else
                     // No error console appender => create console appender with no level
limit.
-                    consoleLogger = createConsoleLogger(rootLogger, Level.ALL);
+                    consoleLogger = createConsoleLogger(rootLogger, Level.INFO);
             }
 
             quiet0 = quiet;
@@ -400,8 +401,10 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware
{
      * @return New console appender.
      */
     // TODO review.
-    private Logger createConsoleLogger(Logger log, Level maxLevel) {
-        LoggerContext context= (LoggerContext) LogManager.getContext();
+    public static Logger createConsoleLogger(Logger log, Level maxLevel) {
+//        ((Log4jContextFactory)LogManager.getFactory()).getSelector().
+
+        LoggerContext context= (LoggerContext) LogManager.getContext(true);
         Configuration config= context.getConfiguration();
 
         PatternLayout layout= PatternLayout.createLayout("[%d{ABSOLUTE}][%-5p][%t][%c{1}]
%m%n", null, null, Charset.defaultCharset(),false,false,null,null);
@@ -409,14 +412,14 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware
{
         appender.start();
         AppenderRef ref= AppenderRef.createAppenderRef("CONSOLE_APPENDER",null,null);
         AppenderRef[] refs = new AppenderRef[] {ref};
-        LoggerConfig loggerConfig= LoggerConfig.createLogger("false", Level.INFO,"CONSOLE_LOGGER","CONSOLE_LOGGER",refs,null,null,null);
+        LoggerConfig loggerConfig= LoggerConfig.createLogger("false", Level.INFO,CONSOLE_LOGGER_NAME,"",refs,null,null,null);
         loggerConfig.addAppender(appender,null,null);
 
         config.addAppender(appender);
-        config.addLogger("CONSOLE_LOGGER", loggerConfig);
+        config.addLogger(CONSOLE_LOGGER_NAME, loggerConfig);
         context.updateLoggers(config);
 
-        return  (Logger)LogManager.getContext().getLogger("CONSOLE_LOGGER");
+        return (Logger)LogManager.getContext().getLogger(CONSOLE_LOGGER_NAME);
     }
 
     /** {@inheritDoc} */
@@ -450,12 +453,15 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware
{
      */
     @Override public Log4J2Logger getLogger(Object ctgr) {
         if (ctgr == null)
-            return new Log4J2Logger((Logger)LogManager.getRootLogger(), (Logger)LogManager.getContext().getLogger("CONSOLE_LOGGER"));
+            return new Log4J2Logger((Logger)LogManager.getRootLogger(), (Logger)LogManager.getContext().getLogger(""));
 
-        if (ctgr instanceof Class)
-            return new Log4J2Logger((Logger)LogManager.getLogger(((Class<?>)ctgr).getName()),
(Logger)LogManager.getContext().getLogger("CONSOLE_LOGGER"));
+        if (ctgr instanceof Class) {
+            String name = ((Class<?>)ctgr).getName();
+            return new Log4J2Logger((Logger)LogManager.getLogger(name), (Logger)LogManager.getContext().getLogger(name));
+        }
 
-        return new Log4J2Logger((Logger)LogManager.getLogger(ctgr.toString()), (Logger)LogManager.getContext().getLogger("CONSOLE_LOGGER"));
+        String name = ctgr.toString();
+        return new Log4J2Logger((Logger)LogManager.getLogger(name), (Logger)LogManager.getContext().getLogger(name));
     }
 
     /** {@inheritDoc} */
@@ -490,7 +496,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
     /** {@inheritDoc} */
     @Override public void warning(String msg) {
         impl.warn(msg);
-        if (LogManager.getContext().getLogger("CONSOLE_LOGGER") != null) LogManager.getContext().getLogger("CONSOLE_LOGGER").warn(msg);
+        if (LogManager.getContext().getLogger(CONSOLE_LOGGER_NAME) != null) LogManager.getContext().getLogger(CONSOLE_LOGGER_NAME).warn(msg);
     }
 
     /** {@inheritDoc} */


Mime
View raw message