WeaviateEx.Debug.RequestLogger (WeaviateEx v0.7.4)

View Source

Request/response logging GenServer for debugging Weaviate operations.

Provides centralized logging of HTTP and gRPC requests with timestamps, filtering, and export capabilities.

Example

# Start the logger
{:ok, _pid} = RequestLogger.start_link(name: :my_logger, max_logs: 1000)

# Enable logging
RequestLogger.enable(:my_logger)

# Perform operations...

# Get recent logs
logs = RequestLogger.get_logs(:my_logger, limit: 10)

# Export to file
RequestLogger.export_logs(:my_logger, "/tmp/debug.json", :json)

Summary

Functions

Returns a specification to start this module under a supervisor.

Clear all logged requests.

Disable request logging.

Enable request logging.

Check if logging is enabled.

Export logs to a file.

Get logged requests.

Log a request/response.

Start the RequestLogger GenServer.

Types

log_entry()

@type log_entry() :: %{
  timestamp: DateTime.t(),
  protocol: protocol(),
  method: atom() | String.t(),
  path: String.t(),
  request_body: term() | nil,
  response_status: pos_integer() | atom(),
  response_body: term() | nil,
  duration_ms: non_neg_integer()
}

protocol()

@type protocol() :: :http | :grpc

state()

@type state() :: %{enabled: boolean(), logs: [log_entry()], max_logs: pos_integer()}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear_logs(server)

@spec clear_logs(GenServer.server()) :: :ok

Clear all logged requests.

Example

RequestLogger.clear_logs(:my_logger)

disable(server)

@spec disable(GenServer.server()) :: :ok

Disable request logging.

Example

RequestLogger.disable(:my_logger)

enable(server)

@spec enable(GenServer.server()) :: :ok

Enable request logging.

Example

RequestLogger.enable(:my_logger)

enabled?(server)

@spec enabled?(GenServer.server()) :: boolean()

Check if logging is enabled.

Example

if RequestLogger.enabled?(:my_logger) do
  # logging is active
end

export_logs(server, path, format)

@spec export_logs(GenServer.server(), String.t(), :json | :text) ::
  :ok | {:error, String.t()}

Export logs to a file.

Parameters

  • server - The logger GenServer
  • path - File path to write to
  • format - :json or :text

Example

RequestLogger.export_logs(:my_logger, "/tmp/logs.json", :json)

get_logs(server, opts \\ [])

@spec get_logs(
  GenServer.server(),
  keyword()
) :: [log_entry()]

Get logged requests.

Options

  • :limit - Maximum number of logs to return
  • :protocol - Filter by protocol (:http or :grpc)
  • :since - Only return logs after this DateTime

Example

logs = RequestLogger.get_logs(:my_logger, limit: 10, protocol: :http)

log_request(server, entry)

@spec log_request(GenServer.server(), map()) :: :ok

Log a request/response.

The entry should contain:

  • :protocol - :http or :grpc
  • :method - HTTP method or gRPC procedure name
  • :path - Request path
  • :request_body - Request body (optional)
  • :response_status - HTTP status code or gRPC status
  • :response_body - Response body (optional)
  • :duration_ms - Request duration in milliseconds

Example

RequestLogger.log_request(:my_logger, %{
  protocol: :http,
  method: :get,
  path: "/v1/objects/Article/uuid",
  response_status: 200,
  duration_ms: 45
})

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Start the RequestLogger GenServer.

Options

  • :name - GenServer name (required for most operations)
  • :max_logs - Maximum number of logs to keep (default: 10000)

Example

{:ok, pid} = RequestLogger.start_link(name: :debug_logger, max_logs: 5000)