Package com.couchbase.client.core.env
Class LoggerConfig
- java.lang.Object
-
- com.couchbase.client.core.env.LoggerConfig
-
public class LoggerConfig extends Object
TheLoggerConfigallows to customize various aspects of the SDKs logging behavior.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLoggerConfig.Builderstatic classLoggerConfig.Defaults
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static LoggerConfig.Builderbuilder()Returns aLoggerConfig.Builderwhich can be used to customize the different logging properties.LoggerFormatterconsoleLoggerFormatter()Returns the logger formatter used for the console logger.LoggerConfig.BuilderconsoleLoggerFormatter(LoggerFormatter loggerFormatter)Allows to customize the format when the console logger is used.LevelconsoleLogLevel()Returns the log level that should be used if the ConsoleLogger is enabled/used.static LoggerConfig.BuilderconsoleLogLevel(Level consoleLogLevel)Allows to customize the log level for the Console Logger.static LoggerConfigcreate()Creates aLoggerConfigwith all the defaults (can be found inLoggerConfig.Defaults).LoggingEventConsumer.LoggercustomLogger()Returns a custom logger if configured for testing.static LoggerConfig.BuildercustomLogger(LoggingEventConsumer.Logger customLogger)Allows to specify a custom logger.booleandiagnosticContextEnabled()Returns true if the diagnostic context is enabled (disabled by default).booleandisableSlf4J()Returns true if SLF4J should not be used, even if found on the classpath.static LoggerConfig.BuilderdisableSlf4J(boolean disableSlf4J)Disable SLF4J logging, which is by default the first option tried.static LoggerConfig.BuilderenableDiagnosticContext(boolean diagnosticContextEnabled)Enables the diagnostic context (if supported by the used logger) - disabled by default.booleanfallbackToConsole()Returns true if the console fallback is activated.static LoggerConfig.BuilderfallbackToConsole(boolean fallbackToConsole)Use the console logger instead of the java.util.logging fallback in case SLF4J is not found or disabled.StringloggerName()Deprecated.static LoggerConfig.BuilderloggerName(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 Detail
-
builder
public static LoggerConfig.Builder builder()
Returns aLoggerConfig.Builderwhich can be used to customize the different logging properties.
-
create
public static LoggerConfig create()
Creates aLoggerConfigwith all the defaults (can be found inLoggerConfig.Defaults).- Returns:
- the created, immutable logger config with defaults.
-
fallbackToConsole
public 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. 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.Builderfor chaining purposes.
-
disableSlf4J
public static LoggerConfig.Builder disableSlf4J(boolean 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.Builderfor chaining purposes.
-
loggerName
@Deprecated public 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.Allowed to set a custom logger name - does not have an effect and is deprecated.- Parameters:
loggerName- the custom logger name.- Returns:
- a
LoggerConfig.Builderfor chaining purposes.
-
enableDiagnosticContext
public static LoggerConfig.Builder enableDiagnosticContext(boolean diagnosticContextEnabled)
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.Builderfor chaining purposes.
-
customLogger
@Internal public static LoggerConfig.Builder customLogger(LoggingEventConsumer.Logger 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.Builderfor chaining purposes.
-
consoleLogLevel
public static LoggerConfig.Builder consoleLogLevel(Level 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.Builderfor chaining purposes.
-
consoleLoggerFormatter
public LoggerConfig.Builder consoleLoggerFormatter(LoggerFormatter loggerFormatter)
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
DefaultLoggerFormatterfor 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.Builderfor chaining purposes.
-
customLogger
@Internal public LoggingEventConsumer.Logger 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 public String 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
public Level consoleLogLevel()
Returns the log level that should be used if the ConsoleLogger is enabled/used.- Returns:
- the log level for the console logger.
-
consoleLoggerFormatter
public LoggerFormatter consoleLoggerFormatter()
Returns the logger formatter used for the console logger.- Returns:
- the logger formatter.
-
-