jekyll_plugin_logger 2.1.0 → 2.1.2

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: 26418179467ef67c9e606c45bd565fff0fe4f8c450da9efa243d29d99b581821
4
- data.tar.gz: 6f7b529c26a6df0b236acb15c2a6c9314b2679cba64d152c41b3f581ab188a8e
3
+ metadata.gz: 90e90f26bac683d004a6ba9c963d8b6532678dac4cc0e03eee15732742c2f936
4
+ data.tar.gz: c1711187ac79bfd16ae6e357e647488f67c32e4b4526222d932e4c02c76615c4
5
5
  SHA512:
6
- metadata.gz: 61308925aaf08121c323b650a7918c549a33c5eb4a2b0c50985210be2edd11bcadf5d31d4773c9a09c96194822efb95b83767ea10f98864752ec7a36cb5ee118
7
- data.tar.gz: e4f70c43f66bffe16ccb045ed645d6ac0167de28e9146661325d69c155a444f9b717bfd9d9972e43e17217445c11247a58de13325cd1e04ef9f32a07d78bd650
6
+ metadata.gz: 1ae7813c1bdac1068b72633198d3e09518590d55982cdc2ee0a178d6b655e4022419d7f49baa16d5dace49f6a1a4c72bb9ff9118e192aef48db9970c48de8bec
7
+ data.tar.gz: fe1bbdc922dd1a0a3cbf5af36dbdf7e5fd67ca12dc8c14b55361d9b9cbef61aa1983abb616dfda460ef3b626a721353cc61c6e4b5b6286c9804a8b6b83a7aec3
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,22 +1,47 @@
1
+ # Change Log
2
+
3
+ ## 2.1.2 / 2023-11-21
4
+
5
+ * Added `demo`.
6
+ * Added `fatal` and `unknown` log levels.
7
+
8
+
9
+ ## 2.1.1 / 2022-04-15
10
+
11
+ * Fixed `progname` reference for the `PluginMetaLogger` debug startup statement.
12
+
13
+
1
14
  ## 2.1.0 / 2022-04-05
2
- * Changed how config info is made available
15
+
16
+ * Changed how config info is made available.
17
+ * `PluginLogger` is a class once again.
18
+
3
19
 
4
20
  ## 2.0.1 / 2022-04-05
5
- * Changed to registration hook to `:site`, `:after_reset` because that is the first hook that gets called.
6
- * Improved the detection of various types of `progname`
21
+
22
+ * Changed to registration hook to `:site`, `:after_reset` because that is the first hook that gets called.
23
+ * Improved the detection of various types of `progname`.
24
+
7
25
 
8
26
  ## 2.0.0 / 2022-03-16
9
- * Completely rewrote this plugin, now not a class, but a module that monkey patches the existing Jekyll logger for compatibility.
10
- * Renamed the gem from `jekyll_logger_factory` to `jekyll_plugin_logger`.
11
- * Automatically obtains plugin class name and uses that as `progname`.
12
- * `:into` level output is colored cyan.
27
+
28
+ * Completely rewrote this plugin, now not a class,
29
+ but a module that monkey patches the existing Jekyll logger for compatibility.
30
+ * Renamed the gem from `jekyll_logger_factory` to `jekyll_plugin_logger`.
31
+ * Automatically obtains plugin class name and uses that as `progname`.
32
+ * `:into` level output is colored cyan.
33
+
13
34
 
14
35
  ## 1.0.0 / 2022-03-16
15
- * Published as a gem.
16
- * New instances are now created with `new` instead of `create_logger`.
17
- * Now subclasses Jekyll's Stevenson logger.
18
- * Documentation improved, clarifies that the only supported levels are those provided by the Stevenson logger: `:debug`, `:info`, and `:error`.
19
- * No longer supports control over where log output goes; STDERR and STDOUT are automatically selected according to log level.
36
+
37
+ * Published as a gem.
38
+ * New instances are now created with `new` instead of `create_logger`.
39
+ * Now subclasses Jekyll's Stevenson logger.
40
+ * Documentation improved, clarifies that the only supported levels are those provided by the
41
+ Stevenson logger: `:debug`, `:info`, and `:error`.
42
+ * No longer supports control over where log output goes; STDERR and STDOUT are automatically selected according to log level.
43
+
20
44
 
21
45
  ## 2020-12-28
22
- * Initial version published at https://www.mslinn.com/blog/2020/12/28/custom-logging-in-jekyll-plugins.html
46
+
47
+ * 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,36 @@
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'
26
23
  spec.post_install_message = <<~END_MESSAGE
27
24
 
28
25
  Thanks for installing #{spec.name}!
29
26
 
30
27
  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)/!)
28
+ spec.require_paths = ['lib']
29
+ 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)/})
35
32
  spec.version = JekyllPluginLoggerVersion::VERSION
36
33
 
37
- spec.add_dependency "jekyll", ">= 3.5.0"
38
-
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"
34
+ spec.add_dependency 'bump'
35
+ spec.add_dependency 'jekyll', '>= 3.5.0'
44
36
  end
45
- # rubocop:enable Metrics/BlockLength
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module JekyllPluginLoggerVersion
4
- VERSION = "2.1.0"
2
+ VERSION = '2.1.2'.freeze
5
3
  end
@@ -1,13 +1,11 @@
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
@@ -32,6 +30,13 @@ class PluginLogger
32
30
  # (`debug`, `info`, `warn`, `error`, or `DEBUG`, `INFO`, `WARN`, `ERROR`),
33
31
  # or as a symbol (`:debug`, `:info`, `:warn`, `:error` ).
34
32
  #
33
+ # 0: debug
34
+ # 1: info
35
+ # 2: warn
36
+ # 3: error
37
+ # 4: fatal
38
+ # 5: unknown (displays as ANY)
39
+ #
35
40
  # @param config [YAML] is normally created by reading a YAML file such as Jekyll's `_config.yml`.
36
41
  # When invoking from a Jekyll plugin, provide `site.config`,
37
42
  # which is available from all types of Jekyll plugins as `Jekyll.configuration({})`.
@@ -41,14 +46,15 @@ class PluginLogger
41
46
  # abc: debug
42
47
  def initialize(klass, config = nil, stream_name = $stdout)
43
48
  @config = config
44
- @logger = Logger.new(stream_name)
45
- @logger.progname = derive_progname(klass)
49
+ plugin_loggers = config&.[] 'plugin_loggers'
50
+
51
+ @logger = Logger.new stream_name
52
+ @logger.progname = derive_progname klass
46
53
  @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]
54
+ @logger.level = plugin_loggers[@logger.progname] if plugin_loggers&.[] @logger.progname
49
55
  # 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"
56
+ @logger.formatter = proc { |severity, _datetime, progname, msg|
57
+ "#{severity} #{progname}: #{msg}\n"
52
58
  }
53
59
  end
54
60
 
@@ -72,6 +78,7 @@ class PluginLogger
72
78
  @logger.level = value
73
79
  end
74
80
 
81
+ # @return the log level specified in _config.yml, or :info (1) if not specified
75
82
  def level
76
83
  @logger.level
77
84
  end
@@ -100,11 +107,28 @@ class PluginLogger
100
107
  end
101
108
  end
102
109
 
110
+ def fatal(progname = nil, &block)
111
+ if block
112
+ @logger.fatal(@logger.progname) { (yield block).to_s.red.bold }
113
+ else
114
+ @logger.fatal(@logger.progname) { progname.to_s.red.bold }
115
+ end
116
+ end
117
+
118
+ # @return the log level specified in _config.yml, or :info (1) if not specified
103
119
  # Available colors are: :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, and the modifier :bold
104
120
  def level_as_sym
105
121
  return :unknown if @logger.level.negative? || level > 4
106
122
 
107
- [:debug, :info, :warn, :error, :fatal, :unknown][@logger.level]
123
+ %i[debug info warn error fatal unknown][@logger.level]
124
+ end
125
+
126
+ def unknown(progname = nil, &block)
127
+ if block
128
+ @logger.unknown(@logger.progname) { (yield block).to_s.green }
129
+ else
130
+ @logger.unknown(@logger.progname) { progname.to_s.green }
131
+ end
108
132
  end
109
133
 
110
134
  private
@@ -112,86 +136,17 @@ class PluginLogger
112
136
  def derive_progname(klass)
113
137
  class_name = klass.class.to_s
114
138
  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
139
+ when 'Class', 'Module', 'Symbol', 'String'
140
+ klass.to_s.split('::').last
119
141
  else
120
142
  class_name
121
143
  end
122
144
  end
123
145
  end
124
146
 
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|
147
+ Jekyll::Hooks.register(:site, :after_reset, priority: :high) do |site|
193
148
  instance = PluginMetaLogger.instance
194
149
  logger = instance.new_logger(PluginMetaLogger, site.config)
195
150
  logger.info { "Loaded #{JekyllPluginLoggerName::PLUGIN_NAME} v#{JekyllPluginLoggerVersion::VERSION} plugin." }
196
- logger.debug { "Logger for #{instance.progname} created at level #{instance.level_as_sym}" }
151
+ logger.debug { "Logger for #{instance.logger.progname} created at level #{instance.level_as_sym}" }
197
152
  end
@@ -0,0 +1,70 @@
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
+
35
+ def initialize
36
+ super
37
+ @config = nil
38
+ @logger = new_logger(self)
39
+ end
40
+
41
+ def info(&block)
42
+ @logger.info(self) { yield block }
43
+ end
44
+
45
+ def debug(&block)
46
+ @logger.debug(self) { yield block }
47
+ end
48
+
49
+ def level_as_sym
50
+ @logger.level_as_sym
51
+ end
52
+
53
+ def warn(&block)
54
+ @logger.warn(self) { yield block }
55
+ end
56
+
57
+ def error(&block)
58
+ @logger.error(self) { yield block }
59
+ end
60
+
61
+ def new_logger(klass, config = nil, stream_name = $stdout)
62
+ @config ||= config
63
+ if @config.nil?
64
+ puts { 'Error: PluginMetaLogger has not been initialized with site.config.'.red }
65
+ PluginLogger.new(klass, {}, stream_name)
66
+ else
67
+ PluginLogger.new(klass, @config, stream_name)
68
+ end
69
+ end
70
+ 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,66 @@ 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 'outputs at info level' do
59
57
  MyTestPlugin.exercise(PluginMetaLogger.instance.new_logger(self, PluginMetaLogger.instance.config, $stdout))
60
58
  expect(PluginMetaLogger.instance.level_as_sym).to eq(:info)
61
59
  end
62
60
 
63
- it "uses config debug" do
61
+ it 'uses config debug' do
64
62
  logger = PluginMetaLogger.instance.new_logger(:MyBlock, PluginMetaLogger.instance.config)
65
63
  expect(logger.level_as_sym).to eq(:debug)
66
64
  MyTestPlugin.exercise(logger)
67
65
  end
68
66
 
69
- it "uses config info" do
67
+ it 'uses config info' do
70
68
  logger = PluginMetaLogger.instance.new_logger(:ArchiveDisplayTag, PluginMetaLogger.instance.config)
71
69
  expect(logger.level_as_sym).to eq(:info)
72
70
  MyTestPlugin.exercise(logger)
73
71
  end
74
72
 
75
- it "uses config warn" do
76
- logger = PluginMetaLogger.instance.new_logger("SiteInspector", PluginMetaLogger.instance.config, $stdout)
73
+ it 'uses config warn' do
74
+ logger = PluginMetaLogger.instance.new_logger('SiteInspector', PluginMetaLogger.instance.config, $stdout)
77
75
  expect(logger.level_as_sym).to eq(:warn)
78
76
  MyTestPlugin.exercise(logger)
79
77
  end
80
78
 
81
- it "uses config error" do
79
+ it 'uses config error' do
82
80
  logger = PluginMetaLogger.instance.new_logger(:PreTagBlock, PluginMetaLogger.instance.config)
83
81
  expect(logger.level_as_sym).to eq(:error)
84
82
  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
@@ -0,0 +1,7 @@
1
+ example_id | status | run_time |
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 |
metadata CHANGED
@@ -1,37 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_plugin_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-06 00:00:00.000000000 Z
11
+ date: 2023-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !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
14
+ name: bump
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
32
18
  - !ruby/object:Gem::Version
33
19
  version: '0'
34
- type: :development
20
+ type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
@@ -39,22 +25,22 @@ dependencies:
39
25
  - !ruby/object:Gem::Version
40
26
  version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
- name: ruby-debug-ide
28
+ name: jekyll
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
46
32
  - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
33
+ version: 3.5.0
34
+ type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - ">="
53
39
  - !ruby/object:Gem::Version
54
- version: '0'
40
+ version: 3.5.0
55
41
  description: 'Generates Jekyll logger with colored output.
56
42
 
57
- '
43
+ '
58
44
  email:
59
45
  - mslinn@mslinn.com
60
46
  executables: []
@@ -69,16 +55,18 @@ files:
69
55
  - jekyll_plugin_logger.gemspec
70
56
  - lib/jekyll_plugin_logger.rb
71
57
  - lib/jekyll_plugin_logger/version.rb
58
+ - lib/jekyll_plugin_meta_logger.rb
72
59
  - spec/jekyll_plugin_logger_spec.rb
73
60
  - spec/spec_helper.rb
74
- homepage: https://www.mslinn.com/blog/2020/12/28/custom-logging-in-jekyll-plugins.html
61
+ - spec/status_persistence.txt
62
+ homepage: https://www.mslinn.com/jekyll_plugins/jekyll_plugin_logger.html
75
63
  licenses:
76
64
  - MIT
77
65
  metadata:
78
66
  allowed_push_host: https://rubygems.org
79
67
  bug_tracker_uri: https://github.com/mslinn/jekyll_plugin_logger/issues
80
68
  changelog_uri: https://github.com/mslinn/jekyll_plugin_logger/CHANGELOG.md
81
- homepage_uri: https://www.mslinn.com/blog/2020/12/28/custom-logging-in-jekyll-plugins.html
69
+ homepage_uri: https://www.mslinn.com/jekyll_plugins/jekyll_plugin_logger.html
82
70
  source_code_uri: https://github.com/mslinn/jekyll_plugin_logger
83
71
  post_install_message: |2+
84
72
 
@@ -98,10 +86,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
86
  - !ruby/object:Gem::Version
99
87
  version: '0'
100
88
  requirements: []
101
- rubygems_version: 3.1.4
102
- signing_key:
89
+ rubygems_version: 3.3.7
90
+ signing_key:
103
91
  specification_version: 4
104
- summary: Generates Jekyll logger with colored output.
92
+ summary: Generates a Jekyll logger with colored output.
105
93
  test_files:
106
94
  - spec/jekyll_plugin_logger_spec.rb
107
95
  - spec/spec_helper.rb
96
+ - spec/status_persistence.txt
97
+ ...