Class LoggingConfigurationBuilder
- java.lang.Object
-
- com.launchdarkly.sdk.server.integrations.LoggingConfigurationBuilder
-
- All Implemented Interfaces:
ComponentConfigurer<LoggingConfiguration>
public abstract class LoggingConfigurationBuilder extends java.lang.Object implements ComponentConfigurer<LoggingConfiguration>
Contains methods for configuring the SDK's logging behavior.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 toLDConfig.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()
.- Since:
- 5.0.0
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
baseName
static java.time.Duration
DEFAULT_LOG_DATA_SOURCE_OUTAGE_AS_ERROR_AFTER
The default value forlogDataSourceOutageAsErrorAfter(Duration)
: one minute.protected LDLogAdapter
logAdapter
protected java.time.Duration
logDataSourceOutageAsErrorAfter
protected LDLogLevel
minimumLevel
-
Constructor Summary
Constructors Constructor Description LoggingConfigurationBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 atERROR
level instead ofWARN
level.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.launchdarkly.sdk.server.subsystems.ComponentConfigurer
build
-
-
-
-
Field Detail
-
DEFAULT_LOG_DATA_SOURCE_OUTAGE_AS_ERROR_AFTER
public static final java.time.Duration DEFAULT_LOG_DATA_SOURCE_OUTAGE_AS_ERROR_AFTER
The default value forlogDataSourceOutageAsErrorAfter(Duration)
: one minute.
-
baseName
protected java.lang.String baseName
-
logDataSourceOutageAsErrorAfter
protected java.time.Duration logDataSourceOutageAsErrorAfter
-
logAdapter
protected LDLogAdapter logAdapter
-
minimumLevel
protected LDLogLevel minimumLevel
-
-
Method Detail
-
adapter
public LoggingConfigurationBuilder adapter(LDLogAdapter logAdapter)
Specifies the implementation of logging to use.The
com.launchdarkly.logging
API defines theLDLogAdapter
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 usesLogs.toConsole()
instead, causing output to go to theSystem.err
stream.You may use the
Logs
factory methods, or a custom implementation, to handle log output differently. For instance, you may specifyLogs.toJavaUtilLogging()
to use thejava.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 usingLoggingConfigurationBuilder
.- Parameters:
logAdapter
- anLDLogAdapter
for the desired logging implementation- Returns:
- the builder
- Since:
- 5.10.0
-
baseLoggerName
public LoggingConfigurationBuilder baseLoggerName(java.lang.String name)
Specifies a custom base logger 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]
.- Parameters:
name
- the base logger name- Returns:
- the builder
- Since:
- 5.10.0
-
-
level
public LoggingConfigurationBuilder level(LDLogLevel minimumLevel)
Specifies the lowest level of logging to enable.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 toLDLogLevel.INFO
means thatDEBUG
-level output is disabled. If not specified, the default minimum level isLDLogLevel.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; callinglevel(LDLogLevel)
in that case has no effect.- Parameters:
minimumLevel
- the lowest level of logging to enable- Returns:
- the builder
- Since:
- 5.10.0
-
logDataSourceOutageAsErrorAfter
public LoggingConfigurationBuilder logDataSourceOutageAsErrorAfter(java.time.Duration logDataSourceOutageAsErrorAfter)
Sets the time threshold, if any, after which the SDK will log a data source outage atERROR
level instead ofWARN
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 atWARN
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 atERROR
level to indicate that this is a sustained problem.The default is
DEFAULT_LOG_DATA_SOURCE_OUTAGE_AS_ERROR_AFTER
. Setting it tonull
will disable this feature, so you will only getWARN
messages.- Parameters:
logDataSourceOutageAsErrorAfter
- the error logging threshold, or null- Returns:
- the builder
-
-