GridGain™ 3.6.0e
Enterprise Edition

org.gridgain.grid.logger.log4j
Class GridLog4jLogger

java.lang.Object
  extended by org.gridgain.grid.lang.GridMetadataAwareAdapter
      extended by org.gridgain.grid.logger.log4j.GridLog4jLogger
All Implemented Interfaces:
Serializable, Cloneable, GridMetadataAware, GridLogger

public class GridLog4jLogger
extends GridMetadataAwareAdapter
implements GridLogger

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 GridGain configuration file:

      <property name="gridLogger">
          <bean class="org.gridgain.grid.logger.log4j.GridLog4jLogger">
              <constructor-arg type="java.lang.String" value="config/default-log4j.xml"/>
          </bean>
      </property>
 
and from your code:
      GridConfiguration cfg = new GridConfigurationAdapter();
      ...
      URL xml = U.resolveGridGainUrl("modules/tests/config/log4j-test.xml");
      GridLogger log = new GridLog4jLogger(xml);
      ...
      cfg.setGridLogger(log);
 
Please take a look at GridLoggerResource annotation about logger injection.

Wiki & Forum:


Wiki
Forum

See Also:
Serialized Form
 

Constructor Summary
GridLog4jLogger()
          Creates new logger and automatically detects if root logger already has appenders configured.
GridLog4jLogger(boolean init)
          Creates new logger.
GridLog4jLogger(File cfgFile)
          Creates new logger with given configuration cfgFile.
GridLog4jLogger(org.apache.log4j.Logger impl)
          Creates new logger with given implementation.
GridLog4jLogger(String path)
          Creates new logger with given configuration path.
GridLog4jLogger(URL cfgUrl)
          Creates new logger with given configuration cfgUrl.
 
Method Summary
 void debug(String msg)
          Logs out debug message.
 void error(String msg)
          Logs out error message.
 void error(String msg, Throwable e)
          Logs error message with optional exception.
 GridLog4jLogger getLogger(Object ctgr)
          Gets GridLogger wrapper around log4j logger for the given category.
 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 info and debug levels are turned off.
 void setLevel(org.apache.log4j.Level level)
          Sets level for internal log4j implementation.
 String toString()
          
 void warning(String msg)
          Logs out warning message.
 void warning(String msg, Throwable e)
          Logs out warning message with optional exception.
 
Methods inherited from class org.gridgain.grid.lang.GridMetadataAwareAdapter
addMeta, addMetaIfAbsent, addMetaIfAbsent, allMeta, clone, copyMeta, copyMeta, hasMeta, hasMeta, meta, putMetaIfAbsent, putMetaIfAbsent, readExternalMeta, removeMeta, removeMeta, replaceMeta, writeExternalMeta
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.gridgain.grid.GridMetadataAware
addMeta, addMetaIfAbsent, addMetaIfAbsent, allMeta, copyMeta, copyMeta, hasMeta, hasMeta, meta, putMetaIfAbsent, putMetaIfAbsent, removeMeta, removeMeta, replaceMeta
 

Constructor Detail

GridLog4jLogger

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


GridLog4jLogger

public GridLog4jLogger(boolean init)
Creates new logger. If initialize parameter is true the Log4j logger will be initialized with default console appender. In this case the log level will be set to DEBUG if system property GridSystemProperties.GG_DFLT_LOG4J_DEBUG is present with any non-null value, otherwise the log level will be set to INFO.

Parameters:
init - If true, then a default console appender with following pattern layout will be created: %d{ABSOLUTE} %-5p [%c{1}] %m%n. If false, then no implicit initialization will take place, and Log4j should be configured prior to calling this constructor.

GridLog4jLogger

public GridLog4jLogger(org.apache.log4j.Logger impl)
Creates new logger with given implementation.

Parameters:
impl - Log4j implementation to use.

GridLog4jLogger

public GridLog4jLogger(String path)
                throws GridException
Creates new logger with given configuration path.

Throws:
GridException - Thrown in case logger can't be created.
Parameters:
path - Path to log4j configuration XML file.

GridLog4jLogger

public GridLog4jLogger(File cfgFile)
                throws GridException
Creates new logger with given configuration cfgFile.

Throws:
GridException - Thrown in case logger can't be created.
Parameters:
cfgFile - Log4j configuration XML file.

GridLog4jLogger

public GridLog4jLogger(URL cfgUrl)
                throws GridException
Creates new logger with given configuration cfgUrl.

Throws:
GridException - Thrown in case logger can't be created.
Parameters:
cfgUrl - URL for Log4j configuration XML file.
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.

getLogger

public GridLog4jLogger getLogger(Object ctgr)
Gets GridLogger 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 GridLogger
Parameters:
ctgr - Category for new logger.
Returns:
GridLogger wrapper around log4j logger.

debug

public void debug(String msg)
Logs out debug message.

Specified by:
debug in interface GridLogger
Parameters:
msg - Debug message.

info

public void info(String msg)
Logs out information message.

Specified by:
info in interface GridLogger
Parameters:
msg - Information message.

warning

public void warning(String msg)
Logs out warning message.

Specified by:
warning in interface GridLogger
Parameters:
msg - Warning message.

warning

public void warning(String msg,
                    @Nullable
                    Throwable e)
Logs out warning message with optional exception.

Specified by:
warning in interface GridLogger
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 GridLogger
Parameters:
msg - Error message.

error

public void error(String msg,
                  @Nullable
                  Throwable e)
Logs error message with optional exception.

Specified by:
error in interface GridLogger
Parameters:
msg - Error message.
e - Optional exception (can be null).

isDebugEnabled

public boolean isDebugEnabled()
Tests whether debug level is enabled.

Specified by:
isDebugEnabled in interface GridLogger
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 GridLogger
Returns:
true in case when info level is enabled, false otherwise.

isQuiet

public boolean isQuiet()
Tests whether info and debug levels are turned off.

Specified by:
isQuiet in interface GridLogger
Returns:
Whether info and debug levels are turned off.

toString

public String toString()

Overrides:
toString in class Object

GridGain™ 3.6.0e
Enterprise Edition

GridGain - Real Time Big Data
Enterprise Edition, ver. 3.6.0e.13012012
2012 Copyright © GridGain Systems
Follow us:   Follow GridGain on Github Follow GridGain on Facebook Join GridGain User Group Follow GridGain on Twitter Follow GridGain on YouTube