Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F3F6B18161 for ; Mon, 20 Jul 2015 14:55:13 +0000 (UTC) Received: (qmail 7817 invoked by uid 500); 20 Jul 2015 14:55:13 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 7784 invoked by uid 500); 20 Jul 2015 14:55:13 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 7733 invoked by uid 99); 20 Jul 2015 14:55:13 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Jul 2015 14:55:13 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 541C0C13BD for ; Mon, 20 Jul 2015 14:55:13 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.771 X-Spam-Level: * X-Spam-Status: No, score=1.771 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id JuWMs2sfPhFB for ; Mon, 20 Jul 2015 14:55:09 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 4C40A50601 for ; Mon, 20 Jul 2015 14:55:05 +0000 (UTC) Received: (qmail 7324 invoked by uid 99); 20 Jul 2015 14:55:04 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Jul 2015 14:55:04 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id A2086E0967; Mon, 20 Jul 2015 14:55:04 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.incubator.apache.org Date: Mon, 20 Jul 2015 14:55:11 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [08/24] incubator-ignite git commit: # ignite-788: file logger works properly # 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 Authored: Wed Jul 15 19:31:57 2015 +0300 Committer: ashutak 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 @@ - - - - - - [%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n - - - - - - + + + + + + + + + + + + + + + @@ -47,7 +61,7 @@ - + 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 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 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 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 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 logFiles() { -// Collection 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 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 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 { - /** */ - 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 ********"); + } + } } }