public abstract class Logs
extends java.lang.Object
See LDLogAdapter for more about how com.launchdarkly.logging works with
different implementations of logging. The methods and properties in Logs provide
easy access to basic behaviors like logging to the console or to a file, or capturing log
output for testing; if you need to direct the log output to another logging framework that
your application is using, you will use an LDLogAdapter implementation specific
to that framework instead.
| Modifier and Type | Method and Description |
|---|---|
static LDLogAdapter |
basic()
A default implementation that writes to the standard error stream at
LDLogLevel.INFO level. |
static LogCapture |
capture() |
static LDLogAdapter |
level(LDLogAdapter adapter,
LDLogLevel minimumLevel)
Disables log output below the specified level, if allowed by the adapter.
|
static LDLogAdapter |
none()
A stub that generates no log output.
|
static SimpleLogging |
toConsole()
A simple logging implementation that writes to the standard error stream.
|
static LDLogAdapter |
toJavaUtilLogging()
A logging implementation that delegates to the
java.util.logging API. |
static SimpleLogging |
toMethod(SimpleLogging.LineWriter lineWriter)
A simple logging implementation that calls an interface method or lambda that you specify
for each line of output.
|
static LDLogAdapter |
toMultiple(LDLogAdapter... adapters)
A logging implementation that delegates to any number of destinations.
|
static SimpleLogging |
toStream(java.io.PrintStream stream)
A simple logging implementation that writes to any
PrintStream. |
public static LDLogAdapter none()
public static LDLogAdapter level(LDLogAdapter adapter, LDLogLevel minimumLevel)
This is a decorator that can be applied to any LDLogAdapter, either one of
the standard ones available in Logs or a custom implementation, as long as it
is not an implementation such as LDSLF4J where there is another external
mechanism for filtering. Any log messages for a lower level will be immediately
discarded; all others will be forwarded to the underlying logging implementation.
// This one will write all log messages to System.err, including Debug messages
LDLogAdapter unfilteredLogging = Logs.toConsole();
// This one will write only WARN and ERROR messages
LDLogAdapter filteredLogging = Logs.level(Logs.toConsole(), LDLogLevel.WARN);
If applied to an adapter that does have an external configuration mechanism, this has no effect.
adapter - a log adapterminimumLevel - the lowest log level that should be enabledpublic static LDLogAdapter basic()
LDLogLevel.INFO level.public static LogCapture capture()
LogCapture instancepublic static SimpleLogging toConsole()
This is equivalent to toStream(System.err).
By default, all logging is enabled including LDLogLevel.DEBUG level.
To filter by level, use level(LDLogAdapter, LDLogLevel). You can also
use SimpleLogging methods for additional configuration.
public static SimpleLogging toStream(java.io.PrintStream stream)
PrintStream.
This could be a built-in stream such as System.out, or a file.
By default, all logging is enabled including LDLogLevel.DEBUG level.
To filter by level, use level(LDLogAdapter, LDLogLevel). You can also
use SimpleLogging methods for additional configuration.
stream - an output print streampublic static SimpleLogging toMethod(SimpleLogging.LineWriter lineWriter)
By default, all logging is enabled including LDLogLevel.DEBUG level.
To filter by level, use level(LDLogAdapter, LDLogLevel). You can also
use SimpleLogging methods for additional configuration.
lineWriter - a SimpleLogging.LineWriter implementation or lambda
that writes a line of textpublic static LDLogAdapter toJavaUtilLogging()
java.util.logging API.
LDLogLevel levels are mapped to java.util.logging.Level levels
as follows: DEBUG to FINE, INFO to INFO,
WARN to WARNING, and ERROR to SEVERE.
The returned object has no configuration methods; it will use whatever
global configuration is defined by java.util.logging (for instance,
the standard system property java.util.logging.config.file).
In Android, using this method requires Android API 26 or higher.
public static LDLogAdapter toMultiple(LDLogAdapter... adapters)
// Send log output both to System.err and a file
PrintWriter fileWriter = new PrintWriter("output.log");
LDLogAdapter logAdapter = Logs.toMultiple(
Logs.toConsole(),
Logs.toStream(fileWriter)
);
adapters - any number of log adapters