Class: Makit::Logging::Sinks::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/makit/logging/sinks/base.rb

Overview

Base class for all logging sinks

Sinks provide a way to output log requests to various destinations like console, files, or external services. This follows the same pattern as the commands middleware but focuses on output rather than transformation.

Examples:

Creating a custom logging sink

class CustomSink < Base
  def call(log_request, &block)
    # Output the log request
    output_log(log_request)

    # Continue to next sink
    block.call(log_request) if block_given?
  end
end

Direct Known Subclasses

FileSink, Structured, UnifiedFileSink

Instance Method Summary collapse

Instance Method Details

#applicable?(_log_request) ⇒ Boolean

Check if this sink should be applied to the given log request

Override this method to provide conditional sink application based on log request properties like level, message, or context.

Parameters:

Returns:

  • (Boolean)

    true if sink should be applied



45
46
47
# File 'lib/makit/logging/sinks/base.rb', line 45

def applicable?(_log_request)
  true
end

#call(log_request) {|LogRequest| ... } ⇒ LogRequest

Execute sink logic

This method must be implemented by subclasses to provide the actual sink functionality. The pattern is to output the log request to the destination, then call the block to continue the sink chain.

Parameters:

  • log_request (LogRequest)

    the log request to process

Yields:

  • (LogRequest)

    yields the processed log request to the next sink

Yield Returns:

Returns:

  • (LogRequest)

    the final processed log request

Raises:

  • (NotImplementedError)

    if not overridden by subclass



34
35
36
# File 'lib/makit/logging/sinks/base.rb', line 34

def call(log_request, &block)
  raise NotImplementedError, "#{self.class.name} must implement #call"
end

#configHash

Get sink configuration

Override this method to provide sink-specific configuration.

Returns:

  • (Hash)

    sink configuration



61
62
63
# File 'lib/makit/logging/sinks/base.rb', line 61

def config
  {}
end

#nameString

Get sink name for logging and debugging

Returns:



52
53
54
# File 'lib/makit/logging/sinks/base.rb', line 52

def name
  self.class.name.split("::").last
end