Class JavaLogger

  • All Implemented Interfaces:
    IgniteLogger, org.apache.ignite.internal.logger.IgniteLoggerEx

    public class JavaLogger
    extends Object
    implements org.apache.ignite.internal.logger.IgniteLoggerEx
    Logger to use with Java logging. Implementation simply delegates to Java Logging.

    Here is an example of configuring Java logger in Ignite configuration Spring file to work over log4j implementation. Note that we use the same configuration file as we provide by default:

          ...
          <property name="gridLogger">
              <bean class="org.apache.ignite.logger.java.JavaLogger">
                  <constructor-arg type="java.util.logging.Logger">
                      <bean class="java.util.logging.Logger">
                          <constructor-arg type="java.lang.String" value="global"/>
                      </bean>
                  </constructor-arg>
              </bean>
          </property>
          ...
     
    or
          ...
          <property name="gridLogger">
              <bean class="org.apache.ignite.logger.java.JavaLogger"/>
          </property>
          ...
     
    And the same configuration if you'd like to configure Ignite in your code:
          IgniteConfiguration cfg = new IgniteConfiguration();
          ...
          IgniteLogger log = new JavaLogger(Logger.global);
          ...
          cfg.setGridLogger(log);
     
    or which is actually the same:
          IgniteConfiguration cfg = new IgniteConfiguration();
          ...
          IgniteLogger log = new JavaLogger();
          ...
          cfg.setGridLogger(log);
     
    Please take a look at Logger javadoc for additional information.

    It's recommended to use Ignite logger injection instead of using/instantiating logger in your task/job code. See LoggerResource annotation about logger injection.

    • Constructor Detail

      • JavaLogger

        public JavaLogger()
        Creates new logger.
      • JavaLogger

        public JavaLogger​(boolean init)
        Creates new logger.
        Parameters:
        init - If true, then a default console appender will be created. If false, then no implicit initialization will take place, and java logger should be configured prior to calling this constructor.
      • JavaLogger

        public JavaLogger​(Logger impl,
                          boolean configure)
        Creates new logger with given implementation.
        Parameters:
        impl - Java Logging implementation to use.
        configure - Configure logger.
    • Method Detail

      • isConfigured

        public static boolean isConfigured()
        Checks if logger is already configured within this VM or not.
        Returns:
        True if logger was already configured, false otherwise.
      • getLogger

        public IgniteLogger getLogger​(Object ctgr)
        Creates new logger with given category based off the current instance.
        Specified by:
        getLogger in interface IgniteLogger
        Parameters:
        ctgr - Category for new logger.
        Returns:
        New logger with given category.
      • trace

        public void trace​(String msg)
        Logs out trace message.
        Specified by:
        trace in interface IgniteLogger
        Parameters:
        msg - Trace message.
      • debug

        public void debug​(String msg)
        Logs out debug message.
        Specified by:
        debug in interface IgniteLogger
        Parameters:
        msg - Debug message.
      • info

        public void info​(String msg)
        Logs out information message.
        Specified by:
        info in interface IgniteLogger
        Parameters:
        msg - Information message.
      • warning

        public void warning​(String msg)
        Logs out warning message.
        Specified by:
        warning in interface IgniteLogger
        Parameters:
        msg - Warning message.
      • warning

        public void warning​(String msg,
                            @Nullable
                            @Nullable Throwable e)
        Logs out warning message with optional exception.
        Specified by:
        warning in interface IgniteLogger
        Parameters:
        msg - Warning message.
        e - Optional exception (can be null).
      • error

        public void error​(String msg)
        Logs out error message.
        Specified by:
        error in interface IgniteLogger
        Parameters:
        msg - Error message.
      • isQuiet

        public boolean isQuiet()
        Tests whether Logger is in "Quiet mode".
        Specified by:
        isQuiet in interface IgniteLogger
        Returns:
        true "Quiet mode" is enabled, false otherwise
      • error

        public void error​(String msg,
                          @Nullable
                          @Nullable Throwable e)
        Logs error message with optional exception.
        Specified by:
        error in interface IgniteLogger
        Parameters:
        msg - Error message.
        e - Optional exception (can be null).
      • isTraceEnabled

        public boolean isTraceEnabled()
        Tests whether trace level is enabled.
        Specified by:
        isTraceEnabled in interface IgniteLogger
        Returns:
        true in case when trace level is enabled, false otherwise.
      • isDebugEnabled

        public boolean isDebugEnabled()
        Tests whether debug level is enabled.
        Specified by:
        isDebugEnabled in interface IgniteLogger
        Returns:
        true in case when debug level is enabled, false otherwise.
      • isInfoEnabled

        public boolean isInfoEnabled()
        Tests whether info level is enabled.
        Specified by:
        isInfoEnabled in interface IgniteLogger
        Returns:
        true in case when info level is enabled, false otherwise.
      • fileName

        @Nullable
        public @Nullable String fileName()
        Gets name of the file being logged to if one is configured or null otherwise.
        Specified by:
        fileName in interface IgniteLogger
        Returns:
        Name of the file being logged to if one is configured or null otherwise.
      • addConsoleAppender

        public void addConsoleAppender​(boolean clearOutput)
        Adds console appender to the logger.
        Specified by:
        addConsoleAppender in interface org.apache.ignite.internal.logger.IgniteLoggerEx
        Parameters:
        clearOutput - If true then console output must be configured without any additional info like time, message level, thread info, etc.
      • flush

        public void flush()
        Flush any buffered output.
        Specified by:
        flush in interface org.apache.ignite.internal.logger.IgniteLoggerEx
      • setWorkDirectory

        public void setWorkDirectory​(String workDir)
        Set work directory.
        Parameters:
        workDir - Work directory.
      • setApplicationAndNode

        public void setApplicationAndNode​(@Nullable
                                          @Nullable String application,
                                          @Nullable
                                          @Nullable UUID nodeId)
        Sets application name and node ID.
        Specified by:
        setApplicationAndNode in interface org.apache.ignite.internal.logger.IgniteLoggerEx
        Parameters:
        application - Application.
        nodeId - Node ID.