jekyll_plugin_logger 2.1.1 → 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: 6d9885c654b34790e6f52a8e3a92a008cc51a40fc2a6ea404037f0e3e929291d
4
- data.tar.gz: 72130fb28aea51696ae2ddf2be772e330dfd7d59ba2f0cc14d2545093c572c25
3
+ metadata.gz: 3c3467fff319002876010e4599258218a4d007fc76f6b78de3dbe4ca6f6e52be
4
+ data.tar.gz: 59811c6f5339fc5eafd5d1f6274739b56a8596cac113c6d1cb4c8a9a588ff808
5
5
  SHA512:
6
- metadata.gz: 509269138c34ff09d9a226657f07443155b89349681929218390b8041dc49b9497c2278c6f5ab6074fdfd7b1541a5caf7b5076eaa45524a734c64d0b6639c98e
7
- data.tar.gz: 798aeac0b80dd88b3cbbe6e174511afd1b5c4df87325adf54af7683051a87776f83310097424e0dd7dc0c6030fdc7648311df982bd68d05c9d95b72f9c423054
6
+ metadata.gz: 3ec77851f74498677d41088a0b121991cd4534bcc7d80f7a982c15b72abb50757fe4ab78acd11c8eceb09c79ee5675cf6bdc39126570b5cc978bb84aa9591f94
7
+ data.tar.gz: b24dd3fa24b79e16506ae4ea7dbe1340f5898f27d6f3c59f0c57d182365234d2638abf2635ad0d42544e792377591e3d9c4f5b54e9e80f63b15918cdc75f53de
data/.rubocop.yml CHANGED
@@ -1,21 +1,85 @@
1
- require: rubocop-jekyll
2
- inherit_gem:
3
- rubocop-jekyll: .rubocop.yml
1
+ require:
2
+ # - rubocop-jekyll
3
+ - rubocop-md
4
+ - rubocop-performance
5
+ - rubocop-rake
6
+ - rubocop-rspec
7
+
8
+ # inherit_gem:
9
+ # rubocop-jekyll: .rubocop.yml
4
10
 
5
11
  AllCops:
6
12
  Exclude:
7
- - vendor/**/*
8
- - Gemfile*
9
- - '*.gemspec' # This does nothing. Why?
13
+ - demo/_site/**/*
14
+ - binstub/**/*
15
+ - vendor/**/*
16
+ - jekyll_plugin_logger.gemspec
10
17
  NewCops: enable
11
- TargetRubyVersion: 2.6
12
18
 
13
- Jekyll/NoPutsAllowed:
19
+ Gemspec/DeprecatedAttributeAssignment:
20
+ Enabled: false
21
+
22
+ Gemspec/RequiredRubyVersion:
23
+ Enabled: false
24
+
25
+ Gemspec/RequireMFA:
26
+ Enabled: false
27
+
28
+ # Jekyll/NoPutsAllowed:
29
+ # Exclude:
30
+ # - spec/**/*
31
+
32
+ Layout/InitialIndentation:
14
33
  Exclude:
15
- - spec/**/*
34
+ - README.md
35
+
36
+ Layout/HashAlignment:
37
+ EnforcedColonStyle: table
38
+ EnforcedHashRocketStyle: table
16
39
 
17
40
  Layout/LineLength:
18
41
  Max: 150
19
42
 
20
- # Gemspec/RequireMFA:
21
- # enable: false
43
+ Lint/RedundantCopDisableDirective:
44
+ Exclude:
45
+ - jekyll_plugin_logger.gemspec
46
+
47
+ Metrics/AbcSize:
48
+ Max: 25
49
+
50
+ Metrics/BlockLength:
51
+ Exclude:
52
+ - jekyll_plugin_logger.gemspec
53
+ - spec/**/*
54
+
55
+ Metrics/ClassLength:
56
+ Exclude:
57
+ - spec/**/*
58
+
59
+ Metrics/CyclomaticComplexity:
60
+ Max: 25
61
+
62
+ Metrics/MethodLength:
63
+ Max: 25
64
+
65
+ Metrics/PerceivedComplexity:
66
+ Max: 20
67
+
68
+ Naming/FileName:
69
+ Exclude:
70
+ - Rakefile
71
+
72
+ RSpec/ExampleLength:
73
+ Max: 20
74
+
75
+ RSpec/MultipleExpectations:
76
+ Max: 15
77
+
78
+ Style/Documentation:
79
+ Enabled: false
80
+
81
+ Style/FrozenStringLiteralComment:
82
+ Enabled: false
83
+
84
+ Style/TrailingCommaInHashLiteral:
85
+ EnforcedStyleForMultiline: comma
data/CHANGELOG.md CHANGED
@@ -1,25 +1,54 @@
1
+ # Change Log
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
+
10
+ ## 2.1.2 / 2023-11-21
11
+
12
+ * Added `demo`.
13
+ * Added `fatal` and `unknown` log levels.
14
+
15
+
1
16
  ## 2.1.1 / 2022-04-15
2
- * Fixed progname reference for metalogger debug startup statement
17
+
18
+ * Fixed `progname` reference for the `PluginMetaLogger` debug startup statement.
19
+
3
20
 
4
21
  ## 2.1.0 / 2022-04-05
5
- * Changed how config info is made available
22
+
23
+ * Changed how config info is made available.
24
+ * `PluginLogger` is a class once again.
25
+
6
26
 
7
27
  ## 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`
28
+
29
+ * Changed to registration hook to `:site`, `:after_reset` because that is the first hook that gets called.
30
+ * Improved the detection of various types of `progname`.
31
+
10
32
 
11
33
  ## 2.0.0 / 2022-03-16
12
- * Completely rewrote this plugin, now not a class, but a module that monkey patches the existing Jekyll logger for compatibility.
13
- * Renamed the gem from `jekyll_logger_factory` to `jekyll_plugin_logger`.
14
- * Automatically obtains plugin class name and uses that as `progname`.
15
- * `:into` level output is colored cyan.
34
+
35
+ * Completely rewrote this plugin, now not a class,
36
+ but a module that monkey patches the existing Jekyll logger for compatibility.
37
+ * Renamed the gem from `jekyll_logger_factory` to `jekyll_plugin_logger`.
38
+ * Automatically obtains plugin class name and uses that as `progname`.
39
+ * `:into` level output is colored cyan.
40
+
16
41
 
17
42
  ## 1.0.0 / 2022-03-16
18
- * Published as a gem.
19
- * New instances are now created with `new` instead of `create_logger`.
20
- * Now subclasses Jekyll's Stevenson logger.
21
- * Documentation improved, clarifies that the only supported levels are those provided by the Stevenson logger: `:debug`, `:info`, and `:error`.
22
- * No longer supports control over where log output goes; STDERR and STDOUT are automatically selected according to log level.
43
+
44
+ * Published as a gem.
45
+ * New instances are now created with `new` instead of `create_logger`.
46
+ * Now subclasses Jekyll's Stevenson logger.
47
+ * Documentation improved, clarifies that the only supported levels are those provided by the
48
+ Stevenson logger: `:debug`, `:info`, and `:error`.
49
+ * No longer supports control over where log output goes; STDERR and STDOUT are automatically selected according to log level.
50
+
23
51
 
24
52
  ## 2020-12-28
25
- * Initial version published at https://www.mslinn.com/blog/2020/12/28/custom-logging-in-jekyll-plugins.html
53
+
54
+ * Initial version published at https://www.mslinn.com/blog/2020/12/28/custom-logging-in-jekyll-plugins.html
data/README.md CHANGED
@@ -1,78 +1,112 @@
1
- `jekyll_plugin_logger`
2
- [![Gem Version](https://badge.fury.io/rb/jekyll_plugin_logger.svg)](https://badge.fury.io/rb/jekyll_plugin_logger)
3
- ===========
1
+ # `jekyll_plugin_logger` [![Gem Version](https://badge.fury.io/rb/jekyll_plugin_logger.svg)](https://badge.fury.io/rb/jekyll_plugin_logger)
4
2
 
5
3
  `jekyll_plugin_logger` is a Jekyll plugin, packaged as a Ruby gem, that provides colored console logs for Jekyll plugins.
4
+ It is based on the standard Ruby [`Logger`](https://ruby-doc.org/stdlib-3.1.0/libdoc/logger/rdoc/Logger.html) class.
5
+
6
+ Log levels are normally set from `_config.yml`:
7
+
8
+ * 0: `debug`
9
+ * 1: `info`
10
+ * 2: `warn`
11
+ * 3: `error`
12
+ * 4: `fatal`
13
+ * 5: `unknown` (displays as `ANY`)
6
14
 
7
15
 
8
16
  ## Usage
9
17
 
10
- It looks within `_config.yml` for a key corresponding to the plugin progname.
11
- For example, if the plugin's class is called `"MyPlugin"` then an entry called `plugin_loggers.MyPlugin`
12
- will be read from the config file, if present.
13
- If the entry exists, its value overrides the value specified when created.
14
- If no such entry is found then the `log_level` value passed to `new` is used.
18
+ The [`demo/_plugins/`](demo/_plugins/) directory demonstrates two ways of working with `jekyll_plugin_logger`:
15
19
 
16
- Here are examples of how to use this plugin:
17
- ```ruby
18
- # These log messages are always computed, needed or not:
19
- Jekyll.logger.info("Info message 1")
20
- Jekyll.logger.info('MyPlugin', "Info message 2")
20
+ * `liquid_tag.rb`, a Jekyll plugin subclassed from
21
+ [`Liquid::Tag`](https://jekyllrb.com/docs/plugins/tags/).
22
+ * `support_tag.rb`, a Jekyll plugin subclassed from
23
+ [`JekyllSupport::JekyllTag`](https://www.mslinn.com/jekyll_plugins/jekyll_plugin_support.html).
21
24
 
22
- # The following blocks are not evaluated unless log_level requires them to be
23
25
 
24
- Jekyll.logger.info('MyPlugin') { "Info message 3" }
25
- Jekyll.info { "Info message 4" }
26
+ ## Installation
26
27
 
27
- Jekyll.logger.warn('MyPlugin') { "Warn message 1" }
28
- Jekyll.warn { "Warn message 2" }
28
+ ### To A Jekyll Website
29
29
 
30
- Jekyll.logger.error('MyPlugin') { "Error message 1" }
31
- Jekyll.error { "Error message 2" }
32
- ```
30
+ Add the following to your Jekyll website's `Gemfile`:
33
31
 
34
- For more information about the logging feature in the Ruby standard library,
35
- see https://ruby-doc.org/stdlib-2.7.2/libdoc/logger/rdoc/Logger.html
32
+ ```ruby
33
+ group :jekyll_plugins do
34
+ gem 'jekyll_plugin_logger'
35
+ end
36
+ ```
36
37
 
38
+ Install all of the dependent gems of your Jekyll website by typing:
37
39
 
40
+ ```shell
41
+ $ bundle
42
+ ```
38
43
 
39
- ## Installation
44
+ ### To A Jekyll Plugin Packaged As A Gem
40
45
 
41
- Add this line to your Jekyll website's `_config.yml`:
46
+ Add the following to your Gem’s `.gemspec`:
42
47
 
43
48
  ```ruby
44
- group :jekyll_plugins do
45
- gem 'jekyll_plugin_logger'
49
+ Gem::Specification.new do |spec|
50
+ spec.add_dependency 'jekyll_plugin_logger'
46
51
  end
47
52
  ```
48
53
 
49
- Install all of the dependent gems of your Jekyll website by typing:
54
+ Install all of the dependent gems of your Gem by typing:
50
55
 
51
- $ bundle install
56
+ ```shell
57
+ $ bundle
58
+ ```
52
59
 
53
- Or install just this one gem by typing:
54
60
 
55
- $ gem install jekyll_plugin_logger
61
+ ## Configuration
62
+
63
+ The default log level is `info`.
64
+ You can change the log level by editing `_config.yml` and adding a `plugin_loggers` section.
65
+ Within that section, add an entry for the fully qualified name of your plugin class.
66
+
67
+ For example, the fully qualified class names of the Jekyll plugins provided in `demo/_plugins/`
68
+ are `Raw::InlineTag` and `Support::InlineTag`, respectively.
69
+ Their log levels can be set to `debug` with the following entries in [`_config.yml`](demo/_config.yml):
70
+
71
+ ```yaml
72
+ plugin_loggers:
73
+ Raw::InlineTag: debug # Notice the module name is specified as well as the class name
74
+ Support::InlineTag: debug # Notice the module name is specified as well as the class name
75
+ ```
76
+
77
+
78
+ ## Run the Demo
79
+
80
+ Run the demo by typing:
81
+
82
+ ```shell
83
+ $ demo/_bin/debug -r
84
+ ```
85
+
86
+ See what happens to the output when you edit the logging levels in the `plugin_loggers` section of `_config.yml`.
87
+ You will have to restart the demo after each modification to `_config.yml`
88
+ in order to see the output change.
56
89
 
57
90
 
58
91
  ## Additional Information
92
+
59
93
  More information is available on Mike Slinn's web site about
60
- [Jekyll plugins](https://www.mslinn.com/blog/index.html#Jekyll).
94
+ [Jekyll plugins](https://www.mslinn.com/jekyll/10100-custom-logging-in-jekyll-plugins.html).
61
95
 
62
96
 
63
97
  ## Development
64
98
 
65
- After checking out the repo, run `bin/setup` to install dependencies, including development dependencies.
99
+ After checking out the `jekyll_plugin_logger` repository,
100
+ run `bin/setup` to install dependencies,
101
+ which includes development dependencies.
102
+
103
+ You can then run `bin/console` for an interactive prompt that will allow you to experiment.
66
104
 
67
- You can also run `bin/console` for an interactive prompt that will allow you to experiment.
68
105
 
69
106
  ### Build and Install Locally
107
+
70
108
  To build and install this gem onto your local machine, run:
71
- ```shell
72
- $ rake install:local
73
- ```
74
109
 
75
- The following also does the same thing:
76
110
  ```shell
77
111
  $ bundle exec rake install
78
112
  jekyll_plugin_logger 1.0.0 built to pkg/jekyll_plugin_logger-0.1.0.gem.
@@ -80,6 +114,7 @@ jekyll_plugin_logger (1.0.0) installed.
80
114
  ```
81
115
 
82
116
  Examine the newly built gem:
117
+
83
118
  ```shell
84
119
  $ gem info jekyll_plugin_logger
85
120
 
@@ -92,19 +127,24 @@ jekyll_plugin_logger (1.0.0)
92
127
  License: MIT
93
128
  Installed at: /home/mslinn/.gems
94
129
 
95
- Generates Jekyll logger with colored output.
130
+ Generates a Jekyll logger with colored output.
96
131
  ```
97
132
 
133
+
98
134
  ### Build and Push to RubyGems
135
+
99
136
  To release a new version,
100
- 1. Update the version number in `version.rb`.
101
- 2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
102
- 3. Run the following:
103
- ```shell
104
- $ bundle exec rake release
105
- ```
106
- The above creates a git tag for the version, commits the created tag,
107
- and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
137
+
138
+ 1. Update the version number in `version.rb`.
139
+ 2. Commit all changes to git; if you don't the next step might fail with an unexplainable error message.
140
+ 3. Run the following:
141
+
142
+ ```shell
143
+ $ bundle exec rake release
144
+ ```
145
+
146
+ The above creates a git tag for the version, commits the created tag,
147
+ and pushes the new `.gem` file to [RubyGems.org](https://rubygems.org).
108
148
 
109
149
 
110
150
  ## Contributing
data/Rakefile CHANGED
@@ -1,14 +1,12 @@
1
- # frozen_string_literal: true
2
-
3
- require "bump/tasks"
4
- require "bundler/gem_tasks"
5
- require "rspec/core/rake_task"
1
+ require 'bump/tasks'
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
6
4
 
7
5
  # do not always tag the version
8
6
  # Bump.tag_by_default = false
9
7
 
10
8
  # bump the version in additional files
11
- # Bump.replace_in_default = ["Readme.md"]
9
+ # Bump.replace_in_default = ['Readme.md']
12
10
 
13
11
  # Maintain changelog:
14
12
  Bump.changelog = true
@@ -17,7 +15,7 @@ Bump.changelog = true
17
15
  Bump.changelog = :editor
18
16
 
19
17
  # Configure bump to not use a prefix:
20
- ENV["TAG_PREFIX"] = ""
18
+ ENV['TAG_PREFIX'] = ''
21
19
 
22
20
  RSpec::Core::RakeTask.new(:spec)
23
- task :default => :spec
21
+ task default: :spec
@@ -1,45 +1,37 @@
1
- # frozen_string_literal: true
1
+ require_relative 'lib/jekyll_plugin_logger/version'
2
2
 
3
- require_relative "lib/jekyll_plugin_logger/version"
3
+ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
4
+ github = 'https://github.com/mslinn/jekyll_plugin_logger'
4
5
 
5
- # rubocop:disable Metrics/BlockLength
6
- Gem::Specification.new do |spec|
7
- github = "https://github.com/mslinn/jekyll_plugin_logger"
8
-
9
- spec.authors = ["Mike Slinn"]
10
- spec.bindir = "exe"
6
+ spec.authors = ['Mike Slinn']
7
+ spec.bindir = 'exe'
11
8
  spec.description = <<~END_OF_DESC
12
9
  Generates Jekyll logger with colored output.
13
10
  END_OF_DESC
14
- spec.email = ["mslinn@mslinn.com"]
15
- spec.files = Dir[".rubocop.yml", "LICENSE.*", "Rakefile", "{lib,spec}/**/*", "*.gemspec", "*.md"]
16
- spec.homepage = "https://www.mslinn.com/blog/2020/12/28/custom-logging-in-jekyll-plugins.html"
17
- spec.license = "MIT"
11
+ spec.email = ['mslinn@mslinn.com']
12
+ spec.files = Dir['.rubocop.yml', 'LICENSE.*', 'Rakefile', '{lib,spec}/**/*', '*.gemspec', '*.md']
13
+ spec.homepage = 'https://www.mslinn.com/jekyll_plugins/jekyll_plugin_logger.html'
14
+ spec.license = 'MIT'
18
15
  spec.metadata = {
19
- "allowed_push_host" => "https://rubygems.org",
20
- "bug_tracker_uri" => "#{github}/issues",
21
- "changelog_uri" => "#{github}/CHANGELOG.md",
22
- "homepage_uri" => spec.homepage,
23
- "source_code_uri" => github,
16
+ 'allowed_push_host' => 'https://rubygems.org',
17
+ 'bug_tracker_uri' => "#{github}/issues",
18
+ 'changelog_uri' => "#{github}/CHANGELOG.md",
19
+ 'homepage_uri' => spec.homepage,
20
+ 'source_code_uri' => github,
24
21
  }
25
- spec.name = "jekyll_plugin_logger"
22
+ spec.name = 'jekyll_plugin_logger'
23
+ spec.platform = Gem::Platform::RUBY
26
24
  spec.post_install_message = <<~END_MESSAGE
27
25
 
28
26
  Thanks for installing #{spec.name}!
29
27
 
30
28
  END_MESSAGE
31
- spec.require_paths = ["lib"]
32
- spec.required_ruby_version = ">= 2.6.0"
33
- spec.summary = "Generates Jekyll logger with colored output."
34
- spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
35
- spec.version = JekyllPluginLoggerVersion::VERSION
36
-
37
- spec.add_dependency "jekyll", ">= 3.5.0"
29
+ spec.require_paths = ['lib']
30
+ spec.required_ruby_version = '>= 2.6.0'
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
38
34
 
39
- spec.add_development_dependency "debase"
40
- # spec.add_development_dependency "rubocop-jekyll"
41
- # spec.add_development_dependency "rubocop-rake"
42
- # spec.add_development_dependency "rubocop-rspec"
43
- spec.add_development_dependency "ruby-debug-ide"
35
+ spec.add_dependency 'bump'
36
+ spec.add_dependency 'jekyll', '>= 3.5.0'
44
37
  end
45
- # rubocop:enable Metrics/BlockLength
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module JekyllPluginLoggerVersion
4
- VERSION = "2.1.1"
2
+ VERSION = '2.1.3'.freeze
5
3
  end
@@ -1,24 +1,25 @@
1
- # frozen_string_literal: true
2
-
3
- require "colorator"
4
- require "logger"
5
- require "singleton"
6
- require "yaml"
7
- require_relative "jekyll_plugin_logger/version"
1
+ require 'colorator'
2
+ require 'logger'
3
+ require 'yaml'
4
+ require_relative 'jekyll_plugin_logger/version'
5
+ require_relative 'jekyll_plugin_meta_logger'
8
6
 
9
7
  module JekyllPluginLoggerName
10
- PLUGIN_NAME = "jekyll_plugin_logger"
8
+ PLUGIN_NAME = 'jekyll_plugin_logger'.freeze
11
9
  end
12
10
 
13
11
  # Once the meta-logger is made (see `PluginMetaLogger`, below) new instances of `PluginLogger` can be created with log levels set
14
12
  # by `config` entries.
13
+ #
15
14
  # @example Create new `PluginLogger`s like this:
16
- # @logger = PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config)
15
+ # @logger = PluginMetaLogger.instance.new_logger(ref, PluginMetaLogger.instance.config)
17
16
  #
18
- # 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.
19
18
  #
19
+ # Logger usage:
20
20
  # Best practice is to invoke `info`, `warn, `debug` and `error` methods by passing blocks that contain the message.
21
21
  # The blocks will only be evaluated if output for that level is enabled.
22
+ #
22
23
  # @example Use `PluginLogger`s like this:
23
24
  # @logger.info { "This is only evaluated if info level debugging is enabled" }
24
25
  #
@@ -26,29 +27,26 @@ end
26
27
  # @see https://ruby-doc.org/stdlib-2.7.1/libdoc/logger/rdoc/Logger.html
27
28
  class PluginLogger
28
29
  # This method should only be called by PluginMetaLogger
29
- # @param log_level [String, Symbol, Integer] can be specified as $stderr or $stdout,
30
- # or an integer from 0..3 (inclusive),
31
- # or as a case-insensitive string
32
- # (`debug`, `info`, `warn`, `error`, or `DEBUG`, `INFO`, `WARN`, `ERROR`),
33
- # or as a symbol (`:debug`, `:info`, `:warn`, `:error` ).
30
+ # @param stream_name [String, Symbol, Integer] can be specified as $stderr or $stdout
34
31
  #
35
- # @param config [YAML] is normally created by reading a YAML file such as Jekyll's `_config.yml`.
36
- # When invoking from a Jekyll plugin, provide `site.config`,
37
- # 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`.
38
34
  #
39
- # @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:
40
36
  # logger_factory:
41
37
  # abc: debug
42
38
  def initialize(klass, config = nil, stream_name = $stdout)
43
39
  @config = config
44
- @logger = Logger.new(stream_name)
45
- @logger.progname = derive_progname(klass)
46
- @logger.level = :info
47
- plugin_loggers = config ? config["plugin_loggers"] : nil
48
- @logger.level = plugin_loggers[@logger.progname] if plugin_loggers && plugin_loggers[@logger.progname]
40
+ plugin_loggers = config&.[] 'plugin_loggers'
41
+
42
+ @logger = Logger.new stream_name
43
+ @logger.progname = derive_progname klass
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
46
+ @logger.level = plugin_loggers[@logger.progname] if plugin_loggers&.[] @logger.progname
49
47
  # puts "PluginLogger.initialize: @logger.progname=#{@logger.progname} set to #{@logger.level}".red
50
- @logger.formatter = proc { |severity, _, prog_name, msg|
51
- "#{severity} #{prog_name}: #{msg}\n"
48
+ @logger.formatter = proc { |severity, _datetime, progname, msg|
49
+ "#{severity} #{progname}: #{msg}\n"
52
50
  }
53
51
  end
54
52
 
@@ -68,10 +66,22 @@ class PluginLogger
68
66
  end
69
67
  end
70
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)
71
80
  def level=(value)
72
81
  @logger.level = value
73
82
  end
74
83
 
84
+ # @return the log level specified in _config.yml, or :info (1) if not specified
75
85
  def level
76
86
  @logger.level
77
87
  end
@@ -100,11 +110,28 @@ class PluginLogger
100
110
  end
101
111
  end
102
112
 
113
+ def fatal(progname = nil, &block)
114
+ if block
115
+ @logger.fatal(@logger.progname) { (yield block).to_s.red.bold }
116
+ else
117
+ @logger.fatal(@logger.progname) { progname.to_s.red.bold }
118
+ end
119
+ end
120
+
121
+ # @return the log level specified in _config.yml, or :info (1) if not specified
103
122
  # Available colors are: :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, and the modifier :bold
104
123
  def level_as_sym
105
124
  return :unknown if @logger.level.negative? || level > 4
106
125
 
107
- [:debug, :info, :warn, :error, :fatal, :unknown][@logger.level]
126
+ %i[debug info warn error fatal unknown][@logger.level]
127
+ end
128
+
129
+ def unknown(progname = nil, &block)
130
+ if block
131
+ @logger.unknown(@logger.progname) { (yield block).to_s.green }
132
+ else
133
+ @logger.unknown(@logger.progname) { progname.to_s.green }
134
+ end
108
135
  end
109
136
 
110
137
  private
@@ -112,86 +139,21 @@ class PluginLogger
112
139
  def derive_progname(klass)
113
140
  class_name = klass.class.to_s
114
141
  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
142
+ when 'Class', 'Module', 'Symbol', 'String'
143
+ klass.to_s.split('::').last
119
144
  else
120
145
  class_name
121
146
  end
122
147
  end
123
148
  end
124
149
 
125
- # Makes a meta-logger instance (a singleton) with level set by `site.config`.
126
- # Saves `site.config` for later use when creating plugin loggers; these loggers each have their own log levels.
127
- #
128
- # For example, if the plugin's progname has value `MyPlugin` then an entry called `plugin_loggers.MyPlugin`
129
- # will be read from `config`, if present.
130
- # If no such entry is found then the meta-logger log_level is set to `:info`.
131
- # If you want to see messages that indicate the loggers and log levels as they are created,
132
- # set the log level for `PluginMetaLogger` to `debug` in `_config.yml`
133
- #
134
- # @example
135
- # # Create and initialize the meta-logger singleton in a high priority Jekyll `site` `:after_init` hook:
136
- # @meta_logger = PluginMetaLogger.instance.new_logger(site.config, self)
137
- # @meta_logger.info { "Meta-logger has been created" }
138
- #
139
- # # In `config.yml`:
140
- # plugin_loggers:
141
- # PluginMetaLogger: info
142
- # MyPlugin: warn
143
- # MakeArchive: error
144
- # ArchiveDisplayTag: debug
145
- #
146
- # # In a Jekyll plugin:
147
- # @logger = PluginMetaLogger.instance.setup(self)
148
- # @logger.info { "This is a log message from a Jekyll plugin" }
149
- # #
150
- # PluginMetaLogger.instance.info { "MyPlugin vX.Y.Z has been loaded" }
151
- class PluginMetaLogger
152
- include Singleton
153
- attr_reader :config, :logger
154
-
155
- def initialize
156
- super
157
- @config = nil
158
- @logger = new_logger(self)
159
- end
160
-
161
- def info
162
- @logger.info(self) { yield }
163
- end
164
-
165
- def debug
166
- @logger.debug(self) { yield }
167
- end
168
-
169
- def level_as_sym
170
- @logger.level_as_sym
171
- end
172
-
173
- def warn
174
- @logger.warn(self) { yield }
175
- end
176
-
177
- def error
178
- @logger.error(self) { yield }
179
- end
180
-
181
- def new_logger(klass, config = nil, stream_name = $stdout)
182
- @config ||= config
183
- if @config.nil?
184
- puts { "Error: PluginMetaLogger has not been initialized with site.config.".red }
185
- PluginLogger.new(klass, {}, stream_name)
186
- else
187
- PluginLogger.new(klass, @config, stream_name)
188
- end
189
- end
190
- end
191
-
192
- 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|
193
155
  instance = PluginMetaLogger.instance
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}" }
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}" }
197
159
  end
@@ -0,0 +1,76 @@
1
+ require 'colorator'
2
+ require 'logger'
3
+ require 'singleton'
4
+
5
+ # Makes a meta-logger instance (a singleton) with level set by `site.config`.
6
+ # Saves `site.config` for later use when creating plugin loggers; these loggers each have their own log levels.
7
+ #
8
+ # For example, if the plugin's progname has value `MyPlugin` then an entry called `plugin_loggers.MyPlugin`
9
+ # will be read from `config`, if present.
10
+ # If no such entry is found then the meta-logger log_level is set to `:info`.
11
+ # If you want to see messages that indicate the loggers and log levels as they are created,
12
+ # set the log level for `PluginMetaLogger` to `debug` in `_config.yml`
13
+ #
14
+ # @example
15
+ # # Create and initialize the meta-logger singleton in a high priority Jekyll `site` `:after_init` hook:
16
+ # @meta_logger = PluginMetaLogger.instance.new_logger(site.config, self)
17
+ # @meta_logger.info { "Meta-logger has been created" }
18
+ #
19
+ # # In `config.yml`:
20
+ # plugin_loggers:
21
+ # PluginMetaLogger: info
22
+ # MyPlugin: warn
23
+ # MakeArchive: error
24
+ # ArchiveDisplayTag: debug
25
+ #
26
+ # # In a Jekyll plugin:
27
+ # @logger = PluginMetaLogger.instance.setup(self)
28
+ # @logger.info { "This is a log message from a Jekyll plugin" }
29
+ # #
30
+ # PluginMetaLogger.instance.info { "MyPlugin vX.Y.Z has been loaded" }
31
+ class PluginMetaLogger
32
+ include Singleton
33
+ attr_reader :config, :logger
34
+ attr_writer :logger
35
+
36
+ def initialize
37
+ super
38
+ @config = nil
39
+ @logger = new_logger(self)
40
+ end
41
+
42
+ def info(&block)
43
+ # Delegate to @logger which respects the configured level
44
+ @logger.info(self) { yield block }
45
+ end
46
+
47
+ def debug(&block)
48
+ # Delegate to @logger which respects the configured level
49
+ @logger.debug(self) { yield block }
50
+ end
51
+
52
+ def level_as_sym
53
+ @logger.level_as_sym
54
+ end
55
+
56
+ def warn(&block)
57
+ @logger.warn(self) { yield block }
58
+ end
59
+
60
+ def error(&block)
61
+ @logger.error(self) { yield block }
62
+ end
63
+
64
+ # By the time this method is called, `PluginMetaLogger.instance.config` contains the entire contents of `_config.yml`
65
+ def new_logger(klass, config = nil, stream_name = $stdout)
66
+ @config ||= config
67
+ if @config.nil?
68
+ logger = PluginLogger.new(klass, {}, stream_name)
69
+ logger.debug { 'PluginMetaLogger was not initialized from site.config.' }
70
+ else
71
+ logger = PluginLogger.new(klass, @config, stream_name)
72
+ logger.debug { 'PluginMetaLogger was initialized from site.config.' }
73
+ end
74
+ logger
75
+ end
76
+ end
@@ -1,8 +1,6 @@
1
- # frozen_string_literal: true
2
-
3
- require "colorator"
4
- require "jekyll"
5
- require_relative "../lib/jekyll_plugin_logger"
1
+ require 'colorator'
2
+ require 'jekyll'
3
+ require_relative '../lib/jekyll_plugin_logger'
6
4
 
7
5
  # Output should be:
8
6
 
@@ -19,66 +17,67 @@ require_relative "../lib/jekyll_plugin_logger"
19
17
  class MyTestPlugin
20
18
  instance = PluginMetaLogger.instance
21
19
  logger = instance.new_logger(self) # Should generate a warning
22
- PluginMetaLogger.instance.info { "How now, brown cow" }
23
- PluginMetaLogger.instance.debug { "How now, brown cow" }
24
- PluginMetaLogger.instance.warn { "How now, brown cow" }
25
- PluginMetaLogger.instance.error { "How now, brown cow" }
20
+ PluginMetaLogger.instance.info { 'How now, brown cow' }
21
+ PluginMetaLogger.instance.debug { 'How now, brown cow' }
22
+ PluginMetaLogger.instance.warn { 'How now, brown cow' }
23
+ PluginMetaLogger.instance.error { 'How now, brown cow' }
26
24
 
27
25
  logger = PluginMetaLogger.instance.new_logger(self, RSpec.configuration.site_config)
28
- logger.debug { "3 fleas fleeing freedom" }
29
- logger.info { "3 fleas fleeing freedom" }
30
- logger.warn { "3 fleas fleeing freedom" }
31
- logger.error { "3 fleas fleeing freedom" }
26
+ logger.debug { '3 fleas fleeing freedom' }
27
+ logger.info { '3 fleas fleeing freedom' }
28
+ logger.warn { '3 fleas fleeing freedom' }
29
+ logger.error { '3 fleas fleeing freedom' }
32
30
 
33
31
  def self.exercise(logger)
34
32
  puts
35
- # puts "\ncalling_class_name=#{logger.send(:calling_class_name)}"
36
- logger.debug("Debug message 1")
37
- # logger.debug("MyPlugin", "Debug message 2")
38
- # logger.debug("MyPlugin") { "Debug message 3" }
39
- logger.debug { "Debug message 4" }
33
+ # puts '\ncalling_class_name=#{logger.send(:calling_class_name)}'
34
+ logger.debug('Debug message 1')
35
+ # logger.debug('MyPlugin', 'Debug message 2')
36
+ # logger.debug('MyPlugin') { 'Debug message 3' }
37
+ logger.debug { 'Debug message 4' }
40
38
 
41
- logger.info("Info message 1")
42
- # logger.info("MyPlugin", "Info message 2")
43
- # logger.info("MyPlugin") { "Info message 3" }
44
- logger.info { "Info message 4" }
39
+ logger.info('Info message 1')
40
+ # logger.info('MyPlugin', 'Info message 2')
41
+ # logger.info('MyPlugin') { 'Info message 3' }
42
+ logger.info { 'Info message 4' }
45
43
 
46
- logger.warn("Warn message 1")
47
- # logger.warn("MyPlugin", "Warn message 2")
48
- # logger.warn("MyPlugin") { "Warn message 3" }
49
- logger.warn { "Warn message 4" }
44
+ logger.warn('Warn message 1')
45
+ # logger.warn('MyPlugin', 'Warn message 2')
46
+ # logger.warn('MyPlugin') { 'Warn message 3' }
47
+ logger.warn { 'Warn message 4' }
50
48
 
51
- logger.error("Error message 1")
52
- # logger.error("MyPlugin", "Error message 2")
53
- # logger.error("MyPlugin") { "Error message 3" }
54
- logger.error { "Error message 4" }
49
+ logger.error('Error message 1')
50
+ # logger.error('MyPlugin', 'Error message 2')
51
+ # logger.error('MyPlugin') { 'Error message 3' }
52
+ logger.error { 'Error message 4' }
55
53
  end
56
54
 
57
55
  RSpec.describe PluginLogger do
58
- it "outputs at info level" do
56
+ it 'defaults to warn level when no config' do
59
57
  MyTestPlugin.exercise(PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config, $stdout))
60
- 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)
61
60
  end
62
61
 
63
- it "uses config debug" do
62
+ it 'uses config debug' do
64
63
  logger = PluginMetaLogger.instance.new_logger(:MyBlock, PluginMetaLogger.instance.config)
65
64
  expect(logger.level_as_sym).to eq(:debug)
66
65
  MyTestPlugin.exercise(logger)
67
66
  end
68
67
 
69
- it "uses config info" do
68
+ it 'uses config info' do
70
69
  logger = PluginMetaLogger.instance.new_logger(:ArchiveDisplayTag, PluginMetaLogger.instance.config)
71
70
  expect(logger.level_as_sym).to eq(:info)
72
71
  MyTestPlugin.exercise(logger)
73
72
  end
74
73
 
75
- it "uses config warn" do
76
- logger = PluginMetaLogger.instance.new_logger("SiteInspector", PluginMetaLogger.instance.config, $stdout)
74
+ it 'uses config warn' do
75
+ logger = PluginMetaLogger.instance.new_logger('SiteInspector', PluginMetaLogger.instance.config, $stdout)
77
76
  expect(logger.level_as_sym).to eq(:warn)
78
77
  MyTestPlugin.exercise(logger)
79
78
  end
80
79
 
81
- it "uses config error" do
80
+ it 'uses config error' do
82
81
  logger = PluginMetaLogger.instance.new_logger(:PreTagBlock, PluginMetaLogger.instance.config)
83
82
  expect(logger.level_as_sym).to eq(:error)
84
83
  MyTestPlugin.exercise(logger)
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,10 @@
1
- # frozen_string_literal: true
2
-
3
- require "jekyll"
4
- require_relative "../lib/jekyll_plugin_logger"
1
+ require 'jekyll'
2
+ require_relative '../lib/jekyll_plugin_logger'
5
3
 
6
4
  Jekyll.logger.log_level = :info
7
5
 
8
6
  RSpec.configure do |config|
7
+ config.filter_run_when_matching focus: true
9
8
  plugin_config = <<~END_CONFIG
10
9
  plugin_loggers:
11
10
  ArchiveDisplayTag: info
@@ -21,10 +20,8 @@ RSpec.configure do |config|
21
20
  config.add_setting :site_config
22
21
  config.site_config = YAML.safe_load(plugin_config)
23
22
 
24
- config.filter_run :focus
25
- config.order = "random"
26
- config.run_all_when_everything_filtered = true
23
+ config.order = 'random'
27
24
 
28
25
  # See https://relishapp.com/rspec/rspec-core/docs/command-line/only-failures
29
- config.example_status_persistence_file_path = "spec/status_persistence.txt"
26
+ config.example_status_persistence_file_path = 'spec/status_persistence.txt'
30
27
  end
@@ -1,7 +1,7 @@
1
1
  example_id | status | run_time |
2
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 |
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,37 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_plugin_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.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: 2022-04-15 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
- name: jekyll
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 3.5.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 3.5.0
27
- - !ruby/object:Gem::Dependency
28
- name: debase
13
+ name: bump
29
14
  requirement: !ruby/object:Gem::Requirement
30
15
  requirements:
31
16
  - - ">="
32
17
  - !ruby/object:Gem::Version
33
18
  version: '0'
34
- type: :development
19
+ type: :runtime
35
20
  prerelease: false
36
21
  version_requirements: !ruby/object:Gem::Requirement
37
22
  requirements:
@@ -39,22 +24,22 @@ dependencies:
39
24
  - !ruby/object:Gem::Version
40
25
  version: '0'
41
26
  - !ruby/object:Gem::Dependency
42
- name: ruby-debug-ide
27
+ name: jekyll
43
28
  requirement: !ruby/object:Gem::Requirement
44
29
  requirements:
45
30
  - - ">="
46
31
  - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
32
+ version: 3.5.0
33
+ type: :runtime
49
34
  prerelease: false
50
35
  version_requirements: !ruby/object:Gem::Requirement
51
36
  requirements:
52
37
  - - ">="
53
38
  - !ruby/object:Gem::Version
54
- version: '0'
39
+ version: 3.5.0
55
40
  description: 'Generates Jekyll logger with colored output.
56
41
 
57
- '
42
+ '
58
43
  email:
59
44
  - mslinn@mslinn.com
60
45
  executables: []
@@ -69,17 +54,18 @@ files:
69
54
  - jekyll_plugin_logger.gemspec
70
55
  - lib/jekyll_plugin_logger.rb
71
56
  - lib/jekyll_plugin_logger/version.rb
57
+ - lib/jekyll_plugin_meta_logger.rb
72
58
  - spec/jekyll_plugin_logger_spec.rb
73
59
  - spec/spec_helper.rb
74
60
  - spec/status_persistence.txt
75
- homepage: https://www.mslinn.com/blog/2020/12/28/custom-logging-in-jekyll-plugins.html
61
+ homepage: https://www.mslinn.com/jekyll_plugins/jekyll_plugin_logger.html
76
62
  licenses:
77
63
  - MIT
78
64
  metadata:
79
65
  allowed_push_host: https://rubygems.org
80
66
  bug_tracker_uri: https://github.com/mslinn/jekyll_plugin_logger/issues
81
67
  changelog_uri: https://github.com/mslinn/jekyll_plugin_logger/CHANGELOG.md
82
- homepage_uri: https://www.mslinn.com/blog/2020/12/28/custom-logging-in-jekyll-plugins.html
68
+ homepage_uri: https://www.mslinn.com/jekyll_plugins/jekyll_plugin_logger.html
83
69
  source_code_uri: https://github.com/mslinn/jekyll_plugin_logger
84
70
  post_install_message: |2+
85
71
 
@@ -99,11 +85,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
85
  - !ruby/object:Gem::Version
100
86
  version: '0'
101
87
  requirements: []
102
- rubygems_version: 3.1.4
103
- signing_key:
88
+ rubygems_version: 3.7.2
104
89
  specification_version: 4
105
- summary: Generates Jekyll logger with colored output.
90
+ summary: Generates a Jekyll logger with colored output.
106
91
  test_files:
107
92
  - spec/jekyll_plugin_logger_spec.rb
108
93
  - spec/spec_helper.rb
109
94
  - spec/status_persistence.txt
95
+ ...