Class LoggingCommandObserver

java.lang.Object
com.datastax.astra.internal.command.LoggingCommandObserver
All Implemented Interfaces:
CommandObserver, Cloneable

public class LoggingCommandObserver extends Object implements CommandObserver
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

    Constructors
    Constructor
    Description
    LoggingCommandObserver(Class<?> sourceClass)
    Initializes a new LoggingCommandObserver instance with a default logging level of DEBUG.
    LoggingCommandObserver(org.slf4j.event.Level logLevel, Class<?> sourceClass)
    Initializes a new LoggingCommandObserver instance with a specified logging level and source class.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    log(String message, Object... params)
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LoggingCommandObserver

      public LoggingCommandObserver(Class<?> sourceClass)
      Initializes a new LoggingCommandObserver 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

      public LoggingCommandObserver(org.slf4j.event.Level logLevel, Class<?> sourceClass)
      Initializes a new LoggingCommandObserver 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

      public 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.

      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 interface CommandObserver
      Parameters:
      executionInfo - The ExecutionInfos containing detailed information about the executed command, including execution context, results, and any errors or warnings that occurred.
    • log

      public void log(String message, Object... params)
      Convenient method to adjust dynamically the log level.
      Parameters:
      message - log message
      params - arguments for the log message.