Module: Smplkit::Logging

Defined in:
lib/smplkit/logging/client.rb,
lib/smplkit/logging/levels.rb,
lib/smplkit/logging/models.rb,
lib/smplkit/logging/helpers.rb,
lib/smplkit/logging/sources.rb,
lib/smplkit/logging/normalize.rb,
lib/smplkit/logging/resolution.rb,
lib/smplkit/logging/adapters/base.rb,
lib/smplkit/logging/adapters/stdlib_logger_adapter.rb,
lib/smplkit/logging/adapters/semantic_logger_adapter.rb

Defined Under Namespace

Modules: Adapters, Helpers, Levels, Normalize, Resolution Classes: LogGroupsClient, LoggerChangeEvent, LoggerEnvironment, LoggerSource, LoggersClient, LoggingClient, SmplLogGroup, SmplLogger

Constant Summary collapse

NOT_INSTALLED_MESSAGE =
"Smpl Logging live operations require install() first — this opens a live " \
"connection to your running service and hooks into your application's logging " \
"framework. Call client.logging.install() before on_change/refresh()."

Class Method Summary collapse

Class Method Details

.auto_load_adaptersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Discover and load the SDK’s built-in logging adapters.



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/smplkit/logging/client.rb', line 73

def self.auto_load_adapters
  adapters = [Adapters::StdlibLoggerAdapter.new]

  begin
    require "semantic_logger"
    require_relative "adapters/semantic_logger_adapter"
    adapters << Adapters::SemanticLoggerAdapter.new
  rescue LoadError
    Smplkit.debug("registration", "semantic_logger gem not installed; semantic-logger adapter skipped")
  end

  adapters
end

.build_logger_environment(env_data) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/smplkit/logging/models.rb', line 35

def self.build_logger_environment(env_data)
  return env_data if env_data.is_a?(LoggerEnvironment)
  return LoggerEnvironment.new unless env_data.is_a?(Hash)

  level_str = env_data["level"] || env_data[:level]
  return LoggerEnvironment.new if level_str.nil?

  begin
    LoggerEnvironment.new(level: LogLevel.coerce(level_str))
  rescue ArgumentError
    LoggerEnvironment.new
  end
end

.convert_environments(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Coerce a dict input into Hash{String => LoggerEnvironment}.

Accepts both pre-built LoggerEnvironment instances and the wire-shaped {env_id => {“level” => “ERROR”}} dicts.



26
27
28
29
30
31
32
# File 'lib/smplkit/logging/models.rb', line 26

def self.convert_environments(value)
  return {} if value.nil? || value.empty?

  value.each_with_object({}) do |(env_id, env_data), out|
    out[env_id] = build_logger_environment(env_data)
  end
end

.environments_to_wire(environments) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert a typed environments dict to the wire-shaped dict for sending. Entries with level=nil are skipped (no override to send).



53
54
55
56
57
# File 'lib/smplkit/logging/models.rb', line 53

def self.environments_to_wire(environments)
  environments.each_with_object({}) do |(env_id, env), out|
    out[env_id] = { "level" => env.level.to_s } unless env.level.nil?
  end
end

.logging_transport(api_key:, base_url:, profile:, base_domain:, scheme:, debug:, extra_headers:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build standalone logging + app transports and resolve the app base URL.

base_url/api_key are used directly when supplied (the path a top-level client takes after it has already resolved them); otherwise the management config resolver fills in whatever is missing (+~/.smplkit+ / env vars / defaults). The app transport is needed for the WebSocket gateway, which lives on the app service (like flags); the app base URL is returned so a standalone client can open its own WebSocket against the event gateway.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/smplkit/logging/client.rb', line 52

def self.logging_transport(api_key:, base_url:, profile:, base_domain:, scheme:, debug:, extra_headers:)
  cfg = ConfigResolution.resolve_client_config(
    profile: profile, api_key: api_key, base_domain: base_domain, scheme: scheme, debug: debug
  )
  resolved_key = api_key.nil? ? cfg.api_key : api_key
  merged = {}
  merged.merge!(cfg.extra_headers || {})
  merged.merge!(extra_headers || {})
  tcfg = ConfigResolution::ResolvedClientConfig.new(
    api_key: resolved_key, base_domain: cfg.base_domain, scheme: cfg.scheme,
    debug: cfg.debug, extra_headers: merged
  )
  app_url = ConfigResolution.service_url(cfg.scheme, "app", cfg.base_domain)
  logging_http = Transport.build_api_client(SmplkitGeneratedClient::Logging, "logging", tcfg, base_url: base_url)
  app_http = Transport.build_api_client(SmplkitGeneratedClient::App, "app", tcfg)
  [logging_http, app_http, app_url, resolved_key]
end