Class LoggingConfigurationBuilder
Contains methods for configuring the SDK's logging behavior.
Inherited Members
Namespace: LaunchDarkly.Sdk.Client.Integrations
Assembly: LaunchDarkly.ClientSdk.dll
Syntax
public sealed class LoggingConfigurationBuilder
Remarks
If you want to set non-default values for any of these properties, create a builder with Logging(), change its properties with the methods of this class, and pass it to Logging(LoggingConfigurationBuilder).
The default behavior, if you do not change any properties, depends on the runtime platform:
- On Android, it uses
android.util.Log
. - On iOS, it uses the Apple
unified logging system
(
OSLog
). - On all other platforms, it writes to Error.
By default, the minimum log level is Info
(that is, Debug
logging is
disabled). This can be overridden with Level(LogLevel).
The base logger name is normally LaunchDarkly.Sdk
(on iOS, this corresponds to a
"subsystem" name of "LaunchDarkly" and a "category" name of "Sdk"). See BaseLoggerName(string)
for more about logger names and how to change the name.
Examples
var config = Configuration.Builder("my-sdk-key")
.Logging(Components.Logging().Level(LogLevel.Warn))
.Build();
Constructors
| Edit this page View SourceLoggingConfigurationBuilder()
Creates a new builder with default properties.
Declaration
public LoggingConfigurationBuilder()
Methods
| Edit this page View SourceAdapter(ILogAdapter)
Specifies the implementation of logging to use.
Declaration
public LoggingConfigurationBuilder Adapter(ILogAdapter adapter)
Parameters
Type | Name | Description |
---|---|---|
ILogAdapter | adapter | an |
Returns
Type | Description |
---|---|
LoggingConfigurationBuilder | the same builder |
Remarks
The LaunchDarkly.Logging
API defines the
ILogAdapter
interface to specify where log output should be sent. By default, it is set to
Logs.ToConsole
, meaning that output will be sent to Console.Error
. You may use other
LaunchDarkly.Logging.Logs
methods, or a custom implementation, to handle log output differently.
Logs.None
disables logging (equivalent to NoLogging).
For more about logging adapters, see the API
documentation for LaunchDarkly.Logging
.
If you don't need to customize any options other than the adapter, you can call Logging(ILogAdapter) as a shortcut rather than using LoggingConfigurationBuilder.
Examples
// This example configures the SDK to send log output to a file writer.
var writer = File.CreateText("sdk.log");
var config = Configuration.Builder("my-sdk-key")
.Logging(Components.Logging().Adapter(Logs.ToWriter(writer)))
.Build();
|
Edit this page
View Source
BaseLoggerName(string)
Specifies a custom base logger name.
Declaration
public LoggingConfigurationBuilder BaseLoggerName(string baseLoggerName)
Parameters
Type | Name | Description |
---|---|---|
string | baseLoggerName |
Returns
Type | Description |
---|---|
LoggingConfigurationBuilder | the same builder |
Remarks
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. The default console logging implementation shows the logger name in brackets, for instance:
[LaunchDarkly.Sdk.DataSource] INFO: Reconnected to LaunchDarkly stream
If you are using an adapter for a third-party logging framework (see Adapter(ILogAdapter)), most frameworks have a mechanism for filtering log output by the logger name.
By default, the SDK uses a base logger name of LaunchDarkly.Sdk
. 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. -
.Events
problems or status messages regarding the SDK's delivery of analytics event data to LaunchDarkly.
Setting BaseLoggerName
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]
.
When using the default logging framework in iOS, logger names are handled slightly
differently because iOS's OSLog
has two kinds of logger names: a general
"subsystem", and a more specific "category". The SDK handles this by taking everything
after the first period in the logger name as the category: for instance, for
LaunchDarkly.Sdk.DataSource
, the subsystem is LaunchDarkly
and the category
is Sdk.DataSource
. If you set a custom base logger name, the same rules apply, so
for instance if you set it to "LD"
then then LD.DataSource
would become
a subsystem of LD
and a category of DataSource
.
CreateLoggingConfiguration()
Called internally by the SDK to create a configuration instance. Applications do not need to call this method.
Declaration
public LoggingConfiguration CreateLoggingConfiguration()
Returns
Type | Description |
---|---|
LoggingConfiguration | the logging configuration |
Level(LogLevel)
Specifies the lowest level of logging to enable.
Declaration
public LoggingConfigurationBuilder Level(LogLevel minimumLevel)
Parameters
Type | Name | Description |
---|---|---|
LogLevel | minimumLevel | the lowest level of logging to enable |
Returns
Type | Description |
---|---|
LoggingConfigurationBuilder | the same builder |
Remarks
This adds a log level filter that is applied regardless of what implementation of logging is
being used, so that log messages at lower levels are suppressed. For instance, setting the
minimum level to Info means that Debug
-level output is disabled.
External logging frameworks may also have their own mechanisms for setting a minimum log level.
If you did not specify an ILogAdapter at all, so it is using the default Console.Error
destination, then the default minimum logging level is Info
.
If you did specify an ILogAdapter, then the SDK does not apply a level filter by default. This is so as not to interfere with any other configuration that you may have set up in an external logging framework. However, you can still use this method to set a higher level so that any messages below that level will not be sent to the external framework at all.