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
-
.auto_load_adapters ⇒ Object
Discover and load the SDK’s built-in logging adapters.
- .build_logger_environment(env_data) ⇒ Object
-
.convert_environments(value) ⇒ Object
Coerce a dict input into Hash{String => LoggerEnvironment}.
-
.environments_to_wire(environments) ⇒ Object
Convert a typed environments dict to the wire-shaped dict for sending.
-
.logging_transport(api_key:, base_url:, profile:, base_domain:, scheme:, debug:, extra_headers:) ⇒ Object
Build standalone logging + app transports and resolve the app base URL.
Class Method Details
.auto_load_adapters ⇒ Object
Discover and load the SDK’s built-in logging adapters.
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/smplkit/logging/client.rb', line 69 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
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/smplkit/logging/models.rb', line 32 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
Coerce a dict input into Hash{String => LoggerEnvironment}.
Accepts both pre-built LoggerEnvironment instances and the wire-shaped {env_id => {“level” => “ERROR”}} dicts.
24 25 26 27 28 29 30 |
# File 'lib/smplkit/logging/models.rb', line 24 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
Convert a typed environments dict to the wire-shaped dict for sending. Entries with level=nil are skipped (no override to send).
48 49 50 51 52 |
# File 'lib/smplkit/logging/models.rb', line 48 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
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.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/smplkit/logging/client.rb', line 50 def self.logging_transport(api_key:, base_url:, profile:, base_domain:, scheme:, debug:, extra_headers:) cfg = ConfigResolution.resolve_management_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::ResolvedManagementConfig.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 |