hubbado-log 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c3427a0327c368a8e65bb9c42587ed49ea58714e70980b3a6050a82b1e3a81d
4
- data.tar.gz: edccc3f0c39bcfb0eac7b2a43f6bad28843592c003e2ebf1f64f1cd057be7d5d
3
+ metadata.gz: 2f5a8718b2c3ad60337526f487610af0018599583b425e83e2f546ee77c2ec1f
4
+ data.tar.gz: 9639ab626d0dad60a49de7c57f2df92b464c0cdd1234308d74ee9dd5e892a366
5
5
  SHA512:
6
- metadata.gz: e2e70e3dc5f3b3b2085f954517802cf8a3c0489c51574f9f5b9f747d97f8b6cff563dbde54752b38f1a9f159141b79072c2fb8c9fef8e70f998f64f549b5ab1b
7
- data.tar.gz: 8cfd3b8fc6b5ab56a7760a7543ffc3ad70bfbf7a89e020e3b3cc2d255fc3ec5123689d94dc130fef0e1dba08c8fd69f66130b08b056635c3bda0a0a3b51c5603
6
+ metadata.gz: 4f869e00dc13dce0a4b9e87a3e662ce49013bdb04fcb769ac343bccb4620aa5a542b7eaed5674f0cbe93e9f445fe0d6bfb4c1764ed708d316527d97f3c1d48d0
7
+ data.tar.gz: 0b689fb92e6f642292b1459c442dcc0e3ad352b5b0c956d5814dc2e7d5cf6c988dbee1a1fc06a3562aee5d7f84f6ae67ea04c4af54a8505cfaa83a765e84d3f7
data/ChangeLog.md CHANGED
@@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ # [1.1.0 - 2026-08-14]
8
+ ## Added
9
+ - A level, below which a line reaches no handler. Set it with `config.level`, or
10
+ with the `LOG_LEVEL` environment variable, which defaults to `info` — so
11
+ `debug` is off unless it is asked for.
12
+
13
+ ## Changed
14
+ - `Logger.new` takes a `level:` keyword. A logger built without one follows the
15
+ configuration.
16
+ - `LOG_LEVEL` is shared with Eventide's log gem, which writes names this gem does
17
+ not know. A name that is not a severity leaves the level at `info` rather than
18
+ raising.
19
+
7
20
  # [1.0.1 - 2024-05-30]
8
21
  # Changed
9
22
  - Release to stop a SHA mismatch between our private github package repo and Ruby Gems
data/README.md CHANGED
@@ -16,7 +16,29 @@ And then execute:
16
16
 
17
17
  Or install it yourself as:
18
18
 
19
- $ gem install hubbado-logger
19
+ $ gem install hubbado-log
20
+
21
+ ## Level
22
+
23
+ A line below the level reaches no handler.
24
+
25
+ ```ruby
26
+ Hubbado::Log.configuration do |config|
27
+ config.loggers = [MyStderrHandler]
28
+ config.level = :debug
29
+ end
30
+ ```
31
+
32
+ Without `config.level`, the level comes from the `LOG_LEVEL` environment variable:
33
+
34
+ $ LOG_LEVEL=debug ./my-command
35
+
36
+ It defaults to `info`, so `debug` is off until it is asked for. A single logger can
37
+ name its own with `Hubbado::Log::Logger.new(subject, handlers, level: :debug)`.
38
+
39
+ `LOG_LEVEL` is shared with Eventide's log gem, which writes names this gem does not
40
+ know. A name that is not one of `debug`, `info`, `warn`, `error`, `fatal` or
41
+ `unknown` leaves the level at `info` rather than raising.
20
42
 
21
43
  ## Development
22
44
 
data/hubbado-log.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "hubbado-log"
3
- s.version = "1.0.1"
3
+ s.version = "1.1.0"
4
4
  s.summary = "Lightweight pluggable logging system"
5
5
 
6
6
  s.authors = ["Hubbado Devs"]
@@ -1,10 +1,26 @@
1
1
  module Hubbado
2
2
  class Log
3
3
  class Configuration
4
+ # Tracing is off until somebody asks for it, which is what lets a debug line be written
5
+ # for a human watching one run without it also reaching every unattended log.
6
+ DEFAULT_LEVEL = :info
7
+
4
8
  attr_accessor :loggers
9
+ attr_reader :level
5
10
 
6
- def initialize
11
+ def initialize(level: nil)
7
12
  @loggers = []
13
+ self.level = level || DEFAULT_LEVEL
14
+ end
15
+
16
+ # A name rather than a severity is answered with the default instead of an exception.
17
+ # The level is set from LOG_LEVEL, which Eventide's log gem owns across hubbado_saas and
18
+ # writes its own vocabulary into ("_min"): a variable this gem shares is not a variable
19
+ # it can refuse.
20
+ def level=(value)
21
+ named = value.to_s.downcase.to_sym
22
+
23
+ @level = SEVERITIES.key?(named) ? named : DEFAULT_LEVEL
8
24
  end
9
25
  end
10
26
  end
@@ -5,7 +5,11 @@ module Hubbado
5
5
  SEVERITIES = { debug: 0, info: 1, warn: 2, error: 3, fatal: 4, unknown: 5 }.freeze
6
6
  STACKTRACE_SEVERITIES = %i[warn error fatal unknown].freeze
7
7
 
8
- @config = Configuration.new
8
+ LEVEL_VARIABLE = "LOG_LEVEL".freeze
9
+
10
+ # The one place the environment is read. A command names its level here or not at all,
11
+ # and everything downstream is handed the value rather than the variable.
12
+ @config = Configuration.new(level: ENV[LEVEL_VARIABLE])
9
13
 
10
14
  class << self
11
15
  attr_reader :config
@@ -4,16 +4,26 @@ module Hubbado
4
4
  attr_accessor :log_handlers
5
5
  attr_accessor :subject
6
6
 
7
- def initialize(subject, log_handlers = [])
7
+ def initialize(subject, log_handlers = [], level: nil)
8
8
  self.subject = subject
9
9
  self.log_handlers = Array(log_handlers)
10
+ @level = level
10
11
  end
11
12
 
13
+ # A logger built without one follows the configuration, which is every logger the gem
14
+ # builds itself: `Log.configure` names no level, so a class using the Dependency module
15
+ # takes whatever the process was configured for.
16
+ def level = @level || Log.config.level
17
+
12
18
  def log(severity, msg, data = nil)
13
19
  unless SEVERITIES.keys.include? severity.to_sym
14
20
  raise ArgumentError, "Unknown serverity #{severity}"
15
21
  end
16
22
 
23
+ # Read after the severity is checked, never before: the level decides what is printed,
24
+ # not what may be said, so quietening a logger must not turn a typo into silence.
25
+ return if SEVERITIES.fetch(severity.to_sym) < SEVERITIES.fetch(level)
26
+
17
27
  stacktrace = if data.is_a?(Exception)
18
28
  data.full_message
19
29
  elsif STACKTRACE_SEVERITIES.include?(severity)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hubbado-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hubbado Devs
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  requirements: []
110
- rubygems_version: 3.6.7
110
+ rubygems_version: 4.0.6
111
111
  specification_version: 4
112
112
  summary: Lightweight pluggable logging system
113
113
  test_files: []