Class: Smplkit::Logging::SmplLogger
- Inherits:
-
Object
- Object
- Smplkit::Logging::SmplLogger
- Defined in:
- lib/smplkit/logging/models.rb
Overview
A logger resource managed by the smplkit Logging service.
Attributes:
- id, name: identity
- resolved_level: effective level computed by the platform from
environment overrides + log group inheritance
- level: explicit override (nil means inherit)
- service, environment: provenance
- log_group_id: parent log group, if any
- managed: whether the SDK should apply server-driven level changes
- environments: per-environment level overrides, keyed by environment
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#description ⇒ Object
Returns the value of attribute description.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#id ⇒ Object
Returns the value of attribute id.
-
#level ⇒ Object
Returns the value of attribute level.
-
#log_group_id ⇒ Object
Returns the value of attribute log_group_id.
-
#managed ⇒ Object
Returns the value of attribute managed.
-
#name ⇒ Object
Returns the value of attribute name.
-
#resolved_level ⇒ Object
Returns the value of attribute resolved_level.
-
#service ⇒ Object
Returns the value of attribute service.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #_apply(other) ⇒ Object
-
#clear_all_environment_levels ⇒ Object
Remove all per-environment level overrides.
-
#clear_level(environment: nil) ⇒ Object
Remove a log level.
- #delete ⇒ Object (also: #delete!)
-
#environments ⇒ Object
Read-only view of per-environment level overrides.
-
#initialize(client = nil, name:, resolved_level:, id: nil, level: nil, service: nil, environment: nil, log_group_id: nil, managed: true, description: nil, environments: nil, created_at: nil, updated_at: nil) ⇒ SmplLogger
constructor
A new instance of SmplLogger.
- #managed? ⇒ Boolean
- #save ⇒ Object (also: #save!)
-
#set_level(level, environment: nil) ⇒ Object
Set the log level.
Constructor Details
#initialize(client = nil, name:, resolved_level:, id: nil, level: nil, service: nil, environment: nil, log_group_id: nil, managed: true, description: nil, environments: nil, created_at: nil, updated_at: nil) ⇒ SmplLogger
Returns a new instance of SmplLogger.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/smplkit/logging/models.rb', line 69 def initialize(client = nil, name:, resolved_level:, id: nil, level: nil, service: nil, environment: nil, log_group_id: nil, managed: true, description: nil, environments: nil, created_at: nil, updated_at: nil) @client = client @id = id @name = name @resolved_level = resolved_level @level = level @service = service @environment = environment @log_group_id = log_group_id @managed = managed @description = description @environments = Logging.convert_environments(environments) @created_at = created_at @updated_at = updated_at end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
66 67 68 |
# File 'lib/smplkit/logging/models.rb', line 66 def created_at @created_at end |
#description ⇒ Object
Returns the value of attribute description.
66 67 68 |
# File 'lib/smplkit/logging/models.rb', line 66 def description @description end |
#environment ⇒ Object
Returns the value of attribute environment.
66 67 68 |
# File 'lib/smplkit/logging/models.rb', line 66 def environment @environment end |
#id ⇒ Object
Returns the value of attribute id.
66 67 68 |
# File 'lib/smplkit/logging/models.rb', line 66 def id @id end |
#level ⇒ Object
Returns the value of attribute level.
66 67 68 |
# File 'lib/smplkit/logging/models.rb', line 66 def level @level end |
#log_group_id ⇒ Object
Returns the value of attribute log_group_id.
66 67 68 |
# File 'lib/smplkit/logging/models.rb', line 66 def log_group_id @log_group_id end |
#managed ⇒ Object
Returns the value of attribute managed.
66 67 68 |
# File 'lib/smplkit/logging/models.rb', line 66 def managed @managed end |
#name ⇒ Object
Returns the value of attribute name.
66 67 68 |
# File 'lib/smplkit/logging/models.rb', line 66 def name @name end |
#resolved_level ⇒ Object
Returns the value of attribute resolved_level.
66 67 68 |
# File 'lib/smplkit/logging/models.rb', line 66 def resolved_level @resolved_level end |
#service ⇒ Object
Returns the value of attribute service.
66 67 68 |
# File 'lib/smplkit/logging/models.rb', line 66 def service @service end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
66 67 68 |
# File 'lib/smplkit/logging/models.rb', line 66 def updated_at @updated_at end |
Instance Method Details
#_apply(other) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/smplkit/logging/models.rb', line 144 def _apply(other) @id = other.id @name = other.name @resolved_level = other.resolved_level @level = other.level @service = other.service @environment = other.environment @log_group_id = other.log_group_id @managed = other.managed @description = other.description @environments = other.environments @created_at = other.created_at @updated_at = other.updated_at end |
#clear_all_environment_levels ⇒ Object
Remove all per-environment level overrides.
124 125 126 |
# File 'lib/smplkit/logging/models.rb', line 124 def clear_all_environment_levels @environments = {} end |
#clear_level(environment: nil) ⇒ Object
Remove a log level.
With environment: nil (the default), removes the base log level (the logger then inherits from its group / ancestor / system default). With environment: “…”, removes the per-environment override only. Changes are local until save.
115 116 117 118 119 120 121 |
# File 'lib/smplkit/logging/models.rb', line 115 def clear_level(environment: nil) if environment.nil? @level = nil else @environments.delete(environment) end end |
#delete ⇒ Object Also known as: delete!
137 138 139 140 141 |
# File 'lib/smplkit/logging/models.rb', line 137 def delete raise "SmplLogger was constructed without a client; cannot delete" if @client.nil? @client.delete(@id || @name) end |
#environments ⇒ Object
Read-only view of per-environment level overrides. Mutate via set_level / clear_level (with environment: “…”).
92 93 94 |
# File 'lib/smplkit/logging/models.rb', line 92 def environments @environments.dup end |
#managed? ⇒ Boolean
88 |
# File 'lib/smplkit/logging/models.rb', line 88 def managed? = !!@managed |
#save ⇒ Object Also known as: save!
128 129 130 131 132 133 134 |
# File 'lib/smplkit/logging/models.rb', line 128 def save raise "SmplLogger was constructed without a client; cannot save" if @client.nil? updated = @client._update_logger(self) _apply(updated) self end |
#set_level(level, environment: nil) ⇒ Object
Set the log level.
With environment: nil (the default), sets the base log level used when no environment-specific override applies. With environment: “…”, sets the per-environment override. Changes are local until save.
101 102 103 104 105 106 107 |
# File 'lib/smplkit/logging/models.rb', line 101 def set_level(level, environment: nil) if environment.nil? @level = level else @environments[environment] = LoggerEnvironment.new(level: level) end end |