review
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/955e6481 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/955e6481 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/955e6481 Branch: refs/heads/ignite-471 Commit: 955e64817139a74fc1a197b3e9bc5820d2fdefe2 Parents: c7ea55c Author: Yakov Zhdanov <yzhda...@gridgain.com> Authored: Tue Apr 28 13:20:31 2015 +0300 Committer: Yakov Zhdanov <yzhda...@gridgain.com> Committed: Tue Apr 28 13:20:31 2015 +0300 ---------------------------------------------------------------------- .../java/org/apache/ignite/IgniteLogger.java | 2 +- .../GridDeploymentPerVersionStore.java | 3 +- .../ignite/logger/jcl/IgniteJclLogger.java | 167 ------------------- .../org/apache/ignite/logger/jcl/JclLogger.java | 167 +++++++++++++++++++ .../ignite/logger/jcl/IgniteJclLoggerTest.java | 48 ------ .../apache/ignite/logger/jcl/JclLoggerTest.java | 48 ++++++ .../ignite/testsuites/IgniteJclTestSuite.java | 2 +- .../ignite/logger/slf4j/GridSlf4jLogger.java | 138 --------------- .../apache/ignite/logger/slf4j/Slf4jLogger.java | 138 +++++++++++++++ 9 files changed, 357 insertions(+), 356 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/955e6481/modules/core/src/main/java/org/apache/ignite/IgniteLogger.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteLogger.java b/modules/core/src/main/java/org/apache/ignite/IgniteLogger.java index 1874f4e..f99927c 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteLogger.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteLogger.java @@ -41,7 +41,7 @@ import org.jetbrains.annotations.*; * <pre name="code" class="xml"> * ... * <property name="gridLogger"> - * <bean class="org.apache.ignite.logger.jcl.IgniteJclLogger"> + * <bean class="org.apache.ignite.logger.jcl.JclLogger"> * <constructor-arg type="org.apache.commons.logging.Log"> * <bean class="org.apache.commons.logging.impl.Log4JLogger"> * <constructor-arg type="java.lang.String" value="config/ignite-log4j.xml"/> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/955e6481/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerVersionStore.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerVersionStore.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerVersionStore.java index bc3b074..459fed6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerVersionStore.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentPerVersionStore.java @@ -293,7 +293,8 @@ public class GridDeploymentPerVersionStore extends GridDeploymentStoreAdapter { // Warn only if mode is not CONTINUOUS. if (meta.deploymentMode() != CONTINUOUS) LT.warn(log, null, "Local node is in participants (most probably, " + - "IgniteConfiguration.getPeerClassLoadingLocalClassPathExclude() is not used properly " + + "IgniteConfiguration.getPeerClassLoadingLocalClassPathExclude() " + + "is not used properly " + "[locNodeId=" + ctx.localNodeId() + ", meta=" + meta + ']'); continue; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/955e6481/modules/jcl/src/main/java/org/apache/ignite/logger/jcl/IgniteJclLogger.java ---------------------------------------------------------------------- diff --git a/modules/jcl/src/main/java/org/apache/ignite/logger/jcl/IgniteJclLogger.java b/modules/jcl/src/main/java/org/apache/ignite/logger/jcl/IgniteJclLogger.java deleted file mode 100644 index 30a15f8..0000000 --- a/modules/jcl/src/main/java/org/apache/ignite/logger/jcl/IgniteJclLogger.java +++ /dev/null @@ -1,167 +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.jcl; - -import org.apache.commons.logging.*; -import org.apache.ignite.*; -import org.jetbrains.annotations.*; - -/** - * This logger wraps any JCL (<a target=_blank href="http://jakarta.apache.org/commons/logging/">Jakarta Commons Logging</a>) - * loggers. Implementation simply delegates to underlying JCL logger. This logger - * should be used by loaders that have JCL-based internal logging (e.g., Websphere). - * <p> - * Here is an example of configuring JCL logger in Ignite configuration Spring - * file to work over log4j implementation. Note that we use the same configuration file - * as we provide by default: - * <pre name="code" class="xml"> - * ... - * <property name="gridLogger"> - * <bean class="org.apache.ignite.logger.jcl.IgniteJclLogger"> - * <constructor-arg type="org.apache.commons.logging.Log"> - * <bean class="org.apache.commons.logging.impl.Log4JLogger"> - * <constructor-arg type="java.lang.String" value="config/ignite-log4j.xml"/> - * </bean> - * </constructor-arg> - * </bean> - * </property> - * ... - * </pre> - * If you are using system properties to configure JCL logger use following configuration: - * <pre name="code" class="xml"> - * ... - * <property name="gridLogger"> - * <bean class="org.apache.ignite.logger.jcl.IgniteJclLogger"/> - * </property> - * ... - * </pre> - * And the same configuration if you'd like to configure Ignite in your code: - * <pre name="code" class="java"> - * IgniteConfiguration cfg = new IgniteConfiguration(); - * ... - * IgniteLogger log = new IgniteJclLogger(new Log4JLogger("config/ignite-log4j.xml")); - * ... - * cfg.setGridLogger(log); - * </pre> - * or following for the configuration by means of system properties: - * <pre name="code" class="java"> - * IgniteConfiguration cfg = new IgniteConfiguration(); - * ... - * IgniteLogger log = new IgniteJclLogger(); - * ... - * cfg.setGridLogger(log); - * </pre> - * - * <p> - * It's recommended to use Ignite logger injection instead of using/instantiating - * logger in your task/job code. See {@link org.apache.ignite.resources.LoggerResource} annotation about logger - * injection. - */ -public class IgniteJclLogger implements IgniteLogger { - /** JCL implementation proxy. */ - private Log impl; - - /** - * Creates new logger. - */ - public IgniteJclLogger() { - this(LogFactory.getLog(IgniteJclLogger.class.getName())); - } - - /** - * Creates new logger with given implementation. - * - * @param impl JCL implementation to use. - */ - public IgniteJclLogger(Log impl) { - assert impl != null; - - this.impl = impl; - } - - /** {@inheritDoc} */ - @Override public IgniteLogger getLogger(Object ctgr) { - return new IgniteJclLogger(LogFactory.getLog( - ctgr instanceof Class ? ((Class)ctgr).getName() : String.valueOf(ctgr))); - } - - /** {@inheritDoc} */ - @Override public void trace(String msg) { - impl.trace(msg); - } - - /** {@inheritDoc} */ - @Override public void debug(String msg) { - impl.debug(msg); - } - - /** {@inheritDoc} */ - @Override public void info(String msg) { - impl.info(msg); - } - - /** {@inheritDoc} */ - @Override public void warning(String msg) { - impl.warn(msg); - } - - /** {@inheritDoc} */ - @Override public void warning(String msg, @Nullable Throwable e) { - impl.warn(msg, e); - } - - /** {@inheritDoc} */ - @Override public void error(String msg) { - impl.error(msg); - } - - /** {@inheritDoc} */ - @Override public boolean isQuiet() { - return !isInfoEnabled() && !isDebugEnabled(); - } - - /** {@inheritDoc} */ - @Override public void error(String msg, @Nullable Throwable e) { - impl.error(msg, e); - } - - /** {@inheritDoc} */ - @Override public boolean isTraceEnabled() { - return impl.isTraceEnabled(); - } - - /** {@inheritDoc} */ - @Override public boolean isDebugEnabled() { - return impl.isDebugEnabled(); - } - - /** {@inheritDoc} */ - @Override public boolean isInfoEnabled() { - return impl.isInfoEnabled(); - } - - /** {@inheritDoc} */ - @Nullable @Override public String fileName() { - return null; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return "IgniteJclLogger [impl=" + impl + ']'; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/955e6481/modules/jcl/src/main/java/org/apache/ignite/logger/jcl/JclLogger.java ---------------------------------------------------------------------- diff --git a/modules/jcl/src/main/java/org/apache/ignite/logger/jcl/JclLogger.java b/modules/jcl/src/main/java/org/apache/ignite/logger/jcl/JclLogger.java new file mode 100644 index 0000000..6e3c4c6 --- /dev/null +++ b/modules/jcl/src/main/java/org/apache/ignite/logger/jcl/JclLogger.java @@ -0,0 +1,167 @@ +/* + * 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.jcl; + +import org.apache.commons.logging.*; +import org.apache.ignite.*; +import org.jetbrains.annotations.*; + +/** + * This logger wraps any JCL (<a target=_blank href="http://jakarta.apache.org/commons/logging/">Jakarta Commons Logging</a>) + * loggers. Implementation simply delegates to underlying JCL logger. This logger + * should be used by loaders that have JCL-based internal logging (e.g., Websphere). + * <p> + * Here is an example of configuring JCL logger in Ignite configuration Spring + * file to work over log4j implementation. Note that we use the same configuration file + * as we provide by default: + * <pre name="code" class="xml"> + * ... + * <property name="gridLogger"> + * <bean class="org.apache.ignite.logger.jcl.JclLogger"> + * <constructor-arg type="org.apache.commons.logging.Log"> + * <bean class="org.apache.commons.logging.impl.Log4JLogger"> + * <constructor-arg type="java.lang.String" value="config/ignite-log4j.xml"/> + * </bean> + * </constructor-arg> + * </bean> + * </property> + * ... + * </pre> + * If you are using system properties to configure JCL logger use following configuration: + * <pre name="code" class="xml"> + * ... + * <property name="gridLogger"> + * <bean class="org.apache.ignite.logger.jcl.JclLogger"/> + * </property> + * ... + * </pre> + * And the same configuration if you'd like to configure Ignite in your code: + * <pre name="code" class="java"> + * IgniteConfiguration cfg = new IgniteConfiguration(); + * ... + * IgniteLogger log = new JclLogger(new Log4JLogger("config/ignite-log4j.xml")); + * ... + * cfg.setGridLogger(log); + * </pre> + * or following for the configuration by means of system properties: + * <pre name="code" class="java"> + * IgniteConfiguration cfg = new IgniteConfiguration(); + * ... + * IgniteLogger log = new JclLogger(); + * ... + * cfg.setGridLogger(log); + * </pre> + * + * <p> + * It's recommended to use Ignite logger injection instead of using/instantiating + * logger in your task/job code. See {@link org.apache.ignite.resources.LoggerResource} annotation about logger + * injection. + */ +public class JclLogger implements IgniteLogger { + /** JCL implementation proxy. */ + private Log impl; + + /** + * Creates new logger. + */ + public JclLogger() { + this(LogFactory.getLog(JclLogger.class.getName())); + } + + /** + * Creates new logger with given implementation. + * + * @param impl JCL implementation to use. + */ + public JclLogger(Log impl) { + assert impl != null; + + this.impl = impl; + } + + /** {@inheritDoc} */ + @Override public IgniteLogger getLogger(Object ctgr) { + return new JclLogger(LogFactory.getLog( + ctgr instanceof Class ? ((Class)ctgr).getName() : String.valueOf(ctgr))); + } + + /** {@inheritDoc} */ + @Override public void trace(String msg) { + impl.trace(msg); + } + + /** {@inheritDoc} */ + @Override public void debug(String msg) { + impl.debug(msg); + } + + /** {@inheritDoc} */ + @Override public void info(String msg) { + impl.info(msg); + } + + /** {@inheritDoc} */ + @Override public void warning(String msg) { + impl.warn(msg); + } + + /** {@inheritDoc} */ + @Override public void warning(String msg, @Nullable Throwable e) { + impl.warn(msg, e); + } + + /** {@inheritDoc} */ + @Override public void error(String msg) { + impl.error(msg); + } + + /** {@inheritDoc} */ + @Override public boolean isQuiet() { + return !isInfoEnabled() && !isDebugEnabled(); + } + + /** {@inheritDoc} */ + @Override public void error(String msg, @Nullable Throwable e) { + impl.error(msg, e); + } + + /** {@inheritDoc} */ + @Override public boolean isTraceEnabled() { + return impl.isTraceEnabled(); + } + + /** {@inheritDoc} */ + @Override public boolean isDebugEnabled() { + return impl.isDebugEnabled(); + } + + /** {@inheritDoc} */ + @Override public boolean isInfoEnabled() { + return impl.isInfoEnabled(); + } + + /** {@inheritDoc} */ + @Nullable @Override public String fileName() { + return null; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return "JclLogger [impl=" + impl + ']'; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/955e6481/modules/jcl/src/test/java/org/apache/ignite/logger/jcl/IgniteJclLoggerTest.java ---------------------------------------------------------------------- diff --git a/modules/jcl/src/test/java/org/apache/ignite/logger/jcl/IgniteJclLoggerTest.java b/modules/jcl/src/test/java/org/apache/ignite/logger/jcl/IgniteJclLoggerTest.java deleted file mode 100644 index 13a32a0..0000000 --- a/modules/jcl/src/test/java/org/apache/ignite/logger/jcl/IgniteJclLoggerTest.java +++ /dev/null @@ -1,48 +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.jcl; - -import junit.framework.*; -import org.apache.commons.logging.*; -import org.apache.ignite.*; -import org.apache.ignite.testframework.junits.common.*; - -/** - * Jcl logger test. - */ -@GridCommonTest(group = "Logger") -public class IgniteJclLoggerTest extends TestCase { - /** */ - @SuppressWarnings({"FieldCanBeLocal"}) - private IgniteLogger log; - - /** */ - public void testLogInitialize() { - log = new IgniteJclLogger(LogFactory.getLog(IgniteJclLoggerTest.class.getName())); - - assert log.isInfoEnabled() == true; - - log.info("This is 'info' message."); - log.warning("This is 'warning' message."); - log.warning("This is 'warning' message.", new Exception("It's a test warning exception")); - log.error("This is 'error' message."); - log.error("This is 'error' message.", new Exception("It's a test error exception")); - - assert log.getLogger(IgniteJclLoggerTest.class.getName()) instanceof IgniteJclLogger; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/955e6481/modules/jcl/src/test/java/org/apache/ignite/logger/jcl/JclLoggerTest.java ---------------------------------------------------------------------- diff --git a/modules/jcl/src/test/java/org/apache/ignite/logger/jcl/JclLoggerTest.java b/modules/jcl/src/test/java/org/apache/ignite/logger/jcl/JclLoggerTest.java new file mode 100644 index 0000000..01bcc65 --- /dev/null +++ b/modules/jcl/src/test/java/org/apache/ignite/logger/jcl/JclLoggerTest.java @@ -0,0 +1,48 @@ +/* + * 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.jcl; + +import junit.framework.*; +import org.apache.commons.logging.*; +import org.apache.ignite.*; +import org.apache.ignite.testframework.junits.common.*; + +/** + * Jcl logger test. + */ +@GridCommonTest(group = "Logger") +public class JclLoggerTest extends TestCase { + /** */ + @SuppressWarnings({"FieldCanBeLocal"}) + private IgniteLogger log; + + /** */ + public void testLogInitialize() { + log = new JclLogger(LogFactory.getLog(JclLoggerTest.class.getName())); + + assert log.isInfoEnabled() == true; + + log.info("This is 'info' message."); + log.warning("This is 'warning' message."); + log.warning("This is 'warning' message.", new Exception("It's a test warning exception")); + log.error("This is 'error' message."); + log.error("This is 'error' message.", new Exception("It's a test error exception")); + + assert log.getLogger(JclLoggerTest.class.getName()) instanceof JclLogger; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/955e6481/modules/jcl/src/test/java/org/apache/ignite/testsuites/IgniteJclTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/jcl/src/test/java/org/apache/ignite/testsuites/IgniteJclTestSuite.java b/modules/jcl/src/test/java/org/apache/ignite/testsuites/IgniteJclTestSuite.java index 29e198c..cb55d51 100644 --- a/modules/jcl/src/test/java/org/apache/ignite/testsuites/IgniteJclTestSuite.java +++ b/modules/jcl/src/test/java/org/apache/ignite/testsuites/IgniteJclTestSuite.java @@ -31,7 +31,7 @@ public class IgniteJclTestSuite extends TestSuite { public static TestSuite suite() throws Exception { TestSuite suite = new TestSuite("Commons Logging Test Suite"); - suite.addTest(new TestSuite(IgniteJclLoggerTest.class)); + suite.addTest(new TestSuite(JclLoggerTest.class)); return suite; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/955e6481/modules/slf4j/src/main/java/org/apache/ignite/logger/slf4j/GridSlf4jLogger.java ---------------------------------------------------------------------- diff --git a/modules/slf4j/src/main/java/org/apache/ignite/logger/slf4j/GridSlf4jLogger.java b/modules/slf4j/src/main/java/org/apache/ignite/logger/slf4j/GridSlf4jLogger.java deleted file mode 100644 index 417108d..0000000 --- a/modules/slf4j/src/main/java/org/apache/ignite/logger/slf4j/GridSlf4jLogger.java +++ /dev/null @@ -1,138 +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.slf4j; - -import org.apache.ignite.*; -import org.jetbrains.annotations.*; -import org.slf4j.*; - -/** - * SLF4J-based implementation for logging. This logger should be used - * by loaders that have prefer slf4j-based logging. - * <p> - * Here is an example of configuring SLF4J logger in Ignite configuration Spring file: - * <pre name="code" class="xml"> - * <property name="gridLogger"> - * <bean class="org.apache.ignite.logger.slf4j.GridSlf4jLogger"/> - * </property> - * </pre> - * <p> - * It's recommended to use Ignite's logger injection instead of using/instantiating - * logger in your task/job code. See {@link org.apache.ignite.resources.LoggerResource} annotation about logger - * injection. - */ -public class GridSlf4jLogger implements IgniteLogger { - /** SLF4J implementation proxy. */ - private final Logger impl; - - /** - * Creates new logger. - */ - public GridSlf4jLogger() { - impl = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); - } - - /** - * Creates new logger with given implementation. - * - * @param impl SLF4J implementation to use. - */ - public GridSlf4jLogger(Logger impl) { - assert impl != null; - - this.impl = impl; - } - - /** {@inheritDoc} */ - @Override public GridSlf4jLogger getLogger(Object ctgr) { - Logger impl = ctgr == null ? LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME) : - ctgr instanceof Class ? LoggerFactory.getLogger(((Class<?>)ctgr).getName()) : - LoggerFactory.getLogger(ctgr.toString()); - - return new GridSlf4jLogger(impl); - } - - /** {@inheritDoc} */ - @Override public void trace(String msg) { - if (!impl.isTraceEnabled()) - warning("Logging at TRACE level without checking if TRACE level is enabled: " + msg); - - impl.trace(msg); - } - - /** {@inheritDoc} */ - @Override public void debug(String msg) { - if (!impl.isDebugEnabled()) - warning("Logging at DEBUG level without checking if DEBUG level is enabled: " + msg); - - impl.debug(msg); - } - - /** {@inheritDoc} */ - @Override public void info(String msg) { - if (!impl.isInfoEnabled()) - warning("Logging at INFO level without checking if INFO level is enabled: " + msg); - - impl.info(msg); - } - - /** {@inheritDoc} */ - @Override public void warning(String msg) { - impl.warn(msg); - } - - /** {@inheritDoc} */ - @Override public void warning(String msg, @Nullable Throwable e) { - impl.warn(msg, e); - } - - /** {@inheritDoc} */ - @Override public void error(String msg) { - impl.error(msg); - } - - /** {@inheritDoc} */ - @Override public void error(String msg, @Nullable Throwable e) { - impl.error(msg, e); - } - - /** {@inheritDoc} */ - @Override public boolean isTraceEnabled() { - return impl.isTraceEnabled(); - } - - /** {@inheritDoc} */ - @Override public boolean isInfoEnabled() { - return impl.isInfoEnabled(); - } - - /** {@inheritDoc} */ - @Override public boolean isDebugEnabled() { - return impl.isDebugEnabled(); - } - - /** {@inheritDoc} */ - @Override public boolean isQuiet() { - return !isInfoEnabled() && !isDebugEnabled(); - } - - /** {@inheritDoc} */ - @Nullable @Override public String fileName() { - return null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/955e6481/modules/slf4j/src/main/java/org/apache/ignite/logger/slf4j/Slf4jLogger.java ---------------------------------------------------------------------- diff --git a/modules/slf4j/src/main/java/org/apache/ignite/logger/slf4j/Slf4jLogger.java b/modules/slf4j/src/main/java/org/apache/ignite/logger/slf4j/Slf4jLogger.java new file mode 100644 index 0000000..d3f1029 --- /dev/null +++ b/modules/slf4j/src/main/java/org/apache/ignite/logger/slf4j/Slf4jLogger.java @@ -0,0 +1,138 @@ +/* + * 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.slf4j; + +import org.apache.ignite.*; +import org.jetbrains.annotations.*; +import org.slf4j.*; + +/** + * SLF4J-based implementation for logging. This logger should be used + * by loaders that have prefer slf4j-based logging. + * <p> + * Here is an example of configuring SLF4J logger in Ignite configuration Spring file: + * <pre name="code" class="xml"> + * <property name="gridLogger"> + * <bean class="org.apache.ignite.logger.slf4j.GridSlf4jLogger"/> + * </property> + * </pre> + * <p> + * It's recommended to use Ignite's logger injection instead of using/instantiating + * logger in your task/job code. See {@link org.apache.ignite.resources.LoggerResource} annotation about logger + * injection. + */ +public class Slf4jLogger implements IgniteLogger { + /** SLF4J implementation proxy. */ + private final Logger impl; + + /** + * Creates new logger. + */ + public Slf4jLogger() { + impl = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); + } + + /** + * Creates new logger with given implementation. + * + * @param impl SLF4J implementation to use. + */ + public Slf4jLogger(Logger impl) { + assert impl != null; + + this.impl = impl; + } + + /** {@inheritDoc} */ + @Override public Slf4jLogger getLogger(Object ctgr) { + Logger impl = ctgr == null ? LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME) : + ctgr instanceof Class ? LoggerFactory.getLogger(((Class<?>)ctgr).getName()) : + LoggerFactory.getLogger(ctgr.toString()); + + return new Slf4jLogger(impl); + } + + /** {@inheritDoc} */ + @Override public void trace(String msg) { + if (!impl.isTraceEnabled()) + warning("Logging at TRACE level without checking if TRACE level is enabled: " + msg); + + impl.trace(msg); + } + + /** {@inheritDoc} */ + @Override public void debug(String msg) { + if (!impl.isDebugEnabled()) + warning("Logging at DEBUG level without checking if DEBUG level is enabled: " + msg); + + impl.debug(msg); + } + + /** {@inheritDoc} */ + @Override public void info(String msg) { + if (!impl.isInfoEnabled()) + warning("Logging at INFO level without checking if INFO level is enabled: " + msg); + + impl.info(msg); + } + + /** {@inheritDoc} */ + @Override public void warning(String msg) { + impl.warn(msg); + } + + /** {@inheritDoc} */ + @Override public void warning(String msg, @Nullable Throwable e) { + impl.warn(msg, e); + } + + /** {@inheritDoc} */ + @Override public void error(String msg) { + impl.error(msg); + } + + /** {@inheritDoc} */ + @Override public void error(String msg, @Nullable Throwable e) { + impl.error(msg, e); + } + + /** {@inheritDoc} */ + @Override public boolean isTraceEnabled() { + return impl.isTraceEnabled(); + } + + /** {@inheritDoc} */ + @Override public boolean isInfoEnabled() { + return impl.isInfoEnabled(); + } + + /** {@inheritDoc} */ + @Override public boolean isDebugEnabled() { + return impl.isDebugEnabled(); + } + + /** {@inheritDoc} */ + @Override public boolean isQuiet() { + return !isInfoEnabled() && !isDebugEnabled(); + } + + /** {@inheritDoc} */ + @Nullable @Override public String fileName() { + return null; + } +}