public final class LDLogger
extends java.lang.Object
The LaunchDarkly SDK sends all of its logging output through this class. What happens
to the output depends on the LDLogAdapter
that has been used to configure the
SDK.
Applications will not normally need to interact with LDLogger
directly. See
the SDK's configuration builder for how to configure logging using a log adapter.
The logger has output methods for each of the levels defined in LDLogLevel
.
For efficiency (to avoid unnecessarily creating varargs arrays), each level has four
methods: one for non-parameterized messages, one for messages with a single parameter,
one for messages with two parameters, and one for messages with an arbitrary number
of parameters.
Parameter substitution uses the syntax defined by SimpleFormat
: the format
string can contain "{}" placeholders, which are replaced by the result of calling
toString()
on the corresponding parameter.
To avoid unnecessary computations, toString()
is not called on parameters
(or, in the single-argument methods, on the single Object
) if logging at
the specified level is disabled.
Modifier and Type | Method and Description |
---|---|
void |
debug(java.lang.Object message)
Writes a message at
LDLogLevel.DEBUG level. |
void |
debug(java.lang.String format,
java.lang.Object... params)
Writes a message at
LDLogLevel.DEBUG level with any number of parameters. |
void |
debug(java.lang.String format,
java.lang.Object param)
Writes a message at
LDLogLevel.DEBUG level with one parameter. |
void |
debug(java.lang.String format,
java.lang.Object param1,
java.lang.Object param2)
Writes a message at
LDLogLevel.DEBUG level with two parameters. |
void |
error(java.lang.Object message)
Writes a message at
LDLogLevel.ERROR level. |
void |
error(java.lang.String format,
java.lang.Object... params)
Writes a message at
LDLogLevel.ERROR level with any number of parameters. |
void |
error(java.lang.String format,
java.lang.Object param)
Writes a message at
LDLogLevel.ERROR level with one parameter. |
void |
error(java.lang.String format,
java.lang.Object param1,
java.lang.Object param2)
Writes a message at
LDLogLevel.ERROR level with two parameters. |
void |
info(java.lang.Object message)
Writes a message at
LDLogLevel.INFO level. |
void |
info(java.lang.String format,
java.lang.Object... params)
Writes a message at
LDLogLevel.INFO level with any number of parameters. |
void |
info(java.lang.String format,
java.lang.Object param)
Writes a message at
LDLogLevel.INFO level with one parameter. |
void |
info(java.lang.String format,
java.lang.Object param1,
java.lang.Object param2)
Writes a message at
LDLogLevel.INFO level with two parameters. |
boolean |
isEnabled(LDLogLevel level)
Tests whether log output for a certain level is at least potentially visible.
|
static LDLogger |
none()
Returns a logger instance that does nothing.
|
LDLogger |
subLogger(java.lang.String nameSuffix)
Returns a logger instance derived from this instance.
|
void |
warn(java.lang.Object message)
Writes a message at
LDLogLevel.WARN level. |
void |
warn(java.lang.String format,
java.lang.Object... params)
Writes a message at
LDLogLevel.WARN level with any number of parameters. |
void |
warn(java.lang.String format,
java.lang.Object param)
Writes a message at
LDLogLevel.WARN level with one parameters. |
void |
warn(java.lang.String format,
java.lang.Object param1,
java.lang.Object param2)
Writes a message at
LDLogLevel.WARN level with two parameters. |
static LDLogger |
withAdapter(LDLogAdapter adapter,
java.lang.String name)
Returns a logger instance using the specified adapter.
|
public static LDLogger withAdapter(LDLogAdapter adapter, java.lang.String name)
adapter
- the LDLogAdapter
that provides the output implementationname
- an identifier for the logger which may be included in outputpublic static LDLogger none()
public LDLogger subLogger(java.lang.String nameSuffix)
nameSuffix
- will be appended to the current logger's name, separated by a
period, to create the new logger's namepublic boolean isEnabled(LDLogLevel level)
Generally, any desired level filtering should be set up in the initial logging
configuration, and code that generates log messages should simply call methods like
info(Object)
without having to know whether that particular level
is enabled or is being filtered out. However, if some kind of log message is
particularly expensive to compute, you may call isEnabled(LDLogLevel)
;
a false value means you can skip trying to log any message at that level.
Another approach is to generate any computationally expensive output lazily, such
as by using the methods in LogValues
.
level
- a log levelpublic void debug(java.lang.Object message)
LDLogLevel.DEBUG
level.message
- the message (will be converted to a string with toString()
)public void debug(java.lang.String format, java.lang.Object param)
LDLogLevel.DEBUG
level with one parameter.format
- the format string, containing "{}" placeholdersparam
- the parameterpublic void debug(java.lang.String format, java.lang.Object param1, java.lang.Object param2)
LDLogLevel.DEBUG
level with two parameters.format
- the format string, containing "{}" placeholdersparam1
- the first parameterparam2
- the second parameterpublic void debug(java.lang.String format, java.lang.Object... params)
LDLogLevel.DEBUG
level with any number of parameters.format
- the format string, containing "{}" placeholdersparams
- the parameterspublic void info(java.lang.Object message)
LDLogLevel.INFO
level.message
- the message (will be converted to a string with toString()
)public void info(java.lang.String format, java.lang.Object param)
LDLogLevel.INFO
level with one parameter.format
- the format string, containing "{}" placeholdersparam
- the parameterpublic void info(java.lang.String format, java.lang.Object param1, java.lang.Object param2)
LDLogLevel.INFO
level with two parameters.format
- the format string, containing "{}" placeholdersparam1
- the first parameterparam2
- the second parameterpublic void info(java.lang.String format, java.lang.Object... params)
LDLogLevel.INFO
level with any number of parameters.format
- the format string, containing "{}" placeholdersparams
- the parameterspublic void warn(java.lang.Object message)
LDLogLevel.WARN
level.message
- the message (will be converted to a string with toString()
)public void warn(java.lang.String format, java.lang.Object param)
LDLogLevel.WARN
level with one parameters.format
- the format string, containing "{}" placeholdersparam
- the parameterpublic void warn(java.lang.String format, java.lang.Object param1, java.lang.Object param2)
LDLogLevel.WARN
level with two parameters.format
- the format string, containing "{}" placeholdersparam1
- the first parameterparam2
- the second parameterpublic void warn(java.lang.String format, java.lang.Object... params)
LDLogLevel.WARN
level with any number of parameters.format
- the format string, containing "{}" placeholdersparams
- the parameterspublic void error(java.lang.Object message)
LDLogLevel.ERROR
level.message
- the message (will be converted to a string with toString()
)public void error(java.lang.String format, java.lang.Object param)
LDLogLevel.ERROR
level with one parameter.format
- the format string, containing "{}" placeholdersparam
- the parameterpublic void error(java.lang.String format, java.lang.Object param1, java.lang.Object param2)
LDLogLevel.ERROR
level with two parameters.format
- the format string, containing "{}" placeholdersparam1
- the first parameterparam2
- the second parameterpublic void error(java.lang.String format, java.lang.Object... params)
LDLogLevel.ERROR
level with any number of parameters.format
- the format string, containing "{}" placeholdersparams
- the parameters