You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/07/20 16:55:10 UTC
[07/24] incubator-ignite git commit: # ignite-788: stop
implementation at this way
# ignite-788: stop implementation at this way
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/992dc65c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/992dc65c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/992dc65c
Branch: refs/heads/ignite-788-last-review
Commit: 992dc65c01f320b328c44bdfa989701dd1e1b118
Parents: 630439f
Author: ashutak <as...@gridgain.com>
Authored: Wed Jul 15 18:51:33 2015 +0300
Committer: ashutak <as...@gridgain.com>
Committed: Wed Jul 15 18:51:33 2015 +0300
----------------------------------------------------------------------
config/ignite-log4j.xml | 10 +-
config/ignite-log4j2.xml | 6 +-
modules/log4j/src/main/java/Log4jTestTmp.java | 37 +++++
.../logger/log4j/Log4jRollingFileAppender.java | 4 +
.../log4j2/IgniteRollingFileAppender.java | 162 +++++++++++++++++++
.../ignite/logger/log4j2/Log4J2Logger.java | 11 +-
.../ignite/logger/log4j2/Log4j2TestTmp.java | 29 ++--
7 files changed, 238 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/992dc65c/config/ignite-log4j.xml
----------------------------------------------------------------------
diff --git a/config/ignite-log4j.xml b/config/ignite-log4j.xml
index 9d4521a..8dd114c 100644
--- a/config/ignite-log4j.xml
+++ b/config/ignite-log4j.xml
@@ -23,14 +23,14 @@
<!--
Default log4j configuration for Ignite.
-->
-<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
<!--
Logs System.out messages to console.
Note, this appender is disabled by default.
To enable, uncomment the section below and also CONSOLE appender in the <root> element.
-->
- <!--
+ <!--<!–-->
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out"/>
@@ -45,7 +45,7 @@
<param name="levelMax" value="WARN"/>
</filter>
</appender>
- -->
+ <!--–>-->
<!--
Logs all ERROR messages to console.
@@ -123,9 +123,9 @@
<level value="INFO"/>
<!-- Uncomment to enable logging to console. -->
- <!--
+ <!--<!–-->
<appender-ref ref="CONSOLE"/>
- -->
+ <!--–>-->
<appender-ref ref="CONSOLE_ERR"/>
<appender-ref ref="FILE"/>
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/992dc65c/config/ignite-log4j2.xml
----------------------------------------------------------------------
diff --git a/config/ignite-log4j2.xml b/config/ignite-log4j2.xml
index 4ada9ff..08d9246 100644
--- a/config/ignite-log4j2.xml
+++ b/config/ignite-log4j2.xml
@@ -17,7 +17,7 @@
limitations under the License.
-->
-<Configuration status="trace">
+<Configuration status="info">
<Appenders>
<Console name="CONSOLE_ERR" target="SYSTEM_ERR">
<PatternLayout pattern="[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n"/>
@@ -26,7 +26,7 @@
<!--TODO-->
<!--<param name="MaxFileSize" value="10MB"/>-->
<!--<param name="MaxBackupIndex" value="10"/>-->
- <RollingFile name="FILE" fileName="work/log/ignite-id.log"
+ <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>
@@ -35,7 +35,7 @@
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="250 MB"/>
</Policies>
- </RollingFile>
+ </IgniteRollingFile>
</Appenders>
<Loggers>
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/992dc65c/modules/log4j/src/main/java/Log4jTestTmp.java
----------------------------------------------------------------------
diff --git a/modules/log4j/src/main/java/Log4jTestTmp.java b/modules/log4j/src/main/java/Log4jTestTmp.java
new file mode 100644
index 0000000..b855ce5
--- /dev/null
+++ b/modules/log4j/src/main/java/Log4jTestTmp.java
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+
+import org.apache.ignite.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.logger.log4j.*;
+
+/**
+ * TODO: Add class description.
+ */
+public class Log4jTestTmp {
+ public static void main(String[] args) throws Exception {
+ IgniteConfiguration cfg = new IgniteConfiguration()
+ .setGridLogger(new Log4JLogger("config/ignite-log4j.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 ********");
+ }}
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/992dc65c/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4jRollingFileAppender.java
----------------------------------------------------------------------
diff --git a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4jRollingFileAppender.java b/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4jRollingFileAppender.java
index dcf03a4..fbe3aab 100644
--- a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4jRollingFileAppender.java
+++ b/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4jRollingFileAppender.java
@@ -73,12 +73,16 @@ public class Log4jRollingFileAppender extends RollingFileAppender implements Log
/** {@inheritDoc} */
@Override public synchronized void updateFilePath(IgniteClosure<String, String> filePathClos) {
+ U.debug("**************** updateFilePath ************");
+
A.notNull(filePathClos, "filePathClos");
if (baseFileName == null)
baseFileName = fileName;
fileName = filePathClos.apply(baseFileName);
+
+ U.debug("**************** fileName=" + fileName + " appender=" + System.identityHashCode(this) + " ************");
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/992dc65c/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
new file mode 100644
index 0000000..75f967f
--- /dev/null
+++ b/modules/log4j2/src/main/java/org/apache/ignite/logger/log4j2/IgniteRollingFileAppender.java
@@ -0,0 +1,162 @@
+/*
+* 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/992dc65c/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 22cc231..c6a4df1 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
@@ -68,6 +68,7 @@ import static org.apache.ignite.IgniteSystemProperties.*;
* injection.
*/
public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware, Log4j2FileAware {
+ public static final String LOGGER_NAME = "Log4J2Logger";
/** Appenders. */
private static Collection<FileAppender> fileAppenders = new GridConcurrentHashSet<>();
@@ -174,7 +175,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware, Log4j2File
@Override public Logger apply(Boolean init) {
if (init)
// TODO review
- Configurator.initialize("Log4J2Logger", cfgUrl.toString());
+ Configurator.initialize(LOGGER_NAME, cfgUrl.toString());
return LogManager.getRootLogger();
}
@@ -202,7 +203,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware, Log4j2File
addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() {
@Override public Logger apply(Boolean init) {
if (init)
- Configurator.initialize("Log4J2Logger", path);
+ Configurator.initialize(LOGGER_NAME, path);
return LogManager.getRootLogger();
}
@@ -227,7 +228,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware, Log4j2File
addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() {
@Override public Logger apply(Boolean init) {
if (init)
- Configurator.initialize("Log4J2Logger", cfgUrl.toString());
+ Configurator.initialize(LOGGER_NAME, cfgUrl.toString());
return LogManager.getRootLogger();
}
@@ -243,7 +244,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware, Log4j2File
*/
// TODO review
public static boolean isConfigured() {
- return LogManager.getLogger("Log4J2Logger") != null;
+ return LogManager.getLogger(LOGGER_NAME) != null;
}
/**
@@ -561,6 +562,8 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware, Log4j2File
@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);
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/992dc65c/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 d809b73..4cd836e 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,23 +17,34 @@
package org.apache.ignite.logger.log4j2;
-import org.apache.ignite.*;
-import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.logging.log4j.*;
+import org.apache.logging.log4j.core.config.*;
+
+import java.net.*;
/**
* TODO: Add class description.
*/
public class Log4j2TestTmp {
public static void main(String[] args) throws Exception {
- IgniteConfiguration cfg = new IgniteConfiguration()
- .setGridLogger(new Log4J2Logger("config/ignite-log4j2.xml"));
+ URL url = U.resolveIgniteUrl("config/ignite-log4j2.xml");
+
+ System.out.println(url);
- try(Ignite ignite = Ignition.start(cfg)) {
- ignite.log().info("********** Hi! **************");
+ Configurator.initialize("test logger", url.toString());
- Thread.sleep(5_000);
+ LogManager.getLogger("test logger").info("******************************");
- ignite.log().info("********** Hi! **************");
- }
+// IgniteConfiguration cfg = new IgniteConfiguration()
+// .setGridLogger(new Log4J2Logger("config/ignite-log4j2.xml"));
+//
+// try(Ignite ignite = Ignition.start(cfg)) {
+// ignite.log().info("********** Hi! **************");
+//
+// Thread.sleep(5_000);
+//
+// ignite.log().info("********** Hi! **************");
+// }
}
}