public abstract class LoggingConfigurationBuilder extends java.lang.Object implements ComponentConfigurer<LoggingConfiguration>
If you want to set non-default values for any of these properties, create a builder with
Components.logging()
, change its properties with the methods of this class, and pass it
to LDConfig.Builder.logging(ComponentConfigurer)
:
LDConfig config = new LDConfig.Builder()
.logging(
Components.logging()
.logDataSourceOutageAsErrorAfter(Duration.ofSeconds(120))
)
.build();
Note that this class is abstract; the actual implementation is created by calling Components.logging()
.
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
baseName |
static java.time.Duration |
DEFAULT_LOG_DATA_SOURCE_OUTAGE_AS_ERROR_AFTER
The default value for
logDataSourceOutageAsErrorAfter(Duration) : one minute. |
protected LDLogAdapter |
logAdapter |
protected java.time.Duration |
logDataSourceOutageAsErrorAfter |
protected LDLogLevel |
minimumLevel |
Constructor and Description |
---|
LoggingConfigurationBuilder() |
Modifier and Type | Method and Description |
---|---|
LoggingConfigurationBuilder |
adapter(LDLogAdapter logAdapter)
Specifies the implementation of logging to use.
|
LoggingConfigurationBuilder |
baseLoggerName(java.lang.String name)
Specifies a custom base logger name.
|
LoggingConfigurationBuilder |
level(LDLogLevel minimumLevel)
Specifies the lowest level of logging to enable.
|
LoggingConfigurationBuilder |
logDataSourceOutageAsErrorAfter(java.time.Duration logDataSourceOutageAsErrorAfter)
Sets the time threshold, if any, after which the SDK will log a data source outage at
ERROR
level instead of WARN level. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
build
public static final java.time.Duration DEFAULT_LOG_DATA_SOURCE_OUTAGE_AS_ERROR_AFTER
logDataSourceOutageAsErrorAfter(Duration)
: one minute.protected java.lang.String baseName
protected java.time.Duration logDataSourceOutageAsErrorAfter
protected LDLogAdapter logAdapter
protected LDLogLevel minimumLevel
public LoggingConfigurationBuilder adapter(LDLogAdapter logAdapter)
The com.launchdarkly.logging
API defines the LDLogAdapter
interface to specify where log output should be sent.
The default logging destination, if no adapter is specified, depends on whether
SLF4J is present in the classpath. If it is, then the SDK uses
LDSLF4J.adapter()
, causing output to go to SLF4J; what happens to
the output then is determined by the SLF4J configuration. If SLF4J is not present in the classpath,
the SDK uses Logs.toConsole()
instead, causing output to go to the System.err
stream.
You may use the Logs
factory methods, or a custom implementation,
to handle log output differently. For instance, you may specify
Logs.toJavaUtilLogging()
to use the java.util.logging
framework.
For more about logging adapters,
see the SDK reference guide
and the API documentation for
com.launchdarkly.logging
.
If you don't need to customize any options other than the adapter, you can call
Components.logging(LDLogAdapter)
as a shortcut rather than using
LoggingConfigurationBuilder
.
logAdapter
- an LDLogAdapter
for the desired logging implementationpublic LoggingConfigurationBuilder baseLoggerName(java.lang.String name)
Logger names are used to give context to the log output, indicating that it is from the LaunchDarkly SDK instead of another component, or indicating a more specific area of functionality within the SDK. Many logging implementations show the logger name in in brackets, for instance:
[com.launchdarkly.sdk.LDClient] INFO: Reconnected to LaunchDarkly stream
If you are using an adapter for a third-party logging framework such as SLF4J (see
adapter(LDLogAdapter)
), most frameworks have a mechanism for filtering log
output by the logger name.
By default, the SDK uses a base logger name of com.launchdarkly.sdk.LDClient
.
Messages will be logged either under this name, or with a suffix to indicate what
general area of functionality is involved:
.DataSource
: problems or status messages regarding how the SDK gets
feature flag data from LaunchDarkly. .DataStore
: problems or status messages regarding how the SDK stores its
feature flag data (for instance, if you are using a database). .Evaluation
: problems in evaluating a feature flag or flags, which were
caused by invalid flag data or incorrect usage of the SDK rather than for instance a
database problem. .Events
problems or status messages regarding the SDK's delivery of
analytics event data to LaunchDarkly.
Setting baseLoggerName(String)
to a non-null value overrides the default. The
SDK still adds the same suffixes to the name, so for instance if you set it to
"LD"
, the example message above would show [LD.DataSource]
.
name
- the base logger namepublic LoggingConfigurationBuilder level(LDLogLevel minimumLevel)
This is only applicable when using an implementation of logging that does not have its own
external configuration mechanism, such as Logs.toConsole()
. It adds a log level filter
so that log messages at lower levels are suppressed. For instance, setting the minimum level to
LDLogLevel.INFO
means that DEBUG
-level output is disabled. If not specified,
the default minimum level is LDLogLevel.INFO
.
When using a logging framework like SLF4J or java.util.logging
that has its own
separate mechanism for log filtering, you must use that framework's configuration options for
log levels; calling level(LDLogLevel)
in that case has no effect.
minimumLevel
- the lowest level of logging to enablepublic LoggingConfigurationBuilder logDataSourceOutageAsErrorAfter(java.time.Duration logDataSourceOutageAsErrorAfter)
ERROR
level instead of WARN
level.
A data source outage means that an error condition, such as a network interruption or an error from
the LaunchDarkly service, is preventing the SDK from receiving feature flag updates. Many outages are
brief and the SDK can recover from them quickly; in that case it may be undesirable to log an
ERROR
line, which might trigger an unwanted automated alert depending on your monitoring
tools. So, by default, the SDK logs such errors at WARN
level. However, if the amount of time
specified by this method elapses before the data source starts working again, the SDK will log an
additional message at ERROR
level to indicate that this is a sustained problem.
The default is DEFAULT_LOG_DATA_SOURCE_OUTAGE_AS_ERROR_AFTER
. Setting it to null
will disable this feature, so you will only get WARN
messages.
logDataSourceOutageAsErrorAfter
- the error logging threshold, or null