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 +4 -4
- data/CHANGELOG.md +7 -0
- data/jekyll_plugin_logger.gemspec +11 -10
- data/lib/jekyll_plugin_logger/version.rb +1 -1
- data/lib/jekyll_plugin_logger.rb +30 -23
- data/lib/jekyll_plugin_meta_logger.rb +9 -3
- data/spec/jekyll_plugin_logger_spec.rb +3 -2
- data/spec/status_persistence.txt +5 -5
- metadata +3 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3c3467fff319002876010e4599258218a4d007fc76f6b78de3dbe4ca6f6e52be
|
|
4
|
+
data.tar.gz: 59811c6f5339fc5eafd5d1f6274739b56a8596cac113c6d1cb4c8a9a588ff808
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3ec77851f74498677d41088a0b121991cd4534bcc7d80f7a982c15b72abb50757fe4ab78acd11c8eceb09c79ee5675cf6bdc39126570b5cc978bb84aa9591f94
|
|
7
|
+
data.tar.gz: b24dd3fa24b79e16506ae4ea7dbe1340f5898f27d6f3c59f0c57d182365234d2638abf2635ad0d42544e792377591e3d9c4f5b54e9e80f63b15918cdc75f53de
|
data/CHANGELOG.md
CHANGED
|
@@ -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
|
|
7
|
-
spec.bindir
|
|
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
|
|
12
|
-
spec.files
|
|
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
|
|
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
|
|
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
|
|
29
|
+
spec.require_paths = ['lib']
|
|
29
30
|
spec.required_ruby_version = '>= 2.6.0'
|
|
30
|
-
spec.summary
|
|
31
|
-
spec.test_files
|
|
32
|
-
spec.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'
|
data/lib/jekyll_plugin_logger.rb
CHANGED
|
@@ -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(
|
|
15
|
+
# @logger = PluginMetaLogger.instance.new_logger(ref, PluginMetaLogger.instance.config)
|
|
15
16
|
#
|
|
16
|
-
#
|
|
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
|
|
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]
|
|
41
|
-
#
|
|
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 `
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
65
|
-
|
|
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 '
|
|
56
|
+
it 'defaults to warn level when no config' do
|
|
57
57
|
MyTestPlugin.exercise(PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config, $stdout))
|
|
58
|
-
|
|
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
|
data/spec/status_persistence.txt
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
example_id | status | run_time |
|
|
2
2
|
---------------------------------------- | ------ | --------------- |
|
|
3
|
-
./spec/jekyll_plugin_logger_spec.rb[1:1] | passed | 0.
|
|
4
|
-
./spec/jekyll_plugin_logger_spec.rb[1:2] | passed | 0.
|
|
5
|
-
./spec/jekyll_plugin_logger_spec.rb[1:3] | passed | 0.
|
|
6
|
-
./spec/jekyll_plugin_logger_spec.rb[1:4] | passed | 0.
|
|
7
|
-
./spec/jekyll_plugin_logger_spec.rb[1:5] | passed | 0.
|
|
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.
|
|
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:
|
|
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.
|
|
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:
|