public class Log4JLogger extends Object implements IgniteLogger, LoggerNodeIdAndApplicationAware
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.
DEV_ONLY
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 . |
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 |
setApplicationAndNode(@Nullable String application,
UUID nodeId)
Sets application name and node ID.
|
void |
setLevel(org.apache.log4j.Level level)
Sets level for internal log4j implementation.
|
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
setNodeId
public Log4JLogger()
Log4JLogger(boolean)
with parameter true
, otherwise, existing appenders will be used (analogous
to calling Log4JLogger(boolean)
with parameter false
).public Log4JLogger(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{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.public Log4JLogger(org.apache.log4j.Logger impl)
impl
- Log4j implementation to use.public Log4JLogger(String path) throws IgniteCheckedException
path
.
Calling this constructor is equivalent to calling Log4JLogger(path, FileWatchdog.DEFAULT_DELAY
.path
- Path to log4j configuration XML file.IgniteCheckedException
- Thrown in case logger can't be created.public Log4JLogger(String path, long watchDelay) throws IgniteCheckedException
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.
path
- Path to log4j configuration XML file.watchDelay
- delay in milliseconds used to check configuration file for changes.IgniteCheckedException
- Thrown in case logger can't be created.public Log4JLogger(File cfgFile) throws IgniteCheckedException
cfgFile
.
Calling this constructor is equivalent to calling Log4JLogger(cfgFile, FileWatchdog.DEFAULT_DELAY
.cfgFile
- Log4j configuration XML file.IgniteCheckedException
- Thrown in case logger can't be created.public Log4JLogger(File cfgFile, long watchDelay) throws IgniteCheckedException
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.
cfgFile
- Log4j configuration XML file.watchDelay
- delay in milliseconds used to check configuration file for changes.IgniteCheckedException
- Thrown in case logger can't be created.public Log4JLogger(URL cfgUrl) throws IgniteCheckedException
cfgUrl
.
Calling this constructor is equivalent to calling Log4JLogger(cfgUrl, FileWatchdog.DEFAULT_DELAY
.cfgUrl
- URL for Log4j configuration XML file.IgniteCheckedException
- Thrown in case logger can't be created.public Log4JLogger(URL cfgUrl, long watchDelay) throws IgniteCheckedException
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.
cfgUrl
- URL for Log4j configuration XML file.watchDelay
- delay in milliseconds used to check configuration file for changes.IgniteCheckedException
- 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 @Nullable String fileName()
null
otherwise.fileName
in interface IgniteLogger
null
otherwise.public static void addAppender(org.apache.log4j.FileAppender a)
a
- Appender.public static void removeAppender(org.apache.log4j.FileAppender a)
a
- Appender.public void setApplicationAndNode(@Nullable @Nullable String application, UUID nodeId)
setApplicationAndNode
in interface LoggerNodeIdAndApplicationAware
application
- Application.nodeId
- Node ID.public UUID getNodeId()
getNodeId
in interface LoggerNodeIdAware
public static Collection<String> logFiles()
public Log4JLogger getLogger(Object ctgr)
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.getLogger
in interface IgniteLogger
ctgr
- Category for new logger.IgniteLogger
wrapper around log4j logger.public void trace(String msg)
trace
in interface IgniteLogger
msg
- Trace message.public void debug(String msg)
debug
in interface IgniteLogger
msg
- Debug message.public void info(String msg)
info
in interface IgniteLogger
msg
- Information message.public void warning(String msg)
warning
in interface IgniteLogger
msg
- Warning message.public void warning(String msg, @Nullable @Nullable Throwable e)
warning
in interface IgniteLogger
msg
- Warning message.e
- Optional exception (can be null
).public void error(String msg)
error
in interface IgniteLogger
msg
- Error message.public void error(String msg, @Nullable @Nullable Throwable e)
error
in interface IgniteLogger
msg
- Error message.e
- Optional exception (can be null
).public boolean isTraceEnabled()
trace
level is enabled.isTraceEnabled
in interface IgniteLogger
true
in case when trace
level is enabled, false
otherwise.public boolean isDebugEnabled()
debug
level is enabled.isDebugEnabled
in interface IgniteLogger
true
in case when debug
level is enabled, false
otherwise.public boolean isInfoEnabled()
info
level is enabled.isInfoEnabled
in interface IgniteLogger
true
in case when info
level is enabled, false
otherwise.public boolean isQuiet()
isQuiet
in interface IgniteLogger
true
"Quiet mode" is enabled, false
otherwisepublic void updateFilePath(IgniteClosure<String,String> filePathClos)
filePathClos
- Closure that generates actual file path.
GridGain In-Memory Computing Platform : ver. 8.9.14 Release Date : November 5 2024