org.apache.ignite.logger.log4j2

## Class Log4J2Logger

- java.lang.Object
- - org.apache.ignite.logger.log4j2.Log4J2Logger

- All Implemented Interfaces:
    IgniteLogger, LoggerNodeIdAware

      public class Log4J2Logger
      extends Object
      implements IgniteLogger, LoggerNodeIdAware

  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-log4j2.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.

- - ### Field Summary

    - ### Fields inherited from interface org.apache.ignite.IgniteLogger

      `DEV_ONLY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Log4J2Logger(File cfgFile)` Creates new logger with given configuration `cfgFile`.
    `Log4J2Logger(String path)` Creates new logger with given configuration `path`.
    `Log4J2Logger(URL cfgUrl)` Creates new logger with given configuration `cfgUrl`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `org.apache.logging.log4j.core.Logger` | `createConsoleLogger()` Creates console appender with some reasonable default logging settings.
    `void` | `debug(String msg)` Logs out debug message.
    `void` | `debug(@Nullable String marker, String msg)` Logs out debug message.
    `void` | `error(@Nullable String marker, String msg, @Nullable Throwable e)` Logs error message with optional exception.
    `void` | `error(String msg, @Nullable Throwable e)` Logs error message with optional exception.
    `@Nullable String` | `fileName()` Gets name of the file being logged to if one is configured or `null` otherwise.
    `Log4J2Logger` | `getLogger(Object ctgr)` Gets `IgniteLogger` wrapper around log4j logger for the given category.
    `UUID` | `getNodeId()` Gets node ID.
    `void` | `info(String msg)` Logs out information message.
    `void` | `info(@Nullable String marker, String msg)` Logs out information message.
    `boolean` | `isDebugEnabled()` Tests whether `debug` level is enabled.
    `boolean` | `isInfoEnabled()` Tests whether `info` level is enabled.
    `boolean` | `isQuiet()` Tests whether Logger is in "Quiet mode".
    `boolean` | `isTraceEnabled()` Tests whether `trace` level is enabled.
    `void` | `setNodeId(UUID nodeId)` Sets node ID.
    `String` | `toString()`
    `void` | `trace(String msg)` Logs out trace message.
    `void` | `trace(@Nullable String marker, String msg)` Logs out trace message.
    `void` | `warning(@Nullable String marker, String msg, @Nullable Throwable e)` Logs out warning message with optional exception.
    `void` | `warning(String msg, @Nullable Throwable e)` Logs out warning message with optional exception.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.apache.ignite.IgniteLogger

      `error, warning`

- - ### Constructor Detail

    - #### 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

    - #### 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.

    - #### createConsoleLogger

          public org.apache.logging.log4j.core.Logger createConsoleLogger()

      Creates console appender with some reasonable default logging settings.
      Returns:
        Logger with auto configured console appender.

    - #### setNodeId

          public void setNodeId(UUID nodeId)

      Sets node ID.
      Specified by:
        `setNodeId` in interface `LoggerNodeIdAware`
      Parameters:
        `nodeId` - Node ID.

    - #### getNodeId

          public UUID getNodeId()

      Gets node ID.
      Specified by:
        `getNodeId` in interface `LoggerNodeIdAware`
      Returns:
        Node ID.

    - #### 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` - Category for new logger.
      Returns:
        `IgniteLogger` wrapper around log4j logger.

    - #### trace

          public void trace(String msg)

      Logs out trace message.
      Specified by:
        `trace` in interface `IgniteLogger`
      Parameters:
        `msg` - Trace message.

    - #### trace

          public void trace(@Nullable
                            @Nullable String marker,
                            String msg)

      Logs out trace message. The default implementation calls `this.trace(msg)`.
      Specified by:
        `trace` in interface `IgniteLogger`
      Parameters:
        `marker` - Name of the marker to be associated with the message.
        `msg` - Trace message.

    - #### debug

          public void debug(String msg)

      Logs out debug message.
      Specified by:
        `debug` in interface `IgniteLogger`
      Parameters:
        `msg` - Debug message.

    - #### debug

          public void debug(@Nullable
                            @Nullable String marker,
                            String msg)

      Logs out debug message. The default implementation calls `this.debug(msg)`.
      Specified by:
        `debug` in interface `IgniteLogger`
      Parameters:
        `marker` - Name of the marker to be associated with the message.
        `msg` - Debug message.

    - #### info

          public void info(String msg)

      Logs out information message.
      Specified by:
        `info` in interface `IgniteLogger`
      Parameters:
        `msg` - Information message.

    - #### info

          public void info(@Nullable
                           @Nullable String marker,
                           String msg)

      Logs out information message. The default implementation calls `this.info(msg)`.
      Specified by:
        `info` in interface `IgniteLogger`
      Parameters:
        `marker` - Name of the marker to be associated with the message.
        `msg` - Information 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`).

    - #### warning

          public void warning(@Nullable
                              @Nullable String marker,
                              String msg,
                              @Nullable
                              @Nullable Throwable e)

      Logs out warning message with optional exception. The default implementation calls `this.warning(msg)`.
      Specified by:
        `warning` in interface `IgniteLogger`
      Parameters:
        `marker` - Name of the marker to be associated with the message.
        `msg` - Warning message.
        `e` - Optional exception (can be `null`).

    - #### 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`).

    - #### error

          public void error(@Nullable
                            @Nullable String marker,
                            String msg,
                            @Nullable
                            @Nullable Throwable e)

      Logs error message with optional exception. The default implementation calls `this.error(msg)`.
      Specified by:
        `error` in interface `IgniteLogger`
      Parameters:
        `marker` - Name of the marker to be associated with the message.
        `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.

    - #### 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

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

2021 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.10.0
Release Date | : March 10 2021