public class GridLog4jLogger
extends org.gridgain.grid.util.lang.GridMetadataAwareAdapter
implements org.gridgain.grid.logger.GridLogger, org.gridgain.grid.logger.GridLoggerNodeIdAware
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/gridgain-log4j.xml"/>
</bean>
</property>
and from your code:
GridConfiguration cfg = new GridConfiguration();
...
URL xml = U.resolveGridGainUrl("config/custom-log4j.xml");
GridLogger log = new GridLog4jLogger(xml);
...
cfg.setGridLogger(log);
Please take a look at Apache Log4j 1.2
for additional information.
It's recommended to use GridGain logger injection instead of using/instantiating
logger in your task/job code. See GridLoggerResource annotation about logger
injection.
| Constructor and Description |
|---|
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. |
| Modifier and Type | Method and Description |
|---|---|
static void |
addAppender(org.apache.log4j.FileAppender a)
Adds file appender.
|
void |
debug(String msg) |
void |
error(String msg) |
void |
error(String msg,
Throwable e) |
String |
fileName() |
GridLog4jLogger |
getLogger(Object ctgr)
Gets
GridLogger wrapper around log4j logger for the given
category. |
UUID |
getNodeId() |
void |
info(String msg) |
static boolean |
isConfigured()
Checks if Log4j is already configured within this VM or not.
|
boolean |
isDebugEnabled() |
boolean |
isInfoEnabled() |
boolean |
isQuiet() |
boolean |
isTraceEnabled() |
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) |
String |
toString() |
void |
trace(String msg) |
void |
updateFilePath(org.gridgain.grid.lang.GridClosure<String,String> filePathClos)
Sets closure that later evaluate file path.
|
void |
warning(String msg) |
void |
warning(String msg,
Throwable e) |
public GridLog4jLogger()
GridLog4jLogger(boolean)
with parameter true, otherwise, existing appenders will be used (analogous
to calling GridLog4jLogger(boolean)
with parameter false).public GridLog4jLogger(boolean init)
true the Log4j
logger will be initialized with default console appender and INFO
log level.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.public GridLog4jLogger(org.apache.log4j.Logger impl)
impl - Log4j implementation to use.public GridLog4jLogger(String path) throws org.gridgain.grid.GridException
path.path - Path to log4j configuration XML file.org.gridgain.grid.GridException - Thrown in case logger can't be created.public GridLog4jLogger(File cfgFile) throws org.gridgain.grid.GridException
cfgFile.cfgFile - Log4j configuration XML file.org.gridgain.grid.GridException - Thrown in case logger can't be created.public GridLog4jLogger(URL cfgUrl) throws org.gridgain.grid.GridException
cfgUrl.cfgUrl - URL for Log4j configuration XML file.org.gridgain.grid.GridException - Thrown in case logger can't be created.public static boolean isConfigured()
True if log4j was already configured, false otherwise.public void setLevel(org.apache.log4j.Level level)
level - Log level to set.@Nullable public String fileName()
fileName in interface org.gridgain.grid.logger.GridLoggerpublic static void addAppender(org.apache.log4j.FileAppender a)
a - Appender.public static void removeAppender(org.apache.log4j.FileAppender a)
a - Appender.public void setNodeId(UUID nodeId)
setNodeId in interface org.gridgain.grid.logger.GridLoggerNodeIdAwarepublic UUID getNodeId()
getNodeId in interface org.gridgain.grid.logger.GridLoggerNodeIdAwarepublic static Collection<String> logFiles()
public GridLog4jLogger getLogger(Object ctgr)
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.getLogger in interface org.gridgain.grid.logger.GridLoggerctgr - GridLogger wrapper around log4j logger.public void trace(String msg)
trace in interface org.gridgain.grid.logger.GridLoggerpublic void debug(String msg)
debug in interface org.gridgain.grid.logger.GridLoggerpublic void info(String msg)
info in interface org.gridgain.grid.logger.GridLoggerpublic void warning(String msg)
warning in interface org.gridgain.grid.logger.GridLoggerpublic void warning(String msg, @Nullable Throwable e)
warning in interface org.gridgain.grid.logger.GridLoggerpublic void error(String msg)
error in interface org.gridgain.grid.logger.GridLoggerpublic void error(String msg, @Nullable Throwable e)
error in interface org.gridgain.grid.logger.GridLoggerpublic boolean isTraceEnabled()
isTraceEnabled in interface org.gridgain.grid.logger.GridLoggerpublic boolean isDebugEnabled()
isDebugEnabled in interface org.gridgain.grid.logger.GridLoggerpublic boolean isInfoEnabled()
isInfoEnabled in interface org.gridgain.grid.logger.GridLoggerpublic boolean isQuiet()
isQuiet in interface org.gridgain.grid.logger.GridLogger
GridGain Fabric : ver. 6.5.6-p1 Release Date : January 8 2015