public final class TruffleLogger extends Object
The logger's Level
configuration is done using the
Context's options
. The level
option key has the following format: log.languageId.className.level
or
log.instrumentId.className.level
. The value is either the name of pre-defined
Level
constant or a numeric Level
value. If not explicitly set in
Context's options
the level
is inherited from the parent logger.
The TruffleLogger
supports message parameters
of
primitive types and strings. The object parameters are converted into string value before they
are passed to the Handler
.
The TruffleLogger
instances are safe to be used on compiled code paths as well as from
multiple-threads.
Modifier and Type | Method and Description |
---|---|
void |
config(String message)
Logs a message with
config level . |
void |
config(Supplier<String> messageSupplier)
Logs a message with
config level . |
void |
entering(String sourceClass,
String sourceMethod)
Logs entry into method.
|
void |
entering(String sourceClass,
String sourceMethod,
Object parameter)
Logs entry into method with single parameter.
|
void |
entering(String sourceClass,
String sourceMethod,
Object[] parameters)
Logs entry into method with multiple parameters.
|
void |
exiting(String sourceClass,
String sourceMethod)
Logs a return from method.
|
void |
exiting(String sourceClass,
String sourceMethod,
Object result)
Logs a return from method with result.
|
void |
fine(String message)
Logs a message with
fine level . |
void |
fine(Supplier<String> messageSupplier)
Logs a message with
fine level . |
void |
finer(String message)
Logs a message with
finer level . |
void |
finer(Supplier<String> messageSupplier)
Logs a message with
finer level . |
void |
finest(String message)
Logs a message with
finest level . |
void |
finest(Supplier<String> messageSupplier)
Logs a message with
finest level . |
static TruffleLogger |
getLogger(String id)
Find or create a root logger for a given language or instrument.
|
static TruffleLogger |
getLogger(String id,
Class<?> forClass)
Find or create a logger for a given language or instrument class.
|
static TruffleLogger |
getLogger(String id,
String loggerName)
Find or create a logger for a given language or instrument.
|
String |
getName()
Returns the name of the logger.
|
TruffleLogger |
getParent()
Returns the parent
TruffleLogger . |
void |
info(String message)
Logs a message with
info level . |
void |
info(Supplier<String> messageSupplier)
Logs a message with
info level . |
boolean |
isLoggable(Level level)
Checks if a message of the given level would be logged by this logger.
|
void |
log(Level level,
String message)
Logs a message.
|
void |
log(Level level,
String message,
Object parameter)
Logs a message with single parameter.
|
void |
log(Level level,
String message,
Object[] parameters)
Logs a message with multiple parameters.
|
void |
log(Level level,
String message,
Throwable thrown)
Logs a message with an exception.
|
void |
log(Level level,
Supplier<String> messageSupplier)
Logs a message.
|
void |
log(Level level,
Throwable thrown,
Supplier<String> messageSupplier)
Logs a message with an exception.
|
void |
logp(Level level,
String sourceClass,
String sourceMethod,
String message)
Logs a message, specifying source class and source method.
|
void |
logp(Level level,
String sourceClass,
String sourceMethod,
String message,
Object parameter)
Logs a message with single parameter, specifying source class and source method.
|
void |
logp(Level level,
String sourceClass,
String sourceMethod,
String message,
Object[] parameters)
Log a message with multiple parameters, specifying source class and source method.
|
void |
logp(Level level,
String sourceClass,
String sourceMethod,
String message,
Throwable thrown)
Logs a message with an exception, specifying source class and source method.
|
void |
logp(Level level,
String sourceClass,
String sourceMethod,
Supplier<String> messageSupplier)
Logs a message, specifying source class and source method.
|
void |
logp(Level level,
String sourceClass,
String sourceMethod,
Throwable thrown,
Supplier<String> messageSupplier)
Logs a message with an exception, specifying source class and source method.
|
void |
severe(String message)
Logs a message with
severe level . |
void |
severe(Supplier<String> messageSupplier)
Logs a message with
severe level . |
<T extends Throwable> |
throwing(String sourceClass,
String sourceMethod,
T thrown)
Logs throwing an exception.
|
void |
warning(String message)
Logs a message with
warning level . |
void |
warning(Supplier<String> messageSupplier)
Logs a message with
warning level . |
public static TruffleLogger getLogger(String id)
id
- the unique id of language or instrumentTruffleLogger
NullPointerException
- if id
is nullIllegalArgumentException
- if id
is not a valid language or instrument id.public static TruffleLogger getLogger(String id, Class<?> forClass)
id
- the unique id of language or instrumentforClass
- the Class
to create a logger forTruffleLogger
NullPointerException
- if id
or forClass
is nullIllegalArgumentException
- if id
is not a valid language or instrument id.public static TruffleLogger getLogger(String id, String loggerName)
id
- the unique id of language or instrumentloggerName
- the the name of a TruffleLogger
, if a loggerName
is null or
empty a root logger for language or instrument is returnedTruffleLogger
NullPointerException
- if id
is nullIllegalArgumentException
- if id
is not a valid language or instrument id.public void config(String message)
config level
.
If the logger is enabled for the config level
the message is sent to the
Handler
registered in the current Context
.
message
- the message to logpublic void config(Supplier<String> messageSupplier)
config level
. The message is constructed only when
the logger is enabled for the config level
.
If the logger is enabled for the config level
the message is sent to the
Handler
registered in the current Context
.
messageSupplier
- the Supplier
called to produce the message to logpublic void entering(String sourceClass, String sourceMethod)
This method can be used to log entry into a method. A LogRecord
with message "ENTRY"
and the given sourceMethod
and sourceClass
is logged with finer level
.
sourceClass
- the entered classsourceMethod
- the entered methodpublic void entering(String sourceClass, String sourceMethod, Object parameter)
This method can be used to log entry into a method. A LogRecord
with message "ENTRY",
the given sourceMethod
and sourceClass
and given parameter is logged with
finer level
.
sourceClass
- the entered classsourceMethod
- the entered methodparameter
- the method parameterpublic void entering(String sourceClass, String sourceMethod, Object[] parameters)
This method can be used to log entry into a method. A LogRecord
with message "ENTRY",
the given sourceMethod
and sourceClass
and given parameters is logged with
finer level
.
sourceClass
- the entered classsourceMethod
- the entered methodparameters
- the method parameterspublic void exiting(String sourceClass, String sourceMethod)
This method can be used to log return from a method. A LogRecord
with message
"RETURN" and the given sourceMethod
and sourceClass
is logged with
finer level
.
sourceClass
- the exiting classsourceMethod
- the exiting methodpublic void exiting(String sourceClass, String sourceMethod, Object result)
This method can be used to log return from a method. A LogRecord
with message
"RETURN", the given sourceMethod
and sourceClass
and method result is logged
with finer level
.
sourceClass
- the exiting classsourceMethod
- the exiting methodresult
- the return valuepublic void fine(String message)
fine level
.
If the logger is enabled for the fine level
the message is sent to the
Handler
registered in the current Context
.
message
- the message to logpublic void fine(Supplier<String> messageSupplier)
fine level
. The message is constructed only when the
logger is enabled for the fine level
.
If the logger is enabled for the fine level
the message is sent to the
Handler
registered in the current Context
.
messageSupplier
- the Supplier
called to produce the message to logpublic void finer(String message)
finer level
.
If the logger is enabled for the finer level
the message is sent to the
Handler
registered in the current Context
.
message
- the message to logpublic void finer(Supplier<String> messageSupplier)
finer level
. The message is constructed only when the
logger is enabled for the finer level
.
If the logger is enabled for the finer level
the message is sent to the
Handler
registered in the current Context
.
messageSupplier
- the Supplier
called to produce the message to logpublic void finest(String message)
finest level
.
If the logger is enabled for the finest level
the message is sent to the
Handler
registered in the current Context
.
message
- the message to logpublic void finest(Supplier<String> messageSupplier)
finest level
. The message is constructed only when
the logger is enabled for the finest level
.
If the logger is enabled for the finest level
the message is sent to the
Handler
registered in the current Context
.
messageSupplier
- the Supplier
called to produce the message to logpublic void info(String message)
info level
.
If the logger is enabled for the info level
the message is sent to the
Handler
registered in the current Context
.
message
- the message to logpublic void info(Supplier<String> messageSupplier)
info level
. The message is constructed only when the
logger is enabled for the info level
.
If the logger is enabled for the info level
the message is sent to the
Handler
registered in the current Context
.
messageSupplier
- the Supplier
called to produce the message to logpublic void severe(String message)
severe level
.
If the logger is enabled for the severe level
the message is sent to the
Handler
registered in the current Context
.
message
- the message to logpublic void severe(Supplier<String> messageSupplier)
severe level
. The message is constructed only when
the logger is enabled for the severe level
.
If the logger is enabled for the severe level
the message is sent to the
Handler
registered in the current Context
.
messageSupplier
- the Supplier
called to produce the message to logpublic <T extends Throwable> T throwing(String sourceClass, String sourceMethod, T thrown)
This method can be used to log exception thrown from a method. A LogRecord
with
message "THROW",the given sourceMethod
and sourceClass
and thrown
is
logged with finer level
.
sourceClass
- the class throwing an exceptionsourceMethod
- the method throwing an exceptionthrown
- the thrown exceptionpublic void warning(String message)
warning level
.
If the logger is enabled for the warning level
the message is sent to
the Handler
registered in the current Context
.
message
- the message to logpublic void warning(Supplier<String> messageSupplier)
warning level
. The message is constructed only when
the logger is enabled for the warning level
.
If the logger is enabled for the warning level
the message is sent to
the Handler
registered in the current Context
.
messageSupplier
- the Supplier
called to produce the message to logpublic void log(Level level, String message)
If the logger is enabled for the given level
the message is sent to the
Handler
registered in the current Context
.
level
- the required Level
message
- the message to logpublic void log(Level level, String message, Object parameter)
If the logger is enabled for the given level
the message is sent to the
Handler
registered in the current Context
.
level
- the required Level
message
- the message to logparameter
- the log message parameterpublic void log(Level level, String message, Object[] parameters)
If the logger is enabled for the given level
the message is sent to the
Handler
registered in the current Context
.
level
- the required Level
message
- the message to logparameters
- the log message parameterspublic void log(Level level, String message, Throwable thrown)
If the logger is enabled for the given level
the message is sent to the
Handler
registered in the current Context
.
level
- the required Level
message
- the message to logthrown
- the exception to logpublic void logp(Level level, String sourceClass, String sourceMethod, String message)
If the logger is enabled for the given level
the message is sent to the
Handler
registered in the current Context
.
level
- the required Level
sourceClass
- the class issued the logging requestsourceMethod
- the method issued the logging requestmessage
- the message to logpublic void logp(Level level, String sourceClass, String sourceMethod, Supplier<String> messageSupplier)
public void logp(Level level, String sourceClass, String sourceMethod, String message, Object parameter)
If the logger is enabled for the given level
the message is sent to the
Handler
registered in the current Context
.
level
- the required Level
sourceClass
- the class issued the logging requestsourceMethod
- the method issued the logging requestmessage
- the message to logparameter
- the log message parameterpublic void logp(Level level, String sourceClass, String sourceMethod, String message, Object[] parameters)
If the logger is enabled for the given level
the message is sent to the
Handler
registered in the current Context
.
level
- the required Level
sourceClass
- the class issued the logging requestsourceMethod
- the method issued the logging requestmessage
- the message to logparameters
- the log message parameterspublic void logp(Level level, String sourceClass, String sourceMethod, String message, Throwable thrown)
If the logger is enabled for the given level
the message is sent to the
Handler
registered in the current Context
.
level
- the required Level
sourceClass
- the class issued the logging requestsourceMethod
- the method issued the logging requestmessage
- the message to logthrown
- the exception to logpublic void logp(Level level, String sourceClass, String sourceMethod, Throwable thrown, Supplier<String> messageSupplier)
public String getName()
public TruffleLogger getParent()
TruffleLogger
.TruffleLogger
or null when the TruffleLogger
has no
parent.public boolean isLoggable(Level level)
level
- the required logging level