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 private
-
#clear_all_environment_levels ⇒ Object
Remove all per-environment level overrides.
-
#clear_level(environment: nil) ⇒ Object
Remove a log level.
-
#delete ⇒ void
(also: #delete!)
Delete this logger from the server.
-
#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
Whether the SDK applies server-driven level changes to this logger.
-
#save ⇒ self
(also: #save!)
Persist this logger to the server (create or update).
-
#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.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/smplkit/logging/models.rb', line 74 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.
71 72 73 |
# File 'lib/smplkit/logging/models.rb', line 71 def created_at @created_at end |
#description ⇒ Object
Returns the value of attribute description.
71 72 73 |
# File 'lib/smplkit/logging/models.rb', line 71 def description @description end |
#environment ⇒ Object
Returns the value of attribute environment.
71 72 73 |
# File 'lib/smplkit/logging/models.rb', line 71 def environment @environment end |
#id ⇒ Object
Returns the value of attribute id.
71 72 73 |
# File 'lib/smplkit/logging/models.rb', line 71 def id @id end |
#level ⇒ Object
Returns the value of attribute level.
71 72 73 |
# File 'lib/smplkit/logging/models.rb', line 71 def level @level end |
#log_group_id ⇒ Object
Returns the value of attribute log_group_id.
71 72 73 |
# File 'lib/smplkit/logging/models.rb', line 71 def log_group_id @log_group_id end |
#managed ⇒ Object
Returns the value of attribute managed.
71 72 73 |
# File 'lib/smplkit/logging/models.rb', line 71 def managed @managed end |
#name ⇒ Object
Returns the value of attribute name.
71 72 73 |
# File 'lib/smplkit/logging/models.rb', line 71 def name @name end |
#resolved_level ⇒ Object
Returns the value of attribute resolved_level.
71 72 73 |
# File 'lib/smplkit/logging/models.rb', line 71 def resolved_level @resolved_level end |
#service ⇒ Object
Returns the value of attribute service.
71 72 73 |
# File 'lib/smplkit/logging/models.rb', line 71 def service @service end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
71 72 73 |
# File 'lib/smplkit/logging/models.rb', line 71 def updated_at @updated_at end |
Instance Method Details
#_apply(other) ⇒ 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.
162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/smplkit/logging/models.rb', line 162 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.
132 133 134 |
# File 'lib/smplkit/logging/models.rb', line 132 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.
123 124 125 126 127 128 129 |
# File 'lib/smplkit/logging/models.rb', line 123 def clear_level(environment: nil) if environment.nil? @level = nil else @environments.delete(environment) end end |
#delete ⇒ void Also known as: delete!
This method returns an undefined value.
Delete this logger from the server.
154 155 156 157 158 |
# File 'lib/smplkit/logging/models.rb', line 154 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: “…”).
100 101 102 |
# File 'lib/smplkit/logging/models.rb', line 100 def environments @environments.dup end |
#managed? ⇒ Boolean
Whether the SDK applies server-driven level changes to this logger.
96 |
# File 'lib/smplkit/logging/models.rb', line 96 def managed? = !!@managed |
#save ⇒ self Also known as: save!
Persist this logger to the server (create or update).
140 141 142 143 144 145 146 |
# File 'lib/smplkit/logging/models.rb', line 140 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.
109 110 111 112 113 114 115 |
# File 'lib/smplkit/logging/models.rb', line 109 def set_level(level, environment: nil) if environment.nil? @level = level else @environments[environment] = LoggerEnvironment.new(level: level) end end |