ignite-commits mailing list archives

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


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

Branch: refs/heads/ignite-788-last-review
Commit: a679ff966d60b8362a36c2a03db9d5e8d9368861
Parents: 992dc65
Author: ashutak <ashutak@gridgain.com>
Authored: Wed Jul 15 19:31:57 2015 +0300
Committer: ashutak <ashutak@gridgain.com>
Committed: Wed Jul 15 19:31:57 2015 +0300

----------------------------------------------------------------------
 config/ignite-log4j2.xml                        |  42 +++--
 .../log4j2/IgniteRollingFileAppender.java       | 162 -------------------
 .../ignite/logger/log4j2/Log4J2Logger.java      |  65 +-------
 .../ignite/logger/log4j2/Log4j2FileAware.java   |  32 ----
 .../logger/log4j2/Log4j2NodeIdFilePath.java     |  64 --------
 .../ignite/logger/log4j2/Log4j2TestTmp.java     |  41 ++---
 6 files changed, 55 insertions(+), 351 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a679ff96/config/ignite-log4j2.xml
----------------------------------------------------------------------
diff --git a/config/ignite-log4j2.xml b/config/ignite-log4j2.xml
index 08d9246..b24c57b 100644
--- a/config/ignite-log4j2.xml
+++ b/config/ignite-log4j2.xml
@@ -23,19 +23,33 @@
             <PatternLayout pattern="[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n"/>
         </Console>
 
-        <!--TODO-->
-        <!--<param name="MaxFileSize" value="10MB"/>-->
-        <!--<param name="MaxBackupIndex" value="10"/>-->
-        <IgniteRollingFile name="FILE" fileName="work/log/ignite-id2.log"
-                     filePattern="work/log/$${date:yyyy-MM}/ignite-%d{MM-dd-yyyy}-%i.log.gz">
-            <PatternLayout>
-                <pattern>[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n</pattern>
-            </PatternLayout>
-            <Policies>
-                <TimeBasedTriggeringPolicy />
-                <SizeBasedTriggeringPolicy size="250 MB"/>
-            </Policies>
-        </IgniteRollingFile>
+        <Routing name="Routing">
+            <Routes pattern="$${ctx:nodeId}">
+                <Route>
+                    <RollingFile name="Rolling-${ctx:nodeId}" fileName="work/log/ignite-${ctx:nodeId}.log"
+                                 filePattern="work/log/ignite-${ctx:nodeId}-%i-%d{yyyy-MM-dd}.log.gz">
+                        <PatternLayout pattern="[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n"/>
+                        <Policies>
+                            <TimeBasedTriggeringPolicy interval="6" modulate="true" />
+                            <SizeBasedTriggeringPolicy size="10 MB" />
+                        </Policies>
+                    </RollingFile>
+                </Route>
+
+                <!--
+                <Route key="$${ctx:nodeId}">
+                    <RollingFile name="Rolling-default" fileName="work/log/ignite-default.log"
+                                 filePattern="work/log/ignite-default-%i-%d{yyyy-MM-dd}.log.gz">
+                        <PatternLayout pattern="[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n"/>
+                        <Policies>
+                            <TimeBasedTriggeringPolicy interval="6" modulate="true" />
+                            <SizeBasedTriggeringPolicy size="10 MB" />
+                        </Policies>
+                    </RollingFile>
+                </Route>
+                 -->
+            </Routes>
+        </Routing>
     </Appenders>
 
     <Loggers>
@@ -47,7 +61,7 @@
 
         <Root level="INFO">
             <AppenderRef ref="CONSOLE_ERR"/>
-            <AppenderRef ref="FILE"/>
+            <AppenderRef ref="Routing"/>
         </Root>
     </Loggers>
 </Configuration>

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a679ff96/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/IgniteRollingFileAppender.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/IgniteRollingFileAppender.java
b/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/IgniteRollingFileAppender.java
deleted file mode 100644
index 75f967f..0000000
--- a/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/IgniteRollingFileAppender.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*      http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-package org.apache.ignite.logger.log4j2;
-
-import org.apache.ignite.lang.*;
-import org.apache.logging.log4j.core.*;
-import org.apache.logging.log4j.core.appender.*;
-import org.apache.logging.log4j.core.appender.rolling.*;
-import org.apache.logging.log4j.core.config.*;
-import org.apache.logging.log4j.core.config.plugins.*;
-
-import java.io.*;
-
-/**
-* TODO
-*/
-@Plugin(name = "IgniteRollingFile", category = "Core", elementType = "appender", printObject
= true)
-public final class IgniteRollingFileAppender implements Appender, Serializable, Log4j2FileAware
{
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** */
-    private volatile RollingFileAppender a;
-
-    /** */
-    private IgniteRollingFileAppender(RollingFileAppender a) {
-        this.a = a;
-    }
-
-    /**
-     * Create a RollingFileAppender.
-     * @param fileName The name of the file that is actively written to. (required).
-     * @param filePattern The pattern of the file name to use on rollover. (required).
-     * @param append If true, events are appended to the file. If false, the file
-     * is overwritten when opened. Defaults to "true"
-     * @param name The name of the Appender (required).
-     * @param bufferedIO When true, I/O will be buffered. Defaults to "true".
-     * @param bufferSizeStr buffer size for buffered IO (default is 8192).
-     * @param immediateFlush When true, events are immediately flushed. Defaults to "true".
-     * @param policy The triggering policy. (required).
-     * @param strategy The rollover strategy. Defaults to DefaultRolloverStrategy.
-     * @param layout The layout to use (defaults to the default PatternLayout).
-     * @param filter The Filter or null.
-     * @param ignore If {@code "true"} (default) exceptions encountered when appending events
are logged; otherwise
-     *               they are propagated to the caller.
-     * @param advertise "true" if the appender configuration should be advertised, "false"
otherwise.
-     * @param advertiseURI The advertised URI which can be used to retrieve the file contents.
-     * @param config The Configuration.
-     * @return A RollingFileAppender.
-     */
-    @PluginFactory
-    public static IgniteRollingFileAppender createAppender(
-        @PluginAttribute("fileName") final String fileName,
-        @PluginAttribute("filePattern") final String filePattern,
-        @PluginAttribute("append") final String append,
-        @PluginAttribute("name") final String name,
-        @PluginAttribute("bufferedIO") final String bufferedIO,
-        @PluginAttribute("bufferSize") final String bufferSizeStr,
-        @PluginAttribute("immediateFlush") final String immediateFlush,
-        @PluginElement("Policy") final TriggeringPolicy policy,
-        @PluginElement("Strategy") RolloverStrategy strategy,
-        @PluginElement("Layout") Layout<? extends Serializable> layout,
-        @PluginElement("Filter") final Filter filter,
-        @PluginAttribute("ignoreExceptions") final String ignore,
-        @PluginAttribute("advertise") final String advertise,
-        @PluginAttribute("advertiseURI") final String advertiseURI,
-        @PluginConfiguration final Configuration config) {
-
-        RollingFileAppender a = RollingFileAppender.createAppender(
-            fileName,
-            filePattern,
-            append,
-            name,
-            bufferedIO,
-            bufferSizeStr,
-            immediateFlush,
-            policy,
-            strategy,
-            layout,
-            filter,
-            ignore,
-            advertise,
-            advertiseURI,
-            config);
-
-        return new IgniteRollingFileAppender(a);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void append(LogEvent event) {
-        a.append(event);
-    }
-
-    /** {@inheritDoc} */
-    @Override public String getName() {
-        return a.getName();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Layout<? extends Serializable> getLayout() {
-        return a.getLayout();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean ignoreExceptions() {
-        return a.ignoreExceptions();
-    }
-
-    /** {@inheritDoc} */
-    @Override public ErrorHandler getHandler() {
-        return a.getHandler();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void setHandler(ErrorHandler handler) {
-        a.setHandler(handler);
-    }
-
-    /** {@inheritDoc} */
-    @Override public State getState() {
-        return a.getState();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void start() {
-        a.start();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void stop() {
-        a.stop();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isStarted() {
-        return a.isStarted();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isStopped() {
-        return a.isStopped();
-    }
-
-    @Override public void updateFilePath(IgniteClosure<String, String> filePathClos)
{
-        System.out.println();
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a679ff96/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 c6a4df1..0cfe485 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
@@ -18,7 +18,6 @@
 package org.apache.ignite.logger.log4j2;
 
 import org.apache.ignite.*;
-import org.apache.ignite.internal.util.*;
 import org.apache.ignite.internal.util.tostring.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
@@ -67,10 +66,9 @@ import static org.apache.ignite.IgniteSystemProperties.*;
  * logger in your task/job code. See {@link org.apache.ignite.resources.LoggerResource} annotation
about logger
  * injection.
  */
-public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware, Log4j2FileAware {
+public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware {
     public static final String LOGGER_NAME = "Log4J2Logger";
-    /** Appenders. */
-    private static Collection<FileAppender> fileAppenders = new GridConcurrentHashSet<>();
+    public static final String NODE_ID = "nodeId";
 
     /** */
     private static volatile boolean inited;
@@ -417,36 +415,16 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware,
Log4j2File
         return console;
     }
 
-    /**
-     * Adds file appender.
-     *
-     * @param a Appender.
-     */
-    public static void addAppender(FileAppender a) {
-        A.notNull(a, "a");
-
-        fileAppenders.add(a);
-    }
-
-    /**
-     * Removes file appender.
-     *
-     * @param a Appender.
-     */
-    public static void removeAppender(FileAppender a) {
-        A.notNull(a, "a");
-
-        fileAppenders.remove(a);
-    }
-
     /** {@inheritDoc} */
     @Override public void setNodeId(UUID nodeId) {
         A.notNull(nodeId, "nodeId");
 
         this.nodeId = nodeId;
 
-        // TODO implement
-        updateFilePath(new Log4j2NodeIdFilePath(nodeId));
+        // Set nodeId at context to be used at configuration.
+        ThreadContext.put(NODE_ID, U.id8(nodeId));
+
+        ((LoggerContext) LogManager.getContext(false)).reconfigure();
     }
 
     /** {@inheritDoc} */
@@ -454,21 +432,6 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware,
Log4j2File
         return nodeId;
     }
 
-    // TODO implement.
-//    /**
-//     * Gets files for all registered file appenders.
-//     *
-//     * @return List of files.
-//     */
-//    public static Collection<String> logFiles() {
-//        Collection<String> res = new ArrayList<>(fileAppenders.size());
-//
-//        for (FileAppender a : fileAppenders)
-//            res.add(a.getFile());
-//
-//        return res;
-//    }
-
     /**
      * Gets {@link IgniteLogger} wrapper around log4j logger for the given
      * category. If category is {@code null}, then root logger is returned. If
@@ -556,20 +519,4 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware,
Log4j2File
     @Override public String toString() {
         return S.toString(Log4J2Logger.class, this);
     }
-
-    /** {@inheritDoc} */
-    // TODO implement.
-    @Override public void updateFilePath(IgniteClosure<String, String> filePathClos)
{
-        A.notNull(filePathClos, "filePathClos");
-
-//        new RollingFileAppender()
-
-//        for (FileAppender a : fileAppenders) {
-//            if (a instanceof Log4j2FileAware) {
-//                ((Log4j2FileAware)a).updateFilePath(filePathClos);
-//
-//                a.activateOptions();
-//            }
-//        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a679ff96/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/Log4j2FileAware.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/Log4j2FileAware.java
b/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/Log4j2FileAware.java
deleted file mode 100644
index de261aa..0000000
--- a/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/Log4j2FileAware.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.logger.log4j2;
-
-import org.apache.ignite.lang.*;
-
-/**
- * Interface for those loggers and appenders that evaluate their file paths lazily.
- */
-interface Log4j2FileAware {
-    /**
-     * Sets closure that later evaluate file path.
-     *
-     * @param filePathClos Closure that generates actual file path.
-     */
-    void updateFilePath(IgniteClosure<String, String> filePathClos);
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a679ff96/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/Log4j2NodeIdFilePath.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/Log4j2NodeIdFilePath.java
b/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/Log4j2NodeIdFilePath.java
deleted file mode 100644
index a0a7b12..0000000
--- a/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/Log4j2NodeIdFilePath.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.logger.log4j2;
-
-import org.apache.ignite.*;
-import org.apache.ignite.internal.util.typedef.*;
-import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.ignite.lang.*;
-
-import java.io.*;
-import java.util.*;
-
-/**
- * Closure that generates file path adding node id to filename as a suffix.
- */
-class Log4j2NodeIdFilePath implements IgniteClosure<String, String> {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** Node id. */
-    private final UUID nodeId;
-
-    /**
-     * Creates new instance.
-     *
-     * @param id Node id.
-     */
-    Log4j2NodeIdFilePath(UUID id) {
-        nodeId = id;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String apply(String oldPath) {
-        if (!F.isEmpty(U.IGNITE_LOG_DIR))
-            return U.nodeIdLogFileName(nodeId, new File(U.IGNITE_LOG_DIR, "ignite.log").getAbsolutePath());
-
-        if (oldPath != null) // fileName could be null if IGNITE_HOME is not defined.
-            return U.nodeIdLogFileName(nodeId, oldPath);
-
-        String tmpDir = IgniteSystemProperties.getString("java.io.tmpdir");
-
-        if (tmpDir != null)
-            return U.nodeIdLogFileName(nodeId, new File(tmpDir, "ignite.log").getAbsolutePath());
-
-        System.err.println("Failed to get tmp directory for log file.");
-
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a679ff96/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2TestTmp.java
----------------------------------------------------------------------
diff --git a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2TestTmp.java
b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2TestTmp.java
index 4cd836e..cb1d6be 100644
--- a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2TestTmp.java
+++ b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2TestTmp.java
@@ -17,34 +17,35 @@
 
 package org.apache.ignite.logger.log4j2;
 
-import org.apache.ignite.internal.util.typedef.internal.*;
-import org.apache.logging.log4j.*;
-import org.apache.logging.log4j.core.config.*;
-
-import java.net.*;
+import org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
 
 /**
  * TODO: Add class description.
  */
 public class Log4j2TestTmp {
     public static void main(String[] args) throws Exception {
-        URL url = U.resolveIgniteUrl("config/ignite-log4j2.xml");
-
-        System.out.println(url);
-
-        Configurator.initialize("test logger", url.toString());
-
-        LogManager.getLogger("test logger").info("******************************");
-
-//        IgniteConfiguration cfg = new IgniteConfiguration()
-//            .setGridLogger(new Log4J2Logger("config/ignite-log4j2.xml"));
+//        URL url = U.resolveIgniteUrl("config/ignite-log4j2.xml");
+//
+//        System.out.println(url);
+//
+//        Configurator.initialize("test logger", url.toString());
 //
-//        try(Ignite ignite = Ignition.start(cfg)) {
-//            ignite.log().info("********** Hi! **************");
+//        LogManager.getLogger("test logger").info("******************************1");
 //
-//            Thread.sleep(5_000);
+//        ThreadContext.put("nodeId", "12345");
 //
-//            ignite.log().info("********** Hi! **************");
-//        }
+//        LogManager.getLogger("test logger").info("******************************2");
+
+        IgniteConfiguration cfg = new IgniteConfiguration()
+            .setGridLogger(new Log4J2Logger("config/ignite-log4j2.xml"));
+
+        try (Ignite ignite = Ignition.start(cfg.setGridName("grid1"))) {
+            ignite.log().info("****** smf 1 ********");
+            try (Ignite ignite2 = Ignition.start(cfg.setGridName("grid2"))) {
+                ignite.log().info("****** smf 2 ********");
+                ignite2.log().info("****** smf 3 ********");
+            }
+        }
     }
 }


Mime
View raw message