Class: IuguLogger::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/iugu_logger/configuration.rb

Overview

SDK configuration object. Set via ‘IuguLogger.configure`.

Constant Summary collapse

DEFAULT_MAX_LOG_SIZE_KB =

Default cap for emitted log size, in KB. The middleware truncates ‘request.params` (typically the biggest field) when the encoded payload would exceed this, and sets `request.params_truncated: true` so downstream consumers know.

64

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/iugu_logger/configuration.rb', line 18

def initialize
  @service_name        = nil
  @service_version     = nil
  @service_environment = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
  @output              = $stdout
  @format              = :json # :json | :pretty

  # PII v0.2 — strategies overridable per type:
  #   :full_redact / :last4 / :detect_only / :preserve
  @pii_redaction       = Pii::DEFAULT_STRATEGIES.dup
  @pii_param_blocklist = Pii::DEFAULT_PARAM_BLOCKLIST.dup

  # Schema v0.3 — event.action validation:
  #   :strict — raise on unknown action / missing required field
  #   :warn   — annotate emitted log with labels.schema_warning, proceed
  #   :off    — disabled (default — backward compatible)
  # event_action_registry: Hash from Schema.load_from_file or nil. When
  # nil, validation is :off regardless of mode.
  @event_action_validator = Schema::DEFAULT_MODE
  @event_action_registry  = nil

  # v0.9 — log size cap (KB). Set to nil to disable.
  @max_log_size_kb = DEFAULT_MAX_LOG_SIZE_KB

  # service.instance (= HOSTNAME/POD_NAME) is OFF by default: in the
  # canonical K8s + Alloy pipeline it duplicates the `pod_name` label
  # Alloy already attaches to every log line. Set to true for contexts
  # where no collector enriches the log (local dev, non-K8s, alternate
  # sinks) and you still want the instance identifier in the payload.
  @emit_service_instance = false
end

Instance Attribute Details

#emit_service_instanceObject

Returns the value of attribute emit_service_instance.



6
7
8
# File 'lib/iugu_logger/configuration.rb', line 6

def emit_service_instance
  @emit_service_instance
end

#event_action_registryObject

Returns the value of attribute event_action_registry.



6
7
8
# File 'lib/iugu_logger/configuration.rb', line 6

def event_action_registry
  @event_action_registry
end

#event_action_validatorObject

Returns the value of attribute event_action_validator.



6
7
8
# File 'lib/iugu_logger/configuration.rb', line 6

def event_action_validator
  @event_action_validator
end

#formatObject

Returns the value of attribute format.



6
7
8
# File 'lib/iugu_logger/configuration.rb', line 6

def format
  @format
end

#max_log_size_kbObject

Returns the value of attribute max_log_size_kb.



6
7
8
# File 'lib/iugu_logger/configuration.rb', line 6

def max_log_size_kb
  @max_log_size_kb
end

#outputObject

Returns the value of attribute output.



6
7
8
# File 'lib/iugu_logger/configuration.rb', line 6

def output
  @output
end

#pii_param_blocklistObject

Returns the value of attribute pii_param_blocklist.



6
7
8
# File 'lib/iugu_logger/configuration.rb', line 6

def pii_param_blocklist
  @pii_param_blocklist
end

#pii_redactionObject

Returns the value of attribute pii_redaction.



6
7
8
# File 'lib/iugu_logger/configuration.rb', line 6

def pii_redaction
  @pii_redaction
end

#service_environmentObject

Returns the value of attribute service_environment.



6
7
8
# File 'lib/iugu_logger/configuration.rb', line 6

def service_environment
  @service_environment
end

#service_nameObject

Returns the value of attribute service_name.



6
7
8
# File 'lib/iugu_logger/configuration.rb', line 6

def service_name
  @service_name
end

#service_versionObject

Returns the value of attribute service_version.



6
7
8
# File 'lib/iugu_logger/configuration.rb', line 6

def service_version
  @service_version
end

Instance Method Details

#validate!Object

Validates required fields. Raises ConfigurationError if missing.



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

def validate!
  missing = []
  missing << 'service_name'        if blank?(service_name)
  missing << 'service_version'     if blank?(service_version)
  missing << 'service_environment' if blank?(service_environment)

  unless missing.empty?
    raise ConfigurationError,
          "missing required configuration: #{missing.join(', ')}. " \
          "Call IuguLogger.configure { |c| c.service_name = ... }."
  end

  unless %i[json pretty].include?(format)
    raise ConfigurationError, "unknown format: #{format.inspect} (expected :json or :pretty)"
  end

  self
end