org.apache.ignite.logger.log4j

## Class Log4JLogger

- java.lang.Object
- - org.apache.ignite.logger.log4j.Log4JLogger

- All Implemented Interfaces:
    IgniteLogger, LoggerNodeIdAware

      public class Log4JLogger
      extends Object
      implements IgniteLogger, LoggerNodeIdAware

  Log4j-based implementation for logging. This logger should be used by loaders that have prefer log4j-based logging.

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

            <property name="gridLogger">
                <bean class="org.apache.ignite.logger.log4j.Log4JLogger">
                    <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-log4j.xml");
            IgniteLogger log = new Log4JLogger(xml);
            ...
            cfg.setGridLogger(log);

  Please take a look at Apache Log4j 1.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
    `Log4JLogger()` Creates new logger and automatically detects if root logger already has appenders configured.
    `Log4JLogger(boolean init)` Creates new logger.
    `Log4JLogger(File cfgFile)` Creates new logger with given configuration `cfgFile`.
    `Log4JLogger(File cfgFile, long watchDelay)` Creates new logger with given configuration `cfgFile`.
    `Log4JLogger(org.apache.log4j.Logger impl)` Creates new logger with given implementation.
    `Log4JLogger(String path)` Creates new logger with given configuration `path`.
    `Log4JLogger(String path, long watchDelay)` Creates new logger with given configuration `path`.
    `Log4JLogger(URL cfgUrl)` Creates new logger with given configuration `cfgUrl`.
    `Log4JLogger(URL cfgUrl, long watchDelay)` Creates new logger with given configuration `cfgUrl`.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `addAppender(org.apache.log4j.FileAppender a)` Adds file appender.
    `void` | `debug(String msg)` Logs out debug message.
    `void` | `error(String msg)` Logs out error message.
    `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.
    `Log4JLogger` | `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.
    `static boolean` | `isConfigured()` Checks if Log4j is already configured within this VM or not.
    `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.
    `static Collection<String>` | `logFiles()` Gets files for all registered file appenders.
    `static void` | `removeAppender(org.apache.log4j.FileAppender a)` Removes file appender.
    `void` | `setLevel(org.apache.log4j.Level level)` Sets level for internal log4j implementation.
    `void` | `setNodeId(UUID nodeId)` Sets node ID.
    `String` | `toString()`
    `void` | `trace(String msg)` Logs out trace message.
    `void` | `updateFilePath(IgniteClosure<String,String> filePathClos)` Sets closure that later evaluate file path.
    `void` | `warning(String msg)` Logs out warning message.
    `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

      `debug, error, info, trace, warning`

- - ### Constructor Detail

    - #### Log4JLogger

          public Log4JLogger()

      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 (analogous to calling `Log4JLogger(boolean)` with parameter `true`, otherwise, existing appenders will be used (analogous to calling `Log4JLogger(boolean)` with parameter `false`).

    - #### Log4JLogger

          public Log4JLogger(boolean init)

      Creates new logger. If initialize parameter is `true` the Log4j logger will be initialized with default console appender and `INFO` log level.
      Parameters:
        `init` - If `true`, then a default console appender with following pattern layout will be created: `%d{ISO8601} %-5p [%c{1}] %m%n`. If `false`, then no implicit initialization will take place, and `Log4j` should be configured prior to calling this constructor.

    - #### Log4JLogger

          public Log4JLogger(org.apache.log4j.Logger impl)

      Creates new logger with given implementation.
      Parameters:
        `impl` - Log4j implementation to use.

    - #### Log4JLogger

          public Log4JLogger(String path)
                      throws IgniteCheckedException

      Creates new logger with given configuration `path`. Calling this constructor is equivalent to calling `Log4JLogger(path, FileWatchdog.DEFAULT_DELAY`.
      Parameters:
        `path` - Path to log4j configuration XML file.
      Throws:
        `IgniteCheckedException` - Thrown in case logger can't be created.

    - #### Log4JLogger

          public Log4JLogger(String path,
                             long watchDelay)
                      throws IgniteCheckedException

      Creates new logger with given configuration `path`.

      If `watchDelay` is not zero, created logger will check the configuration file for changes once every `watchDelay` milliseconds, and update its configuration if the file was changed. See `DOMConfigurator.configureAndWatch(String, long)` for details.

      Parameters:
        `path` - Path to log4j configuration XML file.
        `watchDelay` - delay in milliseconds used to check configuration file for changes.
      Throws:
        `IgniteCheckedException` - Thrown in case logger can't be created.

    - #### Log4JLogger

          public Log4JLogger(File cfgFile)
                      throws IgniteCheckedException

      Creates new logger with given configuration `cfgFile`. Calling this constructor is equivalent to calling `Log4JLogger(cfgFile, FileWatchdog.DEFAULT_DELAY`.
      Parameters:
        `cfgFile` - Log4j configuration XML file.
      Throws:
        `IgniteCheckedException` - Thrown in case logger can't be created.

    - #### Log4JLogger

          public Log4JLogger(File cfgFile,
                             long watchDelay)
                      throws IgniteCheckedException

      Creates new logger with given configuration `cfgFile`.

      If `watchDelay` is not zero, created logger will check the configuration file for changes once every `watchDelay` milliseconds, and update its configuration if the file was changed. See `DOMConfigurator.configureAndWatch(String, long)` for details.

      Parameters:
        `cfgFile` - Log4j configuration XML file.
        `watchDelay` - delay in milliseconds used to check configuration file for changes.
      Throws:
        `IgniteCheckedException` - Thrown in case logger can't be created.

    - #### Log4JLogger

          public Log4JLogger(URL cfgUrl)
                      throws IgniteCheckedException

      Creates new logger with given configuration `cfgUrl`. Calling this constructor is equivalent to calling `Log4JLogger(cfgUrl, FileWatchdog.DEFAULT_DELAY`.
      Parameters:
        `cfgUrl` - URL for Log4j configuration XML file.
      Throws:
        `IgniteCheckedException` - Thrown in case logger can't be created.

    - #### Log4JLogger

          public Log4JLogger(URL cfgUrl,
                             long watchDelay)
                      throws IgniteCheckedException

      Creates new logger with given configuration `cfgUrl`.

      If `watchDelay` is not zero, created logger will check the configuration file for changes once every `watchDelay` milliseconds, and update its configuration if the file was changed. See `DOMConfigurator.configureAndWatch(String, long)` for details.

      Parameters:
        `cfgUrl` - URL for Log4j configuration XML file.
        `watchDelay` - delay in milliseconds used to check configuration file for changes.
      Throws:
        `IgniteCheckedException` - Thrown in case logger can't be created.

  - ### Method Detail

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

    - #### setLevel

          public void setLevel(org.apache.log4j.Level level)

      Sets level for internal log4j implementation.
      Parameters:
        `level` - Log level to set.

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

    - #### addAppender

          public static void addAppender(org.apache.log4j.FileAppender a)

      Adds file appender.
      Parameters:
        `a` - Appender.

    - #### removeAppender

          public static void removeAppender(org.apache.log4j.FileAppender a)

      Removes file appender.
      Parameters:
        `a` - 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.

    - #### logFiles

          public static Collection<String> logFiles()

      Gets files for all registered file appenders.
      Returns:
        List of files.

    - #### getLogger

          public Log4JLogger 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.

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

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

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

    - #### updateFilePath

          public void updateFilePath(IgniteClosure<String,String> filePathClos)

      Sets closure that later evaluate file path.
      Parameters:
        `filePathClos` - Closure that generates actual file path.

2020 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.9.0
Release Date | : October 15 2020