public final class SimpleLogging extends java.lang.Object implements LDLogAdapter
Factory methods for this class are Logs.toStream(PrintStream)
,
Logs.toConsole()
, and Logs.toMethod(SimpleLogging.LineWriter)
.
Currently the output is always in the format "Timestamp [LoggerName] LEVEL: text", or, if a
tag is specified, "Timestamp {Tag} [LoggerName] LEVEL: text". The Timestamp format defaults
to getDefaultTimestampFormat()
but can be customized.
By itself, this class provides no level filtering. You may use
Logs.level(LDLogAdapter, LDLogLevel)
to filter by level, although the LaunchDarkly
SDKs also provide their own configuration syntax for this.
Example of usage in the server-side Java SDK:
LDConfig config = new LDConfig.Builder()
.logging(
Components.logging().adapter(Logs.toStream(System.out))
.Level(LDLogLevel.INFO)
)
.build();
Modifier and Type | Class and Description |
---|---|
static interface |
SimpleLogging.LineWriter
Functional interface for a method or lambda that writes a line of text.
|
LDLogAdapter.Channel
Modifier and Type | Method and Description |
---|---|
static java.text.SimpleDateFormat |
getDefaultTimestampFormat()
The default format for log timestamps.
|
LDLogAdapter.Channel |
newChannel(java.lang.String name)
The logger calls this method to obtain a named output channel.
|
SimpleLogging |
tag(java.lang.String tag)
Specifies an optional tag string to distinguish this from the output of other loggers.
|
SimpleLogging |
timestampFormat(java.text.DateFormat timestampFormat)
Specifies the format for date/timestamps.
|
public static java.text.SimpleDateFormat getDefaultTimestampFormat()
SimpleDateFormat
with the pattern
"yyyy-MM-dd HH:mm:ss.SSS zzz"
.
Because SimpleDateFormat
is not thread-safe, this method always creates a new
instance. We cannot use java.time.DateTimeFormatter
because currently we need
to support Android API versions that do not have java.time
.
public SimpleLogging tag(java.lang.String tag)
This method does not modify the current instance, but returns a new adapter based on this one.
tag
- a string that should appear in log output, or null for nonepublic SimpleLogging timestampFormat(java.text.DateFormat timestampFormat)
getDefaultTimestampFormat()
.
This method does not modify the current instance, but returns a new adapter based on this one.
timestampFormat
- a DateFormat
, or null to omit the date and timepublic LDLogAdapter.Channel newChannel(java.lang.String name)
LDLogAdapter
The name will be included in all log output for this channel. Channels are meant to be
retained and reused by the components they belong to, so the LDLogAdapter
does
not need to cache them.
newChannel
in interface LDLogAdapter
name
- an identifying nameLDLogAdapter.Channel