Class: Smplkit::Logging::SmplLogGroup
- Inherits:
-
Object
- Object
- Smplkit::Logging::SmplLogGroup
- Defined in:
- lib/smplkit/logging/models.rb,
sig/smplkit/logging.rbs
Overview
A log group resource — a hierarchical bag of loggers with a shared configured level.
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#description ⇒ String?
Returns the value of attribute description.
-
#environments ⇒ Hash[String, untyped]
Read-only view of per-environment level overrides.
-
#group ⇒ Object
Returns the value of attribute group.
-
#id ⇒ String?
Returns the value of attribute id.
-
#key ⇒ String
Returns the value of attribute key.
-
#level ⇒ Smplkit::LogLevel?
Returns the value of attribute level.
-
#name ⇒ String?
Returns the value of attribute name.
-
#parent_id ⇒ String?
Returns the value of attribute parent_id.
-
#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 group from the server.
-
#initialize(client = nil, key:, id: nil, name: nil, level: nil, description: nil, group: nil, environments: nil, created_at: nil, updated_at: nil) ⇒ SmplLogGroup
constructor
A new instance of SmplLogGroup.
-
#save ⇒ self
(also: #save!)
Persist this group to the server (create or update).
-
#set_level(level, environment: nil) ⇒ Object
Set the log level.
Constructor Details
#initialize(client = nil, key:, id: nil, name: nil, level: nil, description: nil, group: nil, environments: nil, created_at: nil, updated_at: nil) ⇒ SmplLogGroup
Returns a new instance of SmplLogGroup.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/smplkit/logging/models.rb', line 184 def initialize(client = nil, key:, id: nil, name: nil, level: nil, description: nil, group: nil, environments: nil, created_at: nil, updated_at: nil) @client = client @id = id @key = key @name = name @level = level @description = description @group = group @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.
181 182 183 |
# File 'lib/smplkit/logging/models.rb', line 181 def created_at @created_at end |
#description ⇒ String?
Returns the value of attribute description.
181 182 183 |
# File 'lib/smplkit/logging/models.rb', line 181 def description @description end |
#environments ⇒ Hash[String, untyped]
Read-only view of per-environment level overrides. Mutate via
set_level / clear_level (with environment: "...").
201 202 203 |
# File 'lib/smplkit/logging/models.rb', line 201 def environments @environments.dup end |
#group ⇒ Object
Returns the value of attribute group.
181 182 183 |
# File 'lib/smplkit/logging/models.rb', line 181 def group @group end |
#id ⇒ String?
Returns the value of attribute id.
181 182 183 |
# File 'lib/smplkit/logging/models.rb', line 181 def id @id end |
#key ⇒ String
Returns the value of attribute key.
181 182 183 |
# File 'lib/smplkit/logging/models.rb', line 181 def key @key end |
#level ⇒ Smplkit::LogLevel?
Returns the value of attribute level.
181 182 183 |
# File 'lib/smplkit/logging/models.rb', line 181 def level @level end |
#name ⇒ String?
Returns the value of attribute name.
181 182 183 |
# File 'lib/smplkit/logging/models.rb', line 181 def name @name end |
#parent_id ⇒ String?
Returns the value of attribute parent_id.
39 40 41 |
# File 'sig/smplkit/logging.rbs', line 39 def parent_id @parent_id end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
181 182 183 |
# File 'lib/smplkit/logging/models.rb', line 181 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.
268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/smplkit/logging/models.rb', line 268 def _apply(other) @id = other.id @key = other.key @name = other.name @level = other.level @description = other.description @group = other.group @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.
233 234 235 |
# File 'lib/smplkit/logging/models.rb', line 233 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
group then inherits from its parent group / ancestor / system default).
With environment: "...", removes the per-environment override only.
Changes are local until save.
224 225 226 227 228 229 230 |
# File 'lib/smplkit/logging/models.rb', line 224 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 group from the server.
260 261 262 263 264 |
# File 'lib/smplkit/logging/models.rb', line 260 def delete raise "SmplLogGroup was constructed without a client; cannot delete" if @client.nil? @client.delete(@key) end |
#save ⇒ self Also known as: save!
Persist this group to the server (create or update).
241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/smplkit/logging/models.rb', line 241 def save raise "SmplLogGroup was constructed without a client; cannot save" if @client.nil? updated = if @created_at.nil? @client._create_log_group(self) else @client._update_log_group(self) end _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.
210 211 212 213 214 215 216 |
# File 'lib/smplkit/logging/models.rb', line 210 def set_level(level, environment: nil) if environment.nil? @level = level else @environments[environment] = LoggerEnvironment.new(level: level) end end |