Class Log4J2Logger

  • All Implemented Interfaces:
    IgniteLogger, IgniteLoggerEx

    public class Log4J2Logger
    extends Object
    implements IgniteLoggerEx
    Log4j2-based implementation for logging. This logger should be used by loaders that have prefer log4j2-based logging.

    Here is a typical example of configuring log4j2 logger in Ignite configuration file:

          <property name="gridLogger">
              <bean class="org.apache.ignite.logger.log4j2.Log4J2Logger">
                  <constructor-arg type="java.lang.String" value="config/ignite-log4j.xml"/>
              </bean>
          </property>
     
    and from your code:
          IgniteConfiguration cfg = new IgniteConfiguration();
          ...
          URL xml = U.resolveIgniteUrl("config/custom-log4j2.xml");
          IgniteLogger log = new Log4J2Logger(xml);
          ...
          cfg.setGridLogger(log);
     
    Please take a look at Apache Log4j 2 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

      • Log4J2Logger

        public Log4J2Logger()
        Creates new logger and automatically detects if root logger already has appenders configured. If it does not, the root logger will be configured with default appender, otherwise, existing appenders will be used.
      • Log4J2Logger

        public Log4J2Logger​(String path)
                     throws IgniteCheckedException
        Creates new logger with given configuration path.
        Parameters:
        path - Path to log4j2 configuration XML file.
        Throws:
        IgniteCheckedException - Thrown in case logger can't be created.
      • Log4J2Logger

        public Log4J2Logger​(File cfgFile)
                     throws IgniteCheckedException
        Creates new logger with given configuration cfgFile.
        Parameters:
        cfgFile - Log4j configuration XML file.
        Throws:
        IgniteCheckedException - Thrown in case logger can't be created.
      • Log4J2Logger

        public Log4J2Logger​(URL cfgUrl)
                     throws IgniteCheckedException
        Creates new logger with given configuration cfgUrl.
        Parameters:
        cfgUrl - URL for Log4j configuration XML file.
        Throws:
        IgniteCheckedException - Thrown in case logger can't be created.
    • Method Detail

      • configureConsoleAppender

        public org.apache.logging.log4j.Logger configureConsoleAppender​(boolean clearOutput)
        Creates console appender with some reasonable default logging settings.
        Parameters:
        clearOutput - If true then console output must be configured without any additional info like time, message level, thread info, etc.
        Returns:
        Logger with auto configured console appender.
      • isConfigured

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

        public Log4J2Logger getLogger​(Object ctgr)
        Gets IgniteLogger wrapper around log4j logger for the given category. If category is null, then root logger is returned. If category is an instance of Class then (Class)ctgr).getName() is used as category name.
        Specified by:
        getLogger in interface IgniteLogger
        Parameters:
        ctgr -
        Returns:
        IgniteLogger wrapper around log4j logger.