Class LoggingCommandObserver
java.lang.Object
com.datastax.astra.internal.command.LoggingCommandObserver
- All Implemented Interfaces:
CommandObserver
,Cloneable
Implements a
CommandObserver
that logs command execution details. This observer uses SLF4J for logging,
providing flexibility to integrate with various logging frameworks (e.g., Logback, Log4J). The logging level and
the source class for logging can be customized, allowing for fine-grained control over the log output.-
Constructor Summary
ConstructorDescriptionLoggingCommandObserver
(Class<?> sourceClass) Initializes a newLoggingCommandObserver
instance with a default logging level of DEBUG.LoggingCommandObserver
(org.slf4j.event.Level logLevel, Class<?> sourceClass) Initializes a newLoggingCommandObserver
instance with a specified logging level and source class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Convenient method to adjust dynamically the log level.void
onCommand
(ExecutionInfos executionInfo) Invoked when a command is executed, providing an opportunity for registered observers to perform synchronous post-execution treatments based on the command's execution information.
-
Constructor Details
-
LoggingCommandObserver
Initializes a newLoggingCommandObserver
instance with a default logging level of DEBUG. This constructor is convenient when a moderate level of logging detail is sufficient, and it associates the logging output with the specified source class.- Parameters:
sourceClass
- The class from which the logging will be performed. This parameter is used to initialize the logger and associate log messages with the correct part of the application.
-
LoggingCommandObserver
Initializes a newLoggingCommandObserver
instance with a specified logging level and source class. This constructor offers full control over the logging configuration, allowing for detailed customization of the logging behavior.- Parameters:
logLevel
- The logging level to use for logging command execution details. This level determines the verbosity of the log output.sourceClass
- The class from which the logging will be performed. This parameter is used to initialize the logger and ensure that log messages are correctly categorized in the application's log output.
-
-
Method Details
-
onCommand
Invoked when a command is executed, providing an opportunity for registered observers to perform synchronous post-execution treatments based on the command's execution information.Implementers should define the logic within this method to handle the command execution event, utilizing the
ExecutionInfos
provided to access details about the command's execution context, results, and status. This method is called synchronously, ensuring that any processing here is completed before the command execution flow continues.- Specified by:
onCommand
in interfaceCommandObserver
- Parameters:
executionInfo
- TheExecutionInfos
containing detailed information about the executed command, including execution context, results, and any errors or warnings that occurred.
-
log
Convenient method to adjust dynamically the log level.- Parameters:
message
- log messageparams
- arguments for the log message.
-