Package com.couchbase.client.core.env
Class LoggerConfig
java.lang.Object
com.couchbase.client.core.env.LoggerConfig
The
LoggerConfig
allows to customize various aspects of the SDKs logging behavior.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
-
Method Summary
Modifier and TypeMethodDescriptionstatic LoggerConfig.Builder
builder()
Returns aLoggerConfig.Builder
which can be used to customize the different logging properties.Returns the logger formatter used for the console logger.consoleLoggerFormatter
(LoggerFormatter loggerFormatter) Allows to customize the format when the console logger is used.Returns the log level that should be used if the ConsoleLogger is enabled/used.static LoggerConfig.Builder
consoleLogLevel
(Level consoleLogLevel) Allows to customize the log level for the Console Logger.static LoggerConfig
create()
Creates aLoggerConfig
with all the defaults (can be found inLoggerConfig.Defaults
).Returns a custom logger if configured for testing.static LoggerConfig.Builder
customLogger
(LoggingEventConsumer.Logger customLogger) Allows to specify a custom logger.boolean
Returns true if the diagnostic context is enabled (disabled by default).boolean
Returns true if SLF4J should not be used, even if found on the classpath.static LoggerConfig.Builder
disableSlf4J
(boolean disableSlf4J) Disable SLF4J logging, which is by default the first option tried.static LoggerConfig.Builder
enableDiagnosticContext
(boolean diagnosticContextEnabled) Enables the diagnostic context (if supported by the used logger) - disabled by default.boolean
Returns true if the console fallback is activated.static LoggerConfig.Builder
fallbackToConsole
(boolean fallbackToConsole) Use the console logger instead of the java.util.logging fallback in case SLF4J is not found or disabled.Deprecated.static LoggerConfig.Builder
loggerName
(String loggerName) Deprecated.the logging infrastructure picks the logger name automatically now based on the event type so it is easier to enable/disable logging or change the verbosity level for certain groups rather than having a single universal logger name.
-
Method Details
-
builder
Returns aLoggerConfig.Builder
which can be used to customize the different logging properties. -
create
Creates aLoggerConfig
with all the defaults (can be found inLoggerConfig.Defaults
).- Returns:
- the created, immutable logger config with defaults.
-
fallbackToConsole
Use the console logger instead of the java.util.logging fallback in case SLF4J is not found or disabled. Please note that in addition setting this to true, either SLF4J must not be on the classpath or manually disabled viadisableSlf4J(boolean)
to make it work. By default, it will log at INFO level to stdout/stderr, but the loglevel can be configured viaconsoleLogLevel(Level)
.- Parameters:
fallbackToConsole
- true if the console logger should be used as a fallback.- Returns:
- a
LoggerConfig.Builder
for chaining purposes.
-
disableSlf4J
Disable SLF4J logging, which is by default the first option tried. If SLF4J is disabled, java.util.logging will be tried next, unlessfallbackToConsole(boolean)
is set to true.- Parameters:
disableSlf4J
- set to true to disable SLF4J logging.- Returns:
- a
LoggerConfig.Builder
for chaining purposes.
-
loggerName
Deprecated.the logging infrastructure picks the logger name automatically now based on the event type so it is easier to enable/disable logging or change the verbosity level for certain groups rather than having a single universal logger name.Allowed to set a custom logger name - does not have an effect and is deprecated.- Parameters:
loggerName
- the custom logger name.- Returns:
- a
LoggerConfig.Builder
for chaining purposes.
-
enableDiagnosticContext
Enables the diagnostic context (if supported by the used logger) - disabled by default. Please note that this will only work for the SLF4J logger. Neither the java util logger, nor the console logger support the diagnostic context at this point. In SLF4J parlance, it is called the MDC.- Parameters:
diagnosticContextEnabled
- if the diagnostic context should be enabled.- Returns:
- a
LoggerConfig.Builder
for chaining purposes.
-
customLogger
Allows to specify a custom logger. This is used for testing only.- Parameters:
customLogger
- the custom logger to use in testing.- Returns:
- a
LoggerConfig.Builder
for chaining purposes.
-
consoleLogLevel
Allows to customize the log level for the Console Logger. Please note that this DOES NOT AFFECT any other logging infrastructure (so neither the java.util.logging, nor the SLF4J setup which is the default!). It will only affect the log level iffallbackToConsole(boolean)
is set to true at the same time.- Parameters:
consoleLogLevel
- the log level for the console logger.- Returns:
- a
LoggerConfig.Builder
for chaining purposes.
-
consoleLoggerFormatter
Allows to customize the format when the console logger is used. Please note that this DOES NOT AFFECT any other logging infrastructure (so neither the java.util.logging, nor the SLF4J setup which is the default!). It will only affect the log level iffallbackToConsole(boolean)
is set to true at the same time.If only a custom timestamp needs to be added, it is recommended to override the
DefaultLoggerFormatter
for ease of use. If a completely custom line is needed, the interface can be implemented from scratch.- Parameters:
loggerFormatter
- the custom formatter to be used.- Returns:
- a
LoggerConfig.Builder
for chaining purposes.
-
customLogger
Returns a custom logger if configured for testing. -
fallbackToConsole
public boolean fallbackToConsole()Returns true if the console fallback is activated. -
disableSlf4J
public boolean disableSlf4J()Returns true if SLF4J should not be used, even if found on the classpath. -
loggerName
Deprecated.Returns the custom logger name to use, deprecated. -
diagnosticContextEnabled
public boolean diagnosticContextEnabled()Returns true if the diagnostic context is enabled (disabled by default). -
consoleLogLevel
Returns the log level that should be used if the ConsoleLogger is enabled/used.- Returns:
- the log level for the console logger.
-
consoleLoggerFormatter
Returns the logger formatter used for the console logger.- Returns:
- the logger formatter.
-