jekyll_plugin_logger 2.0.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7a503b502ebd28c7bfe8ed9237ae721560135f1620054da34ece8275cfb5118
4
- data.tar.gz: 5285da27eebe3005f00562260e38117a8d685a8f10b8ab5bf444ee804d17cf46
3
+ metadata.gz: 6d9885c654b34790e6f52a8e3a92a008cc51a40fc2a6ea404037f0e3e929291d
4
+ data.tar.gz: 72130fb28aea51696ae2ddf2be772e330dfd7d59ba2f0cc14d2545093c572c25
5
5
  SHA512:
6
- metadata.gz: ebc0a877d7bf80fe01e1609123ea93900ce9a23e96c877e3d304128543946c1fe31613c3af9b50324fa5fdf030170a06f5f2b79ba02d3fd079f7797931639088
7
- data.tar.gz: 516fb3f7250fce0bacf7f5a2e782111e358ab0e979cd98950a7105faa0516d657423e88499dfd9534c05c9c70dec00431475a8c1f72be1b166b2164cc0018c56
6
+ metadata.gz: 509269138c34ff09d9a226657f07443155b89349681929218390b8041dc49b9497c2278c6f5ab6074fdfd7b1541a5caf7b5076eaa45524a734c64d0b6639c98e
7
+ data.tar.gz: 798aeac0b80dd88b3cbbe6e174511afd1b5c4df87325adf54af7683051a87776f83310097424e0dd7dc0c6030fdc7648311df982bd68d05c9d95b72f9c423054
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 2.1.1 / 2022-04-15
2
+ * Fixed progname reference for metalogger debug startup statement
3
+
4
+ ## 2.1.0 / 2022-04-05
5
+ * Changed how config info is made available
6
+
7
+ ## 2.0.1 / 2022-04-05
8
+ * Changed to registration hook to `:site`, `:after_reset` because that is the first hook that gets called.
9
+ * Improved the detection of various types of `progname`
10
+
1
11
  ## 2.0.0 / 2022-03-16
2
12
  * Completely rewrote this plugin, now not a class, but a module that monkey patches the existing Jekyll logger for compatibility.
3
13
  * Renamed the gem from `jekyll_logger_factory` to `jekyll_plugin_logger`.
data/Rakefile CHANGED
@@ -1,7 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "bump/tasks"
3
4
  require "bundler/gem_tasks"
4
5
  require "rspec/core/rake_task"
5
6
 
7
+ # do not always tag the version
8
+ # Bump.tag_by_default = false
9
+
10
+ # bump the version in additional files
11
+ # Bump.replace_in_default = ["Readme.md"]
12
+
13
+ # Maintain changelog:
14
+ Bump.changelog = true
15
+
16
+ # Open the changelog in an editor when bumping
17
+ Bump.changelog = :editor
18
+
19
+ # Configure bump to not use a prefix:
20
+ ENV["TAG_PREFIX"] = ""
21
+
6
22
  RSpec::Core::RakeTask.new(:spec)
7
23
  task :default => :spec
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.required_ruby_version = ">= 2.6.0"
33
33
  spec.summary = "Generates Jekyll logger with colored output."
34
34
  spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
35
- spec.version = JekyllPluginLogger::VERSION
35
+ spec.version = JekyllPluginLoggerVersion::VERSION
36
36
 
37
37
  spec.add_dependency "jekyll", ">= 3.5.0"
38
38
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module JekyllPluginLogger
4
- VERSION = "2.0.0"
3
+ module JekyllPluginLoggerVersion
4
+ VERSION = "2.1.1"
5
5
  end
@@ -10,13 +10,14 @@ module JekyllPluginLoggerName
10
10
  PLUGIN_NAME = "jekyll_plugin_logger"
11
11
  end
12
12
 
13
- # Once the meta-logger is made (see `PluginMetaLogger``, below) new instances of `PluginLogger` can be created with log levels set by `config` entries.
13
+ # Once the meta-logger is made (see `PluginMetaLogger`, below) new instances of `PluginLogger` can be created with log levels set
14
+ # by `config` entries.
14
15
  # @example Create new `PluginLogger`s like this:
15
- # @logger = PluginMetaLogger.instance.new_logger(self)
16
+ # @logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
16
17
  #
17
- # self can be a class, a string, or a symbol.
18
+ # self can be a module, a class, a string, or a symbol.
18
19
  #
19
- # Best practice is to invoke `info``, `warn, `debug`` and `error`` methods by passing blocks that contain the message.
20
+ # Best practice is to invoke `info`, `warn, `debug` and `error` methods by passing blocks that contain the message.
20
21
  # The blocks will only be evaluated if output for that level is enabled.
21
22
  # @example Use `PluginLogger`s like this:
22
23
  # @logger.info { "This is only evaluated if info level debugging is enabled" }
@@ -24,8 +25,6 @@ end
24
25
  # For more information about the logging feature in the Ruby standard library,
25
26
  # @see https://ruby-doc.org/stdlib-2.7.1/libdoc/logger/rdoc/Logger.html
26
27
  class PluginLogger
27
- include JekyllPluginLogger
28
-
29
28
  # This method should only be called by PluginMetaLogger
30
29
  # @param log_level [String, Symbol, Integer] can be specified as $stderr or $stdout,
31
30
  # or an integer from 0..3 (inclusive),
@@ -40,12 +39,13 @@ class PluginLogger
40
39
  # @example If `progname` has value `abc`, then the YAML to override the programmatically set log_level to `debug` is:
41
40
  # logger_factory:
42
41
  # abc: debug
43
- def initialize(klass, config, stream_name = $stdout)
42
+ def initialize(klass, config = nil, stream_name = $stdout)
43
+ @config = config
44
44
  @logger = Logger.new(stream_name)
45
45
  @logger.progname = derive_progname(klass)
46
46
  @logger.level = :info
47
- plugin_loggers = config["plugin_loggers"]
48
- @logger.level ||= plugin_loggers["PluginMetaLogger"] if plugin_loggers
47
+ plugin_loggers = config ? config["plugin_loggers"] : nil
48
+ @logger.level = plugin_loggers[@logger.progname] if plugin_loggers && plugin_loggers[@logger.progname]
49
49
  # puts "PluginLogger.initialize: @logger.progname=#{@logger.progname} set to #{@logger.level}".red
50
50
  @logger.formatter = proc { |severity, _, prog_name, msg|
51
51
  "#{severity} #{prog_name}: #{msg}\n"
@@ -100,26 +100,26 @@ class PluginLogger
100
100
  end
101
101
  end
102
102
 
103
- private
104
-
105
- def derive_progname(klass)
106
- full_name = case klass.class
107
- when String
108
- klass
109
- when Symbol
110
- klass.to_s
111
- else
112
- klass.class.name
113
- end
114
- full_name.split("::").last
115
- end
116
-
117
103
  # Available colors are: :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, and the modifier :bold
118
104
  def level_as_sym
119
105
  return :unknown if @logger.level.negative? || level > 4
120
106
 
121
107
  [:debug, :info, :warn, :error, :fatal, :unknown][@logger.level]
122
108
  end
109
+
110
+ private
111
+
112
+ def derive_progname(klass)
113
+ class_name = klass.class.to_s
114
+ case class_name
115
+ when "Class"
116
+ klass.to_s.split("::").last # class_name.name.split("::").last
117
+ when "Module", "Symbol", "String"
118
+ klass.to_s.split("::").last
119
+ else
120
+ class_name
121
+ end
122
+ end
123
123
  end
124
124
 
125
125
  # Makes a meta-logger instance (a singleton) with level set by `site.config`.
@@ -133,7 +133,8 @@ end
133
133
  #
134
134
  # @example
135
135
  # # Create and initialize the meta-logger singleton in a high priority Jekyll `site` `:after_init` hook:
136
- # PluginMetaLogger.instance.setup(site.config).info { "Meta-logger has been created" }
136
+ # @meta_logger = PluginMetaLogger.instance.new_logger(site.config, self)
137
+ # @meta_logger.info { "Meta-logger has been created" }
137
138
  #
138
139
  # # In `config.yml`:
139
140
  # plugin_loggers:
@@ -143,13 +144,13 @@ end
143
144
  # ArchiveDisplayTag: debug
144
145
  #
145
146
  # # In a Jekyll plugin:
146
- # @logger = PluginMetaLogger.instance.new_logger(self)
147
+ # @logger = PluginMetaLogger.instance.setup(self)
147
148
  # @logger.info { "This is a log message from a Jekyll plugin" }
148
149
  # #
149
150
  # PluginMetaLogger.instance.info { "MyPlugin vX.Y.Z has been loaded" }
150
151
  class PluginMetaLogger
151
152
  include Singleton
152
- attr_reader :logger
153
+ attr_reader :config, :logger
153
154
 
154
155
  def initialize
155
156
  super
@@ -165,6 +166,10 @@ class PluginMetaLogger
165
166
  @logger.debug(self) { yield }
166
167
  end
167
168
 
169
+ def level_as_sym
170
+ @logger.level_as_sym
171
+ end
172
+
168
173
  def warn
169
174
  @logger.warn(self) { yield }
170
175
  end
@@ -173,25 +178,20 @@ class PluginMetaLogger
173
178
  @logger.error(self) { yield }
174
179
  end
175
180
 
176
- def new_logger(klass, stream_name = $stdout)
181
+ def new_logger(klass, config = nil, stream_name = $stdout)
182
+ @config ||= config
177
183
  if @config.nil?
178
- puts { "Error: PluginMetaLogger has not been initialized by calling setup yet.".red }
184
+ puts { "Error: PluginMetaLogger has not been initialized with site.config.".red }
179
185
  PluginLogger.new(klass, {}, stream_name)
180
186
  else
181
187
  PluginLogger.new(klass, @config, stream_name)
182
188
  end
183
189
  end
184
-
185
- def setup(config, stream_name = $stdout)
186
- @config = config
187
- @logger = new_logger(self, stream_name)
188
- @logger
189
- end
190
190
  end
191
191
 
192
- Jekyll::Hooks.register(:site, :after_init, :priority => :high) do |site|
192
+ Jekyll::Hooks.register(:site, :after_reset, :priority => :high) do |site|
193
193
  instance = PluginMetaLogger.instance
194
- logger = instance.setup(site.config)
195
- logger.info { "Loaded #{JekyllPluginLoggerName::PLUGIN_NAME} v#{JekyllPluginLogger::VERSION} plugin." }
196
- logger.debug { "Logger for #{instance.progname} created at level #{instance.level_as_sym}" }
194
+ logger = instance.new_logger(PluginMetaLogger, site.config)
195
+ logger.info { "Loaded #{JekyllPluginLoggerName::PLUGIN_NAME} v#{JekyllPluginLoggerVersion::VERSION} plugin." }
196
+ logger.debug { "Logger for #{instance.logger.progname} created at level #{instance.level_as_sym}" }
197
197
  end
@@ -19,26 +19,17 @@ require_relative "../lib/jekyll_plugin_logger"
19
19
  class MyTestPlugin
20
20
  instance = PluginMetaLogger.instance
21
21
  logger = instance.new_logger(self) # Should generate a warning
22
- instance.setup({})
23
22
  PluginMetaLogger.instance.info { "How now, brown cow" }
24
23
  PluginMetaLogger.instance.debug { "How now, brown cow" }
25
24
  PluginMetaLogger.instance.warn { "How now, brown cow" }
26
25
  PluginMetaLogger.instance.error { "How now, brown cow" }
27
26
 
28
- logger = PluginMetaLogger.instance.new_logger(self)
27
+ logger = PluginMetaLogger.instance.new_logger(self, RSpec.configuration.site_config)
29
28
  logger.debug { "3 fleas fleeing freedom" }
30
29
  logger.info { "3 fleas fleeing freedom" }
31
30
  logger.warn { "3 fleas fleeing freedom" }
32
31
  logger.error { "3 fleas fleeing freedom" }
33
32
 
34
- _yaml = <<~END_YAML
35
- plugin_loggers:
36
- PluginMetaLogger: debug
37
- SiteInspector: warn
38
- MakeArchive: error
39
- ArchiveDisplayTag: debug
40
- END_YAML
41
-
42
33
  def self.exercise(logger)
43
34
  puts
44
35
  # puts "\ncalling_class_name=#{logger.send(:calling_class_name)}"
@@ -63,18 +54,33 @@ class MyTestPlugin
63
54
  logger.error { "Error message 4" }
64
55
  end
65
56
 
66
- RSpec.describe JekyllPluginLogger do
67
- it "outputs at debug level" do
68
- MyTestPlugin.exercise(PluginMetaLogger.instance.new_logger(self, $stdout))
57
+ RSpec.describe PluginLogger do
58
+ it "outputs at info level" do
59
+ MyTestPlugin.exercise(PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config, $stdout))
60
+ expect(PluginMetaLogger.instance.level_as_sym).to eq(:info)
61
+ end
62
+
63
+ it "uses config debug" do
64
+ logger = PluginMetaLogger.instance.new_logger(:MyBlock, PluginMetaLogger.instance.config)
65
+ expect(logger.level_as_sym).to eq(:debug)
66
+ MyTestPlugin.exercise(logger)
67
+ end
68
+
69
+ it "uses config info" do
70
+ logger = PluginMetaLogger.instance.new_logger(:ArchiveDisplayTag, PluginMetaLogger.instance.config)
71
+ expect(logger.level_as_sym).to eq(:info)
72
+ MyTestPlugin.exercise(logger)
69
73
  end
70
74
 
71
75
  it "uses config warn" do
72
- logger = PluginMetaLogger.instance.new_logger("SiteInspector", $stdout)
76
+ logger = PluginMetaLogger.instance.new_logger("SiteInspector", PluginMetaLogger.instance.config, $stdout)
77
+ expect(logger.level_as_sym).to eq(:warn)
73
78
  MyTestPlugin.exercise(logger)
74
79
  end
75
80
 
76
81
  it "uses config error" do
77
- logger = PluginMetaLogger.instance.new_logger(:MakeArchive)
82
+ logger = PluginMetaLogger.instance.new_logger(:PreTagBlock, PluginMetaLogger.instance.config)
83
+ expect(logger.level_as_sym).to eq(:error)
78
84
  MyTestPlugin.exercise(logger)
79
85
  end
80
86
  end
data/spec/spec_helper.rb CHANGED
@@ -6,7 +6,25 @@ require_relative "../lib/jekyll_plugin_logger"
6
6
  Jekyll.logger.log_level = :info
7
7
 
8
8
  RSpec.configure do |config|
9
- config.run_all_when_everything_filtered = true
9
+ plugin_config = <<~END_CONFIG
10
+ plugin_loggers:
11
+ ArchiveDisplayTag: info
12
+ FlexibleInclude: info
13
+ MakeArchive: info
14
+ MyBlock: debug
15
+ PluginMetaLogger: info
16
+ PreTagBlock: error
17
+ SiteInspector: warn
18
+ UnselectableTag: info
19
+ END_CONFIG
20
+
21
+ config.add_setting :site_config
22
+ config.site_config = YAML.safe_load(plugin_config)
23
+
10
24
  config.filter_run :focus
11
25
  config.order = "random"
26
+ config.run_all_when_everything_filtered = true
27
+
28
+ # See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
29
+ config.example_status_persistence_file_path = "spec/status_persistence.txt"
12
30
  end
@@ -0,0 +1,7 @@
1
+ example_id | status | run_time |
2
+ ---------------------------------------- | ------ | --------------- |
3
+ ./spec/jekyll_plugin_logger_spec.rb[1:1] | failed | 0.02037 seconds |
4
+ ./spec/jekyll_plugin_logger_spec.rb[1:2] | passed | 0.03764 seconds |
5
+ ./spec/jekyll_plugin_logger_spec.rb[1:3] | passed | 0.00041 seconds |
6
+ ./spec/jekyll_plugin_logger_spec.rb[1:4] | passed | 0.00026 seconds |
7
+ ./spec/jekyll_plugin_logger_spec.rb[1:5] | passed | 0.0002 seconds |
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_plugin_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-25 00:00:00.000000000 Z
11
+ date: 2022-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -69,8 +69,9 @@ files:
69
69
  - jekyll_plugin_logger.gemspec
70
70
  - lib/jekyll_plugin_logger.rb
71
71
  - lib/jekyll_plugin_logger/version.rb
72
- - spec/jekyll_plugin_logger.rb
72
+ - spec/jekyll_plugin_logger_spec.rb
73
73
  - spec/spec_helper.rb
74
+ - spec/status_persistence.txt
74
75
  homepage: https://www.mslinn.com/blog/2020/12/28/custom-logging-in-jekyll-plugins.html
75
76
  licenses:
76
77
  - MIT
@@ -103,5 +104,6 @@ signing_key:
103
104
  specification_version: 4
104
105
  summary: Generates Jekyll logger with colored output.
105
106
  test_files:
106
- - spec/jekyll_plugin_logger.rb
107
+ - spec/jekyll_plugin_logger_spec.rb
107
108
  - spec/spec_helper.rb
109
+ - spec/status_persistence.txt