IGNITE-6971 Ignite Logger type & logging file config indication. This closes #3095.
Signed-off-by: nikolay_tikhonov <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/92042475 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/92042475 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/92042475 Branch: refs/heads/ignite-zk Commit: 92042475186515fc5041aaa5bb10d669f31d0e62 Parents: f905442 Author: Alexey Popov <[email protected]> Authored: Wed Dec 6 16:21:20 2017 +0300 Committer: nikolay_tikhonov <[email protected]> Committed: Wed Dec 6 16:21:50 2017 +0300 ---------------------------------------------------------------------- .../apache/ignite/internal/GridLoggerProxy.java | 9 +++++ .../apache/ignite/internal/IgniteKernal.java | 13 +++++++ .../logger/platform/PlatformLogger.java | 15 ++++++++ .../org/apache/ignite/logger/NullLogger.java | 6 +++ .../apache/ignite/logger/java/JavaLogger.java | 17 +++++++++ .../ignite/logger/java/JavaLoggerTest.java | 5 +++ .../junits/logger/GridTestLog4jLogger.java | 21 +++++----- .../apache/ignite/logger/log4j/Log4JLogger.java | 40 +++++++++++++++----- .../log4j/GridLog4jCorrectFileNameTest.java | 13 +++++++ .../logger/log4j/GridLog4jInitializedTest.java | 7 +++- .../logger/log4j/GridLog4jLoggingFileTest.java | 13 +++++-- .../logger/log4j/GridLog4jLoggingPathTest.java | 12 +++++- .../logger/log4j/GridLog4jLoggingUrlTest.java | 15 ++++++-- .../log4j/GridLog4jNotInitializedTest.java | 5 +++ .../ignite/testsuites/IgniteLog4jTestSuite.java | 6 +++ .../ignite/logger/log4j2/Log4J2Logger.java | 20 +++++++--- .../logger/log4j2/Log4j2LoggerSelfTest.java | 19 +++++++++- .../apache/ignite/logger/slf4j/Slf4jLogger.java | 6 +++ 18 files changed, 207 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/92042475/modules/core/src/main/java/org/apache/ignite/internal/GridLoggerProxy.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridLoggerProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/GridLoggerProxy.java index 9f5daae..fc49b96 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridLoggerProxy.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/GridLoggerProxy.java @@ -169,6 +169,15 @@ public class GridLoggerProxy implements IgniteLogger, LifecycleAware, Externaliz } /** + * Gets the class name and parameters of the Logger type used. + * + * @return Logger information (name and parameters) + */ + public String getLoggerInfo() { + return impl.toString(); + } + + /** * Enriches the log message with Ignite instance name if * {@link org.apache.ignite.IgniteSystemProperties#IGNITE_LOG_INSTANCE_NAME} or * {@link org.apache.ignite.IgniteSystemProperties#IGNITE_LOG_GRID_NAME} system property is set. http://git-wip-us.apache.org/repos/asf/ignite/blob/92042475/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java index f29b994..f6ad9b3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java @@ -815,6 +815,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable { ackOsInfo(); ackLanguageRuntime(); ackRemoteManagement(); + ackLogger(); ackVmArguments(rtBean); ackClassPaths(rtBean); ackSystemProperties(); @@ -1982,6 +1983,16 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable { } /** + * Acks Logger configuration. + */ + private void ackLogger() { + assert log != null; + + if (log.isInfoEnabled()) + log.info("Logger: " + log.getLoggerInfo() ); + } + + /** * Acks ASCII-logo. Thanks to http://patorjk.com/software/taag */ private void ackAsciiLogo() { @@ -2025,6 +2036,8 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable { if (fileName != null) U.quiet(false, " ^-- Logging to file '" + fileName + '\''); + U.quiet(false, " ^-- Logging by '" + log.getLoggerInfo() + '\''); + U.quiet(false, " ^-- To see **FULL** console log here add -DIGNITE_QUIET=false or \"-v\" to ignite.{sh|bat}", ""); http://git-wip-us.apache.org/repos/asf/ignite/blob/92042475/modules/core/src/main/java/org/apache/ignite/internal/logger/platform/PlatformLogger.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/logger/platform/PlatformLogger.java b/modules/core/src/main/java/org/apache/ignite/internal/logger/platform/PlatformLogger.java index 0a0437e..c082126 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/logger/platform/PlatformLogger.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/logger/platform/PlatformLogger.java @@ -24,7 +24,10 @@ import org.apache.ignite.internal.processors.platform.PlatformNativeException; import org.apache.ignite.internal.processors.platform.callback.PlatformCallbackGateway; import org.apache.ignite.internal.processors.platform.memory.PlatformMemory; import org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream; +import org.apache.ignite.internal.util.tostring.GridToStringExclude; +import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.X; +import org.apache.ignite.internal.util.typedef.internal.S; import org.jetbrains.annotations.Nullable; import static org.apache.ignite.IgniteSystemProperties.IGNITE_QUIET; @@ -49,24 +52,31 @@ public class PlatformLogger implements IgniteLogger { public static final int LVL_ERROR = 4; /** Callbacks. */ + @GridToStringExclude private volatile PlatformCallbackGateway gate; /** Context. */ + @GridToStringExclude private volatile PlatformContext ctx; /** Category. */ + @GridToStringExclude private final String category; /** Trace flag. */ + @GridToStringInclude private volatile boolean traceEnabled; /** Debug flag. */ + @GridToStringInclude private volatile boolean debugEnabled; /** Info flag. */ + @GridToStringInclude private volatile boolean infoEnabled; /** Quiet flag. */ + @GridToStringInclude private static final boolean isQuiet = Boolean.valueOf(System.getProperty(IGNITE_QUIET, "true")); /** @@ -220,4 +230,9 @@ public class PlatformLogger implements IgniteLogger { ? ((Class)ctgr).getName() : (ctgr == null ? null : String.valueOf(ctgr)); } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(PlatformLogger.class, this); + } } http://git-wip-us.apache.org/repos/asf/ignite/blob/92042475/modules/core/src/main/java/org/apache/ignite/logger/NullLogger.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/logger/NullLogger.java b/modules/core/src/main/java/org/apache/ignite/logger/NullLogger.java index 71c7ba4..5b9c483 100644 --- a/modules/core/src/main/java/org/apache/ignite/logger/NullLogger.java +++ b/modules/core/src/main/java/org/apache/ignite/logger/NullLogger.java @@ -18,6 +18,7 @@ package org.apache.ignite.logger; import org.apache.ignite.IgniteLogger; +import org.apache.ignite.internal.util.typedef.internal.S; import org.jetbrains.annotations.Nullable; /** @@ -88,4 +89,9 @@ public class NullLogger implements IgniteLogger { @Nullable @Override public String fileName() { return null; } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(NullLogger.class, this); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/92042475/modules/core/src/main/java/org/apache/ignite/logger/java/JavaLogger.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/logger/java/JavaLogger.java b/modules/core/src/main/java/org/apache/ignite/logger/java/JavaLogger.java index 6aa7d38..78d3afa 100644 --- a/modules/core/src/main/java/org/apache/ignite/logger/java/JavaLogger.java +++ b/modules/core/src/main/java/org/apache/ignite/logger/java/JavaLogger.java @@ -29,8 +29,10 @@ import java.util.logging.LogManager; import java.util.logging.Logger; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteLogger; +import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.A; +import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.logger.LoggerNodeIdAware; import org.jetbrains.annotations.Nullable; @@ -107,16 +109,23 @@ public class JavaLogger implements IgniteLogger, LoggerNodeIdAware { private static volatile boolean quiet0; /** Java Logging implementation proxy. */ + @GridToStringExclude @SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized") private Logger impl; + /** Path to configuration file. */ + @GridToStringExclude + private String cfg; + /** Quiet flag. */ private final boolean quiet; /** Work directory. */ + @GridToStringExclude private volatile String workDir; /** Node ID. */ + @GridToStringExclude private volatile UUID nodeId; /** @@ -153,6 +162,8 @@ public class JavaLogger implements IgniteLogger, LoggerNodeIdAware { catch (IOException e) { error("Failed to read logging configuration: " + cfgUrl, e); } + + cfg = cfgUrl.getPath(); } /** @@ -216,6 +227,7 @@ public class JavaLogger implements IgniteLogger, LoggerNodeIdAware { // User configured console appender, thus log is not quiet. quiet0 = !consoleHndFound; inited = true; + cfg = System.getProperty("java.util.logging.config.file"); return; } @@ -406,4 +418,9 @@ public class JavaLogger implements IgniteLogger, LoggerNodeIdAware { return null; } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(JavaLogger.class, this, "config", this.cfg); + } } http://git-wip-us.apache.org/repos/asf/ignite/blob/92042475/modules/core/src/test/java/org/apache/ignite/logger/java/JavaLoggerTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/logger/java/JavaLoggerTest.java b/modules/core/src/test/java/org/apache/ignite/logger/java/JavaLoggerTest.java index 5fd5b5e..d9ec810 100644 --- a/modules/core/src/test/java/org/apache/ignite/logger/java/JavaLoggerTest.java +++ b/modules/core/src/test/java/org/apache/ignite/logger/java/JavaLoggerTest.java @@ -42,6 +42,11 @@ public class JavaLoggerTest extends TestCase { ((JavaLogger)log).setWorkDirectory(U.defaultWorkDirectory()); ((LoggerNodeIdAware)log).setNodeId(UUID.fromString("00000000-1111-2222-3333-444444444444")); + System.out.println(log.toString()); + + assertTrue(log.toString().contains("JavaLogger")); + assertTrue(log.toString().contains(JavaLogger.DFLT_CONFIG_PATH)); + if (log.isDebugEnabled()) log.debug("This is 'debug' message."); http://git-wip-us.apache.org/repos/asf/ignite/blob/92042475/modules/core/src/test/java/org/apache/ignite/testframework/junits/logger/GridTestLog4jLogger.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/logger/GridTestLog4jLogger.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/logger/GridTestLog4jLogger.java index 52813b9..2ac32ce 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/logger/GridTestLog4jLogger.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/logger/GridTestLog4jLogger.java @@ -96,12 +96,14 @@ public class GridTestLog4jLogger implements IgniteLogger, LoggerNodeIdAware { private Logger impl; /** Path to configuration file. */ - private final String path; + @GridToStringExclude + private final String cfg; /** Quiet flag. */ private final boolean quiet; /** Node ID. */ + @GridToStringExclude private UUID nodeId; /** @@ -140,7 +142,7 @@ public class GridTestLog4jLogger implements IgniteLogger, LoggerNodeIdAware { else quiet = true; - path = null; + cfg = null; } /** @@ -148,11 +150,9 @@ public class GridTestLog4jLogger implements IgniteLogger, LoggerNodeIdAware { * * @param impl Log4j implementation to use. */ - public GridTestLog4jLogger(final Logger impl) { + protected GridTestLog4jLogger(final Logger impl) { assert impl != null; - path = null; - addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() { @Override public Logger apply(Boolean init) { return impl; @@ -160,6 +160,7 @@ public class GridTestLog4jLogger implements IgniteLogger, LoggerNodeIdAware { }); quiet = quiet0; + cfg = null; } /** @@ -172,7 +173,7 @@ public class GridTestLog4jLogger implements IgniteLogger, LoggerNodeIdAware { if (path == null) throw new IgniteCheckedException("Configuration XML file for Log4j must be specified."); - this.path = path; + this.cfg = path; final URL cfgUrl = U.resolveIgniteUrl(path); @@ -204,12 +205,12 @@ public class GridTestLog4jLogger implements IgniteLogger, LoggerNodeIdAware { if (!cfgFile.exists() || cfgFile.isDirectory()) throw new IgniteCheckedException("Log4j configuration path was not found or is a directory: " + cfgFile); - path = cfgFile.getAbsolutePath(); + cfg = cfgFile.getAbsolutePath(); addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() { @Override public Logger apply(Boolean init) { if (init) - DOMConfigurator.configure(path); + DOMConfigurator.configure(cfg); return Logger.getRootLogger(); } @@ -228,7 +229,7 @@ public class GridTestLog4jLogger implements IgniteLogger, LoggerNodeIdAware { if (cfgUrl == null) throw new IgniteCheckedException("Configuration XML file for Log4j must be specified."); - path = null; + cfg = cfgUrl.getPath(); addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() { @Override public Logger apply(Boolean init) { @@ -519,6 +520,6 @@ public class GridTestLog4jLogger implements IgniteLogger, LoggerNodeIdAware { /** {@inheritDoc} */ @Override public String toString() { - return S.toString(GridTestLog4jLogger.class, this); + return S.toString(GridTestLog4jLogger.class, this, "config", cfg); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/92042475/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JLogger.java ---------------------------------------------------------------------- diff --git a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JLogger.java b/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JLogger.java index 39a1008..02e7b35 100644 --- a/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JLogger.java +++ b/modules/log4j/src/main/java/org/apache/ignite/logger/log4j/Log4JLogger.java @@ -96,12 +96,14 @@ public class Log4JLogger implements IgniteLogger, LoggerNodeIdAware, Log4jFileAw private Logger impl; /** Path to configuration file. */ - private final String path; + @GridToStringExclude + private final String cfg; /** Quiet flag. */ private final boolean quiet; /** Node ID. */ + @GridToStringExclude private UUID nodeId; /** @@ -140,7 +142,7 @@ public class Log4JLogger implements IgniteLogger, LoggerNodeIdAware, Log4jFileAw else quiet = true; - path = null; + cfg = null; } /** @@ -151,7 +153,24 @@ public class Log4JLogger implements IgniteLogger, LoggerNodeIdAware, Log4jFileAw public Log4JLogger(final Logger impl) { assert impl != null; - path = null; + addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() { + @Override public Logger apply(Boolean init) { + return impl; + } + }); + + quiet = quiet0; + cfg = null; + } + + /** + * Creates new logger with given implementation. + * + * @param impl Log4j implementation to use. + * @param path Configuration file/url path. + */ + private Log4JLogger(final Logger impl, final String path) { + assert impl != null; addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() { @Override public Logger apply(Boolean init) { @@ -160,6 +179,7 @@ public class Log4JLogger implements IgniteLogger, LoggerNodeIdAware, Log4jFileAw }); quiet = quiet0; + cfg = path; } /** @@ -168,11 +188,11 @@ public class Log4JLogger implements IgniteLogger, LoggerNodeIdAware, Log4jFileAw * @param path Path to log4j configuration XML file. * @throws IgniteCheckedException Thrown in case logger can't be created. */ - public Log4JLogger(String path) throws IgniteCheckedException { + public Log4JLogger(final String path) throws IgniteCheckedException { if (path == null) throw new IgniteCheckedException("Configuration XML file for Log4j must be specified."); - this.path = path; + this.cfg = path; final URL cfgUrl = U.resolveIgniteUrl(path); @@ -204,12 +224,12 @@ public class Log4JLogger implements IgniteLogger, LoggerNodeIdAware, Log4jFileAw if (!cfgFile.exists() || cfgFile.isDirectory()) throw new IgniteCheckedException("Log4j configuration path was not found or is a directory: " + cfgFile); - path = cfgFile.getAbsolutePath(); + cfg = cfgFile.getAbsolutePath(); addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() { @Override public Logger apply(Boolean init) { if (init) - DOMConfigurator.configure(path); + DOMConfigurator.configure(cfg); return Logger.getRootLogger(); } @@ -228,7 +248,7 @@ public class Log4JLogger implements IgniteLogger, LoggerNodeIdAware, Log4jFileAw if (cfgUrl == null) throw new IgniteCheckedException("Configuration XML file for Log4j must be specified."); - path = null; + cfg = cfgUrl.getPath(); addConsoleAppenderIfNeeded(null, new C1<Boolean, Logger>() { @Override public Logger apply(Boolean init) { @@ -448,7 +468,7 @@ public class Log4JLogger implements IgniteLogger, LoggerNodeIdAware, Log4jFileAw @Override public Log4JLogger getLogger(Object ctgr) { return new Log4JLogger(ctgr == null ? Logger.getRootLogger() : ctgr instanceof Class ? Logger.getLogger(((Class<?>)ctgr).getName()) : - Logger.getLogger(ctgr.toString())); + Logger.getLogger(ctgr.toString()), cfg); } /** {@inheritDoc} */ @@ -517,7 +537,7 @@ public class Log4JLogger implements IgniteLogger, LoggerNodeIdAware, Log4jFileAw /** {@inheritDoc} */ @Override public String toString() { - return S.toString(Log4JLogger.class, this); + return S.toString(Log4JLogger.class, this, "config", this.cfg); } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/ignite/blob/92042475/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jCorrectFileNameTest.java ---------------------------------------------------------------------- diff --git a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jCorrectFileNameTest.java b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jCorrectFileNameTest.java index 4672963..ac5b498 100644 --- a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jCorrectFileNameTest.java +++ b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jCorrectFileNameTest.java @@ -18,12 +18,15 @@ package org.apache.ignite.logger.log4j; import java.io.File; +import java.util.Collections; import java.util.Enumeration; import junit.framework.TestCase; import org.apache.ignite.Ignite; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.util.typedef.G; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; import org.apache.ignite.testframework.junits.common.GridCommonTest; import org.apache.log4j.Level; import org.apache.log4j.Logger; @@ -108,6 +111,16 @@ public class GridLog4jCorrectFileNameTest extends TestCase { cfg.setGridLogger(new Log4JLogger()); cfg.setConnectorConfiguration(null); + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder(false); + + ipFinder.setAddresses(Collections.singleton("127.0.0.1:47500..47502")); + + disco.setIpFinder(ipFinder); + + cfg.setDiscoverySpi(disco); + return cfg; } http://git-wip-us.apache.org/repos/asf/ignite/blob/92042475/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jInitializedTest.java ---------------------------------------------------------------------- diff --git a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jInitializedTest.java b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jInitializedTest.java index 94907f0..1fb9c34 100644 --- a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jInitializedTest.java +++ b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jInitializedTest.java @@ -39,7 +39,12 @@ public class GridLog4jInitializedTest extends TestCase { public void testLogInitialize() { IgniteLogger log = new Log4JLogger(); - assert log.isInfoEnabled() == true; + System.out.println(log.toString()); + + assertTrue(log.toString().contains("Log4JLogger")); + assertTrue(log.toString().contains("config=null")); + + assertTrue(log.isInfoEnabled()); if (log.isDebugEnabled()) log.debug("This is 'debug' message."); http://git-wip-us.apache.org/repos/asf/ignite/blob/92042475/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingFileTest.java ---------------------------------------------------------------------- diff --git a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingFileTest.java b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingFileTest.java index e64edd3..d1b09d7 100644 --- a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingFileTest.java +++ b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingFileTest.java @@ -31,9 +31,12 @@ public class GridLog4jLoggingFileTest extends TestCase { /** */ private IgniteLogger log; + /** Logger config */ + private File xml; + /** {@inheritDoc} */ @Override protected void setUp() throws Exception { - File xml = GridTestUtils.resolveIgnitePath("modules/core/src/test/config/log4j-test.xml"); + xml = GridTestUtils.resolveIgnitePath("modules/core/src/test/config/log4j-test.xml"); assert xml != null; assert xml.exists() == true; @@ -45,8 +48,12 @@ public class GridLog4jLoggingFileTest extends TestCase { * Tests log4j logging SPI. */ public void testLog() { - assert log.isDebugEnabled() == true; - assert log.isInfoEnabled() == true; + System.out.println(log.toString()); + + assertTrue(log.toString().contains("Log4JLogger")); + assertTrue(log.toString().contains(xml.getPath())); + + assertTrue(log.isInfoEnabled()); log.debug("This is 'debug' message."); log.info("This is 'info' message."); http://git-wip-us.apache.org/repos/asf/ignite/blob/92042475/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingPathTest.java ---------------------------------------------------------------------- diff --git a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingPathTest.java b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingPathTest.java index 9ab56d5..867efba 100644 --- a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingPathTest.java +++ b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingPathTest.java @@ -29,16 +29,24 @@ public class GridLog4jLoggingPathTest extends TestCase { /** */ private IgniteLogger log; + /** Logger config */ + private String path = "modules/core/src/test/config/log4j-test.xml"; + /** {@inheritDoc} */ @Override protected void setUp() throws Exception { - log = new Log4JLogger("modules/core/src/test/config/log4j-test.xml").getLogger(getClass()); + log = new Log4JLogger(path).getLogger(getClass()); } /** * Tests log4j logging SPI. */ public void testLog() { - assert log.isInfoEnabled() == true; + System.out.println(log.toString()); + + assertTrue(log.toString().contains("Log4JLogger")); + assertTrue(log.toString().contains(path)); + + assertTrue(log.isInfoEnabled()); if (log.isDebugEnabled()) log.debug("This is 'debug' message."); http://git-wip-us.apache.org/repos/asf/ignite/blob/92042475/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingUrlTest.java ---------------------------------------------------------------------- diff --git a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingUrlTest.java b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingUrlTest.java index 9ec695e..1e2e8df 100644 --- a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingUrlTest.java +++ b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jLoggingUrlTest.java @@ -18,6 +18,7 @@ package org.apache.ignite.logger.log4j; import java.io.File; +import java.net.URL; import junit.framework.TestCase; import org.apache.ignite.IgniteLogger; import org.apache.ignite.testframework.GridTestUtils; @@ -31,6 +32,9 @@ public class GridLog4jLoggingUrlTest extends TestCase { /** */ private IgniteLogger log; + /** Logger config */ + private URL url; + /** {@inheritDoc} */ @Override protected void setUp() throws Exception { File xml = GridTestUtils.resolveIgnitePath("modules/core/src/test/config/log4j-test.xml"); @@ -38,15 +42,20 @@ public class GridLog4jLoggingUrlTest extends TestCase { assert xml != null; assert xml.exists(); - log = new Log4JLogger(xml.toURI().toURL()).getLogger(getClass()); + url = xml.toURI().toURL(); + log = new Log4JLogger(url).getLogger(getClass()); } /** * Tests log4j logging SPI. */ public void testLog() { - assert log.isDebugEnabled(); - assert log.isInfoEnabled(); + System.out.println(log.toString()); + + assertTrue(log.toString().contains("Log4JLogger")); + assertTrue(log.toString().contains(url.getPath())); + + assertTrue(log.isInfoEnabled()); log.debug("This is 'debug' message."); log.info("This is 'info' message."); http://git-wip-us.apache.org/repos/asf/ignite/blob/92042475/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jNotInitializedTest.java ---------------------------------------------------------------------- diff --git a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jNotInitializedTest.java b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jNotInitializedTest.java index 390fdcb..d32e890 100644 --- a/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jNotInitializedTest.java +++ b/modules/log4j/src/test/java/org/apache/ignite/logger/log4j/GridLog4jNotInitializedTest.java @@ -30,6 +30,11 @@ public class GridLog4jNotInitializedTest extends TestCase { public void testLogInitialize() { IgniteLogger log = new Log4JLogger().getLogger(GridLog4jNotInitializedTest.class); + System.out.println(log.toString()); + + assertTrue(log.toString().contains("Log4JLogger")); + assertTrue(log.toString().contains("config=null")); + if (log.isDebugEnabled()) log.debug("This is 'debug' message."); else http://git-wip-us.apache.org/repos/asf/ignite/blob/92042475/modules/log4j/src/test/java/org/apache/ignite/testsuites/IgniteLog4jTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/log4j/src/test/java/org/apache/ignite/testsuites/IgniteLog4jTestSuite.java b/modules/log4j/src/test/java/org/apache/ignite/testsuites/IgniteLog4jTestSuite.java index f5f13d9..2c0af79 100644 --- a/modules/log4j/src/test/java/org/apache/ignite/testsuites/IgniteLog4jTestSuite.java +++ b/modules/log4j/src/test/java/org/apache/ignite/testsuites/IgniteLog4jTestSuite.java @@ -20,6 +20,9 @@ package org.apache.ignite.testsuites; import junit.framework.TestSuite; import org.apache.ignite.logger.log4j.GridLog4jCorrectFileNameTest; import org.apache.ignite.logger.log4j.GridLog4jInitializedTest; +import org.apache.ignite.logger.log4j.GridLog4jLoggingFileTest; +import org.apache.ignite.logger.log4j.GridLog4jLoggingPathTest; +import org.apache.ignite.logger.log4j.GridLog4jLoggingUrlTest; import org.apache.ignite.logger.log4j.GridLog4jNotInitializedTest; /** @@ -36,6 +39,9 @@ public class IgniteLog4jTestSuite extends TestSuite { suite.addTest(new TestSuite(GridLog4jInitializedTest.class)); suite.addTest(new TestSuite(GridLog4jNotInitializedTest.class)); suite.addTest(new TestSuite(GridLog4jCorrectFileNameTest.class)); + suite.addTest(new TestSuite(GridLog4jLoggingFileTest.class)); + suite.addTest(new TestSuite(GridLog4jLoggingPathTest.class)); + suite.addTest(new TestSuite(GridLog4jLoggingUrlTest.class)); return suite; } http://git-wip-us.apache.org/repos/asf/ignite/blob/92042475/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 5c92afa..ee5d9a5 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 @@ -26,6 +26,7 @@ import java.util.UUID; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteLogger; import org.apache.ignite.internal.util.tostring.GridToStringExclude; +import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.C1; import org.apache.ignite.internal.util.typedef.internal.A; import org.apache.ignite.internal.util.typedef.internal.S; @@ -100,10 +101,15 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware { @SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized") private Logger impl; + /** Path to configuration file. */ + @GridToStringExclude + private final String cfg; + /** Quiet flag. */ private final boolean quiet; /** Node ID. */ + @GridToStringExclude private volatile UUID nodeId; /** @@ -111,7 +117,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware { * * @param impl Log4j implementation to use. */ - private Log4J2Logger(final Logger impl) { + private Log4J2Logger(final Logger impl, String path) { assert impl != null; addConsoleAppenderIfNeeded(new C1<Boolean, Logger>() { @@ -121,6 +127,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware { }); quiet = quiet0; + cfg = path; } /** @@ -148,6 +155,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware { }); quiet = quiet0; + cfg = path; } /** @@ -175,6 +183,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware { }); quiet = quiet0; + cfg = cfgFile.getPath(); } /** @@ -197,6 +206,7 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware { }); quiet = quiet0; + cfg = cfgUrl.getPath(); } /** @@ -415,17 +425,17 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware { */ @Override public Log4J2Logger getLogger(Object ctgr) { if (ctgr == null) - return new Log4J2Logger((Logger)LogManager.getRootLogger()); + return new Log4J2Logger((Logger)LogManager.getRootLogger(), cfg); if (ctgr instanceof Class) { String name = ((Class<?>)ctgr).getName(); - return new Log4J2Logger((Logger)LogManager.getLogger(name)); + return new Log4J2Logger((Logger)LogManager.getLogger(name), cfg); } String name = ctgr.toString(); - return new Log4J2Logger((Logger)LogManager.getLogger(name)); + return new Log4J2Logger((Logger)LogManager.getLogger(name), cfg); } /** {@inheritDoc} */ @@ -494,6 +504,6 @@ public class Log4J2Logger implements IgniteLogger, LoggerNodeIdAware { /** {@inheritDoc} */ @Override public String toString() { - return S.toString(Log4J2Logger.class, this); + return S.toString(Log4J2Logger.class, this, "config", cfg); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/92042475/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2LoggerSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2LoggerSelfTest.java b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2LoggerSelfTest.java index a5564da..5f3207e 100644 --- a/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2LoggerSelfTest.java +++ b/modules/log4j2/src/test/java/org/apache/ignite/logger/log4j2/Log4j2LoggerSelfTest.java @@ -18,6 +18,7 @@ package org.apache.ignite.logger.log4j2; import java.io.File; +import java.net.URL; import java.util.Collections; import java.util.UUID; import junit.framework.TestCase; @@ -59,6 +60,11 @@ public class Log4j2LoggerSelfTest extends TestCase { IgniteLogger log = new Log4J2Logger(xml).getLogger(getClass()); + System.out.println(log.toString()); + + assertTrue(log.toString().contains("Log4J2Logger")); + assertTrue(log.toString().contains(xml.getPath())); + ((LoggerNodeIdAware)log).setNodeId(UUID.randomUUID()); checkLog(log); @@ -73,7 +79,13 @@ public class Log4j2LoggerSelfTest extends TestCase { assert xml != null; assert xml.exists(); - IgniteLogger log = new Log4J2Logger(xml.toURI().toURL()).getLogger(getClass()); + URL url = xml.toURI().toURL(); + IgniteLogger log = new Log4J2Logger(url).getLogger(getClass()); + + System.out.println(log.toString()); + + assertTrue(log.toString().contains("Log4J2Logger")); + assertTrue(log.toString().contains(url.getPath())); ((LoggerNodeIdAware)log).setNodeId(UUID.randomUUID()); @@ -86,6 +98,11 @@ public class Log4j2LoggerSelfTest extends TestCase { public void testPathConstructor() throws Exception { IgniteLogger log = new Log4J2Logger(LOG_PATH_TEST).getLogger(getClass()); + System.out.println(log.toString()); + + assertTrue(log.toString().contains("Log4J2Logger")); + assertTrue(log.toString().contains(LOG_PATH_TEST)); + ((LoggerNodeIdAware)log).setNodeId(UUID.randomUUID()); checkLog(log); http://git-wip-us.apache.org/repos/asf/ignite/blob/92042475/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 index 2b0e980..2450850 100644 --- 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 @@ -18,6 +18,7 @@ package org.apache.ignite.logger.slf4j; import org.apache.ignite.IgniteLogger; +import org.apache.ignite.internal.util.typedef.internal.S; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -143,4 +144,9 @@ public class Slf4jLogger implements IgniteLogger { @Nullable @Override public String fileName() { return null; } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(Slf4jLogger.class, this); + } } \ No newline at end of file
