jekyll_plugin_logger 2.1.2 → 2.1.3

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: 90e90f26bac683d004a6ba9c963d8b6532678dac4cc0e03eee15732742c2f936
4
- data.tar.gz: c1711187ac79bfd16ae6e357e647488f67c32e4b4526222d932e4c02c76615c4
3
+ metadata.gz: 3c3467fff319002876010e4599258218a4d007fc76f6b78de3dbe4ca6f6e52be
4
+ data.tar.gz: 59811c6f5339fc5eafd5d1f6274739b56a8596cac113c6d1cb4c8a9a588ff808
5
5
  SHA512:
6
- metadata.gz: 1ae7813c1bdac1068b72633198d3e09518590d55982cdc2ee0a178d6b655e4022419d7f49baa16d5dace49f6a1a4c72bb9ff9118e192aef48db9970c48de8bec
7
- data.tar.gz: fe1bbdc922dd1a0a3cbf5af36dbdf7e5fd67ca12dc8c14b55361d9b9cbef61aa1983abb616dfda460ef3b626a721353cc61c6e4b5b6286c9804a8b6b83a7aec3
6
+ metadata.gz: 3ec77851f74498677d41088a0b121991cd4534bcc7d80f7a982c15b72abb50757fe4ab78acd11c8eceb09c79ee5675cf6bdc39126570b5cc978bb84aa9591f94
7
+ data.tar.gz: b24dd3fa24b79e16506ae4ea7dbe1340f5898f27d6f3c59f0c57d182365234d2638abf2635ad0d42544e792377591e3d9c4f5b54e9e80f63b15918cdc75f53de
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## 2.1.3 / 2025-11-21
4
+
5
+ * Improved comments.
6
+ * Improved PluginMetaLogger.new_logger debug output.
7
+ * Fixed initial log level always being INFO
8
+
9
+
3
10
  ## 2.1.2 / 2023-11-21
4
11
 
5
12
  * Added `demo`.
@@ -3,15 +3,15 @@ require_relative 'lib/jekyll_plugin_logger/version'
3
3
  Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
4
4
  github = 'https://github.com/mslinn/jekyll_plugin_logger'
5
5
 
6
- spec.authors = ['Mike Slinn']
7
- spec.bindir = 'exe'
6
+ spec.authors = ['Mike Slinn']
7
+ spec.bindir = 'exe'
8
8
  spec.description = <<~END_OF_DESC
9
9
  Generates Jekyll logger with colored output.
10
10
  END_OF_DESC
11
- spec.email = ['mslinn@mslinn.com']
12
- spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
11
+ spec.email = ['mslinn@mslinn.com']
12
+ spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
13
13
  spec.homepage = 'https://www.mslinn.com/jekyll_plugins/jekyll_plugin_logger.html'
14
- spec.license = 'MIT'
14
+ spec.license = 'MIT'
15
15
  spec.metadata = {
16
16
  'allowed_push_host' => 'https://rubygems.org',
17
17
  'bug_tracker_uri' => "#{github}/issues",
@@ -19,17 +19,18 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
19
19
  'homepage_uri' => spec.homepage,
20
20
  'source_code_uri' => github,
21
21
  }
22
- spec.name = 'jekyll_plugin_logger'
22
+ spec.name = 'jekyll_plugin_logger'
23
+ spec.platform = Gem::Platform::RUBY
23
24
  spec.post_install_message = <<~END_MESSAGE
24
25
 
25
26
  Thanks for installing #{spec.name}!
26
27
 
27
28
  END_MESSAGE
28
- spec.require_paths = ['lib']
29
+ spec.require_paths = ['lib']
29
30
  spec.required_ruby_version = '>= 2.6.0'
30
- spec.summary = 'Generates a Jekyll logger with colored output.'
31
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
32
- spec.version = JekyllPluginLoggerVersion::VERSION
31
+ spec.summary = 'Generates a Jekyll logger with colored output.'
32
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
33
+ spec.version = JekyllPluginLoggerVersion::VERSION
33
34
 
34
35
  spec.add_dependency 'bump'
35
36
  spec.add_dependency 'jekyll', '>= 3.5.0'
@@ -1,3 +1,3 @@
1
1
  module JekyllPluginLoggerVersion
2
- VERSION = '2.1.2'.freeze
2
+ VERSION = '2.1.3'.freeze
3
3
  end
@@ -10,13 +10,16 @@ end
10
10
 
11
11
  # Once the meta-logger is made (see `PluginMetaLogger`, below) new instances of `PluginLogger` can be created with log levels set
12
12
  # by `config` entries.
13
+ #
13
14
  # @example Create new `PluginLogger`s like this:
14
- # @logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
15
+ # @logger = PluginMetaLogger.instance.new_logger(ref, PluginMetaLogger.instance.config)
15
16
  #
16
- # self can be a module, a class, a string, or a symbol.
17
+ # ref can be a module name, a class name, a string, or a symbol.
17
18
  #
19
+ # Logger usage:
18
20
  # Best practice is to invoke `info`, `warn, `debug` and `error` methods by passing blocks that contain the message.
19
21
  # The blocks will only be evaluated if output for that level is enabled.
22
+ #
20
23
  # @example Use `PluginLogger`s like this:
21
24
  # @logger.info { "This is only evaluated if info level debugging is enabled" }
22
25
  #
@@ -24,24 +27,12 @@ end
24
27
  # @see https://ruby-doc.org/stdlib-2.7.1/libdoc/logger/rdoc/Logger.html
25
28
  class PluginLogger
26
29
  # This method should only be called by PluginMetaLogger
27
- # @param log_level [String, Symbol, Integer] can be specified as $stderr or $stdout,
28
- # or an integer from 0..3 (inclusive),
29
- # or as a case-insensitive string
30
- # (`debug`, `info`, `warn`, `error`, or `DEBUG`, `INFO`, `WARN`, `ERROR`),
31
- # or as a symbol (`:debug`, `:info`, `:warn`, `:error` ).
32
- #
33
- # 0: debug
34
- # 1: info
35
- # 2: warn
36
- # 3: error
37
- # 4: fatal
38
- # 5: unknown (displays as ANY)
30
+ # @param stream_name [String, Symbol, Integer] can be specified as $stderr or $stdout
39
31
  #
40
- # @param config [YAML] is normally created by reading a YAML file such as Jekyll's `_config.yml`.
41
- # When invoking from a Jekyll plugin, provide `site.config`,
42
- # which is available from all types of Jekyll plugins as `Jekyll.configuration({})`.
32
+ # @param config [YAML] can accept configuration data, usually a reference to `site.config`,
33
+ # stored in `PluginMetaLogger.instance.config`.
43
34
  #
44
- # @example If `progname` has value `abc`, then the YAML to override the programmatically set log_level to `debug` is:
35
+ # @example If `klass` has value `abc`, then the YAML to override the programmatically set log_level to `debug` is:
45
36
  # logger_factory:
46
37
  # abc: debug
47
38
  def initialize(klass, config = nil, stream_name = $stdout)
@@ -50,7 +41,8 @@ class PluginLogger
50
41
 
51
42
  @logger = Logger.new stream_name
52
43
  @logger.progname = derive_progname klass
53
- @logger.level = :info
44
+ # Default to :warn when no config, so INFO messages are suppressed until config is loaded
45
+ @logger.level = (config.nil? || config.empty?) ? :warn : :info
54
46
  @logger.level = plugin_loggers[@logger.progname] if plugin_loggers&.[] @logger.progname
55
47
  # puts "PluginLogger.initialize: @logger.progname=#{@logger.progname} set to #{@logger.level}".red
56
48
  @logger.formatter = proc { |severity, _datetime, progname, msg|
@@ -74,6 +66,17 @@ class PluginLogger
74
66
  end
75
67
  end
76
68
 
69
+ # @param value [String, Symbol, Integer] can be an integer from 0..3 (inclusive),
70
+ # or a case-insensitive string
71
+ # (`debug`, `info`, `warn`, `error`, or `DEBUG`, `INFO`, `WARN`, `ERROR`),
72
+ # or a symbol (`:debug`, `:info`, `:warn`, `:error` ).
73
+ #
74
+ # 0: debug
75
+ # 1: info
76
+ # 2: warn
77
+ # 3: error
78
+ # 4: fatal
79
+ # 5: unknown (displays as ANY)
77
80
  def level=(value)
78
81
  @logger.level = value
79
82
  end
@@ -144,9 +147,13 @@ class PluginLogger
144
147
  end
145
148
  end
146
149
 
147
- Jekyll::Hooks.register(:site, :after_reset, priority: :high) do |site|
150
+ # When Jekyll first starts, this code reads the contents of `_config.yml` that was stored in `site.config`,
151
+ # and stores a reference to the configuration information in `PluginMetaLogger.instance.config` for when loggers are
152
+ # created in the future.
153
+ # The `site.config` information is used by `PluginLogger.initialize` to automatically configure new loggers.
154
+ Jekyll::Hooks.register(:site, :after_init, priority: :high) do |site|
148
155
  instance = PluginMetaLogger.instance
149
- logger = instance.new_logger(PluginMetaLogger, site.config)
150
- logger.info { "Loaded #{JekyllPluginLoggerName::PLUGIN_NAME} v#{JekyllPluginLoggerVersion::VERSION} plugin." }
151
- logger.debug { "Logger for #{instance.logger.progname} created at level #{instance.level_as_sym}" }
156
+ instance.logger = instance.new_logger(PluginMetaLogger, site.config)
157
+ instance.logger.info { "Loaded #{JekyllPluginLoggerName::PLUGIN_NAME} v#{JekyllPluginLoggerVersion::VERSION} plugin." }
158
+ instance.logger.debug { "Logger for #{instance.logger.progname} created at level #{instance.level_as_sym}" }
152
159
  end
@@ -31,6 +31,7 @@ require 'singleton'
31
31
  class PluginMetaLogger
32
32
  include Singleton
33
33
  attr_reader :config, :logger
34
+ attr_writer :logger
34
35
 
35
36
  def initialize
36
37
  super
@@ -39,10 +40,12 @@ class PluginMetaLogger
39
40
  end
40
41
 
41
42
  def info(&block)
43
+ # Delegate to @logger which respects the configured level
42
44
  @logger.info(self) { yield block }
43
45
  end
44
46
 
45
47
  def debug(&block)
48
+ # Delegate to @logger which respects the configured level
46
49
  @logger.debug(self) { yield block }
47
50
  end
48
51
 
@@ -58,13 +61,16 @@ class PluginMetaLogger
58
61
  @logger.error(self) { yield block }
59
62
  end
60
63
 
64
+ # By the time this method is called, `PluginMetaLogger.instance.config` contains the entire contents of `_config.yml`
61
65
  def new_logger(klass, config = nil, stream_name = $stdout)
62
66
  @config ||= config
63
67
  if @config.nil?
64
- puts { 'Error: PluginMetaLogger has not been initialized with site.config.'.red }
65
- PluginLogger.new(klass, {}, stream_name)
68
+ logger = PluginLogger.new(klass, {}, stream_name)
69
+ logger.debug { 'PluginMetaLogger was not initialized from site.config.' }
66
70
  else
67
- PluginLogger.new(klass, @config, stream_name)
71
+ logger = PluginLogger.new(klass, @config, stream_name)
72
+ logger.debug { 'PluginMetaLogger was initialized from site.config.' }
68
73
  end
74
+ logger
69
75
  end
70
76
  end
@@ -53,9 +53,10 @@ class MyTestPlugin
53
53
  end
54
54
 
55
55
  RSpec.describe PluginLogger do
56
- it 'outputs at info level' do
56
+ it 'defaults to warn level when no config' do
57
57
  MyTestPlugin.exercise(PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config, $stdout))
58
- expect(PluginMetaLogger.instance.level_as_sym).to eq(:info)
58
+ # Default level is :warn when no config is provided (suppresses INFO during gem loading)
59
+ expect(PluginMetaLogger.instance.level_as_sym).to eq(:warn)
59
60
  end
60
61
 
61
62
  it 'uses config debug' do
@@ -1,7 +1,7 @@
1
1
  example_id | status | run_time |
2
2
  ---------------------------------------- | ------ | --------------- |
3
- ./spec/jekyll_plugin_logger_spec.rb[1:1] | passed | 0.00004 seconds |
4
- ./spec/jekyll_plugin_logger_spec.rb[1:2] | passed | 0.00005 seconds |
5
- ./spec/jekyll_plugin_logger_spec.rb[1:3] | passed | 0.00009 seconds |
6
- ./spec/jekyll_plugin_logger_spec.rb[1:4] | passed | 0.00005 seconds |
7
- ./spec/jekyll_plugin_logger_spec.rb[1:5] | passed | 0.00117 seconds |
3
+ ./spec/jekyll_plugin_logger_spec.rb[1:1] | passed | 0.00032 seconds |
4
+ ./spec/jekyll_plugin_logger_spec.rb[1:2] | passed | 0.0002 seconds |
5
+ ./spec/jekyll_plugin_logger_spec.rb[1:3] | passed | 0.0002 seconds |
6
+ ./spec/jekyll_plugin_logger_spec.rb[1:4] | passed | 0.00078 seconds |
7
+ ./spec/jekyll_plugin_logger_spec.rb[1:5] | passed | 0.00025 seconds |
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_plugin_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-11-22 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bump
@@ -86,8 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
85
  - !ruby/object:Gem::Version
87
86
  version: '0'
88
87
  requirements: []
89
- rubygems_version: 3.3.7
90
- signing_key:
88
+ rubygems_version: 3.7.2
91
89
  specification_version: 4
92
90
  summary: Generates a Jekyll logger with colored output.
93
91
  test_files: