jekyll_plugin_logger 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +21 -0
- data/CHANGELOG.md +15 -0
- data/LICENSE.txt +21 -0
- data/README.md +120 -0
- data/Rakefile +7 -0
- data/jekyll_plugin_logger.gemspec +45 -0
- data/lib/jekyll_plugin_logger/version.rb +5 -0
- data/lib/jekyll_plugin_logger.rb +197 -0
- data/spec/jekyll_plugin_logger.rb +81 -0
- data/spec/spec_helper.rb +12 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a7a503b502ebd28c7bfe8ed9237ae721560135f1620054da34ece8275cfb5118
|
4
|
+
data.tar.gz: 5285da27eebe3005f00562260e38117a8d685a8f10b8ab5bf444ee804d17cf46
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ebc0a877d7bf80fe01e1609123ea93900ce9a23e96c877e3d304128543946c1fe31613c3af9b50324fa5fdf030170a06f5f2b79ba02d3fd079f7797931639088
|
7
|
+
data.tar.gz: 516fb3f7250fce0bacf7f5a2e782111e358ab0e979cd98950a7105faa0516d657423e88499dfd9534c05c9c70dec00431475a8c1f72be1b166b2164cc0018c56
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require: rubocop-jekyll
|
2
|
+
inherit_gem:
|
3
|
+
rubocop-jekyll: .rubocop.yml
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
Exclude:
|
7
|
+
- vendor/**/*
|
8
|
+
- Gemfile*
|
9
|
+
- '*.gemspec' # This does nothing. Why?
|
10
|
+
NewCops: enable
|
11
|
+
TargetRubyVersion: 2.6
|
12
|
+
|
13
|
+
Jekyll/NoPutsAllowed:
|
14
|
+
Exclude:
|
15
|
+
- spec/**/*
|
16
|
+
|
17
|
+
Layout/LineLength:
|
18
|
+
Max: 150
|
19
|
+
|
20
|
+
# Gemspec/RequireMFA:
|
21
|
+
# enable: false
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
## 2.0.0 / 2022-03-16
|
2
|
+
* Completely rewrote this plugin, now not a class, but a module that monkey patches the existing Jekyll logger for compatibility.
|
3
|
+
* Renamed the gem from `jekyll_logger_factory` to `jekyll_plugin_logger`.
|
4
|
+
* Automatically obtains plugin class name and uses that as `progname`.
|
5
|
+
* `:into` level output is colored cyan.
|
6
|
+
|
7
|
+
## 1.0.0 / 2022-03-16
|
8
|
+
* Published as a gem.
|
9
|
+
* New instances are now created with `new` instead of `create_logger`.
|
10
|
+
* Now subclasses Jekyll's Stevenson logger.
|
11
|
+
* Documentation improved, clarifies that the only supported levels are those provided by the Stevenson logger: `:debug`, `:info`, and `:error`.
|
12
|
+
* No longer supports control over where log output goes; STDERR and STDOUT are automatically selected according to log level.
|
13
|
+
|
14
|
+
## 2020-12-28
|
15
|
+
* Initial version published at https://www.mslinn.com/blog/2020/12/28/custom-logging-in-jekyll-plugins.html
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Mike Slinn
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,120 @@
|
|
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
|
+
===========
|
4
|
+
|
5
|
+
`jekyll_plugin_logger` is a Jekyll plugin, packaged as a Ruby gem, that provides colored console logs for Jekyll plugins.
|
6
|
+
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
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.
|
15
|
+
|
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")
|
21
|
+
|
22
|
+
# The following blocks are not evaluated unless log_level requires them to be
|
23
|
+
|
24
|
+
Jekyll.logger.info('MyPlugin') { "Info message 3" }
|
25
|
+
Jekyll.info { "Info message 4" }
|
26
|
+
|
27
|
+
Jekyll.logger.warn('MyPlugin') { "Warn message 1" }
|
28
|
+
Jekyll.warn { "Warn message 2" }
|
29
|
+
|
30
|
+
Jekyll.logger.error('MyPlugin') { "Error message 1" }
|
31
|
+
Jekyll.error { "Error message 2" }
|
32
|
+
```
|
33
|
+
|
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
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
## Installation
|
40
|
+
|
41
|
+
Add this line to your Jekyll website's `_config.yml`:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
group :jekyll_plugins do
|
45
|
+
gem 'jekyll_plugin_logger'
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
Install all of the dependent gems of your Jekyll website by typing:
|
50
|
+
|
51
|
+
$ bundle install
|
52
|
+
|
53
|
+
Or install just this one gem by typing:
|
54
|
+
|
55
|
+
$ gem install jekyll_plugin_logger
|
56
|
+
|
57
|
+
|
58
|
+
## Additional Information
|
59
|
+
More information is available on Mike Slinn's web site about
|
60
|
+
[Jekyll plugins](https://www.mslinn.com/blog/index.html#Jekyll).
|
61
|
+
|
62
|
+
|
63
|
+
## Development
|
64
|
+
|
65
|
+
After checking out the repo, run `bin/setup` to install dependencies, including development dependencies.
|
66
|
+
|
67
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
68
|
+
|
69
|
+
### Build and Install Locally
|
70
|
+
To build and install this gem onto your local machine, run:
|
71
|
+
```shell
|
72
|
+
$ rake install:local
|
73
|
+
```
|
74
|
+
|
75
|
+
The following also does the same thing:
|
76
|
+
```shell
|
77
|
+
$ bundle exec rake install
|
78
|
+
jekyll_plugin_logger 1.0.0 built to pkg/jekyll_plugin_logger-0.1.0.gem.
|
79
|
+
jekyll_plugin_logger (1.0.0) installed.
|
80
|
+
```
|
81
|
+
|
82
|
+
Examine the newly built gem:
|
83
|
+
```shell
|
84
|
+
$ gem info jekyll_plugin_logger
|
85
|
+
|
86
|
+
*** LOCAL GEMS ***
|
87
|
+
|
88
|
+
jekyll_plugin_logger (1.0.0)
|
89
|
+
Author: Mike Slinn
|
90
|
+
Homepage:
|
91
|
+
https://github.com/mslinn/jekyll_plugin_logger
|
92
|
+
License: MIT
|
93
|
+
Installed at: /home/mslinn/.gems
|
94
|
+
|
95
|
+
Generates Jekyll logger with colored output.
|
96
|
+
```
|
97
|
+
|
98
|
+
### Build and Push to RubyGems
|
99
|
+
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).
|
108
|
+
|
109
|
+
|
110
|
+
## Contributing
|
111
|
+
|
112
|
+
1. Fork the project
|
113
|
+
2. Create a descriptively named feature branch
|
114
|
+
3. Add your feature
|
115
|
+
4. Submit a pull request
|
116
|
+
|
117
|
+
|
118
|
+
## License
|
119
|
+
|
120
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/jekyll_plugin_logger/version"
|
4
|
+
|
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"
|
11
|
+
spec.description = <<~END_OF_DESC
|
12
|
+
Generates Jekyll logger with colored output.
|
13
|
+
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"
|
18
|
+
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,
|
24
|
+
}
|
25
|
+
spec.name = "jekyll_plugin_logger"
|
26
|
+
spec.post_install_message = <<~END_MESSAGE
|
27
|
+
|
28
|
+
Thanks for installing #{spec.name}!
|
29
|
+
|
30
|
+
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 = JekyllPluginLogger::VERSION
|
36
|
+
|
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"
|
44
|
+
end
|
45
|
+
# rubocop:enable Metrics/BlockLength
|
@@ -0,0 +1,197 @@
|
|
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"
|
8
|
+
|
9
|
+
module JekyllPluginLoggerName
|
10
|
+
PLUGIN_NAME = "jekyll_plugin_logger"
|
11
|
+
end
|
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.
|
14
|
+
# @example Create new `PluginLogger`s like this:
|
15
|
+
# @logger = PluginMetaLogger.instance.new_logger(self)
|
16
|
+
#
|
17
|
+
# self can be a class, a string, or a symbol.
|
18
|
+
#
|
19
|
+
# Best practice is to invoke `info``, `warn, `debug`` and `error`` methods by passing blocks that contain the message.
|
20
|
+
# The blocks will only be evaluated if output for that level is enabled.
|
21
|
+
# @example Use `PluginLogger`s like this:
|
22
|
+
# @logger.info { "This is only evaluated if info level debugging is enabled" }
|
23
|
+
#
|
24
|
+
# For more information about the logging feature in the Ruby standard library,
|
25
|
+
# @see https://ruby-doc.org/stdlib-2.7.1/libdoc/logger/rdoc/Logger.html
|
26
|
+
class PluginLogger
|
27
|
+
include JekyllPluginLogger
|
28
|
+
|
29
|
+
# This method should only be called by PluginMetaLogger
|
30
|
+
# @param log_level [String, Symbol, Integer] can be specified as $stderr or $stdout,
|
31
|
+
# or an integer from 0..3 (inclusive),
|
32
|
+
# or as a case-insensitive string
|
33
|
+
# (`debug`, `info`, `warn`, `error`, or `DEBUG`, `INFO`, `WARN`, `ERROR`),
|
34
|
+
# or as a symbol (`:debug`, `:info`, `:warn`, `:error` ).
|
35
|
+
#
|
36
|
+
# @param config [YAML] is normally created by reading a YAML file such as Jekyll's `_config.yml`.
|
37
|
+
# When invoking from a Jekyll plugin, provide `site.config`,
|
38
|
+
# which is available from all types of Jekyll plugins as `Jekyll.configuration({})`.
|
39
|
+
#
|
40
|
+
# @example If `progname` has value `abc`, then the YAML to override the programmatically set log_level to `debug` is:
|
41
|
+
# logger_factory:
|
42
|
+
# abc: debug
|
43
|
+
def initialize(klass, config, stream_name = $stdout)
|
44
|
+
@logger = Logger.new(stream_name)
|
45
|
+
@logger.progname = derive_progname(klass)
|
46
|
+
@logger.level = :info
|
47
|
+
plugin_loggers = config["plugin_loggers"]
|
48
|
+
@logger.level ||= plugin_loggers["PluginMetaLogger"] if plugin_loggers
|
49
|
+
# 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"
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def debug(progname = nil, &block)
|
56
|
+
if block
|
57
|
+
@logger.debug(@logger.progname) { (yield block).to_s.magenta }
|
58
|
+
else
|
59
|
+
@logger.debug(@logger.progname) { progname.to_s.magenta }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def info(progname = nil, &block)
|
64
|
+
if block
|
65
|
+
@logger.info(@logger.progname) { (yield block).to_s.cyan }
|
66
|
+
else
|
67
|
+
@logger.info(@logger.progname) { progname.to_s.cyan }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def level=(value)
|
72
|
+
@logger.level = value
|
73
|
+
end
|
74
|
+
|
75
|
+
def level
|
76
|
+
@logger.level
|
77
|
+
end
|
78
|
+
|
79
|
+
def progname=(value)
|
80
|
+
@logger.progname = value
|
81
|
+
end
|
82
|
+
|
83
|
+
def progname
|
84
|
+
@logger.progname
|
85
|
+
end
|
86
|
+
|
87
|
+
def warn(progname = nil, &block)
|
88
|
+
if block
|
89
|
+
@logger.warn(@logger.progname) { (yield block).to_s.yellow }
|
90
|
+
else
|
91
|
+
@logger.warn(@logger.progname) { progname.to_s.yellow }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def error(progname = nil, &block)
|
96
|
+
if block
|
97
|
+
@logger.error(@logger.progname) { (yield block).to_s.red }
|
98
|
+
else
|
99
|
+
@logger.error(@logger.progname) { progname.to_s.red }
|
100
|
+
end
|
101
|
+
end
|
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
|
+
# Available colors are: :black, :red, :green, :yellow, :blue, :magenta, :cyan, :white, and the modifier :bold
|
118
|
+
def level_as_sym
|
119
|
+
return :unknown if @logger.level.negative? || level > 4
|
120
|
+
|
121
|
+
[:debug, :info, :warn, :error, :fatal, :unknown][@logger.level]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
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
|
+
# PluginMetaLogger.instance.setup(site.config).info { "Meta-logger has been created" }
|
137
|
+
#
|
138
|
+
# # In `config.yml`:
|
139
|
+
# plugin_loggers:
|
140
|
+
# PluginMetaLogger: info
|
141
|
+
# MyPlugin: warn
|
142
|
+
# MakeArchive: error
|
143
|
+
# ArchiveDisplayTag: debug
|
144
|
+
#
|
145
|
+
# # In a Jekyll plugin:
|
146
|
+
# @logger = PluginMetaLogger.instance.new_logger(self)
|
147
|
+
# @logger.info { "This is a log message from a Jekyll plugin" }
|
148
|
+
# #
|
149
|
+
# PluginMetaLogger.instance.info { "MyPlugin vX.Y.Z has been loaded" }
|
150
|
+
class PluginMetaLogger
|
151
|
+
include Singleton
|
152
|
+
attr_reader :logger
|
153
|
+
|
154
|
+
def initialize
|
155
|
+
super
|
156
|
+
@config = nil
|
157
|
+
@logger = new_logger(self)
|
158
|
+
end
|
159
|
+
|
160
|
+
def info
|
161
|
+
@logger.info(self) { yield }
|
162
|
+
end
|
163
|
+
|
164
|
+
def debug
|
165
|
+
@logger.debug(self) { yield }
|
166
|
+
end
|
167
|
+
|
168
|
+
def warn
|
169
|
+
@logger.warn(self) { yield }
|
170
|
+
end
|
171
|
+
|
172
|
+
def error
|
173
|
+
@logger.error(self) { yield }
|
174
|
+
end
|
175
|
+
|
176
|
+
def new_logger(klass, stream_name = $stdout)
|
177
|
+
if @config.nil?
|
178
|
+
puts { "Error: PluginMetaLogger has not been initialized by calling setup yet.".red }
|
179
|
+
PluginLogger.new(klass, {}, stream_name)
|
180
|
+
else
|
181
|
+
PluginLogger.new(klass, @config, stream_name)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def setup(config, stream_name = $stdout)
|
186
|
+
@config = config
|
187
|
+
@logger = new_logger(self, stream_name)
|
188
|
+
@logger
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
Jekyll::Hooks.register(:site, :after_init, :priority => :high) do |site|
|
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}" }
|
197
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "colorator"
|
4
|
+
require "jekyll"
|
5
|
+
require_relative "../lib/jekyll_plugin_logger"
|
6
|
+
|
7
|
+
# Output should be:
|
8
|
+
|
9
|
+
# Info message 1 (cyan)
|
10
|
+
# MyPlugin Info message 2 (cyan)
|
11
|
+
# MyPlugin: Info message 3 (cyan)
|
12
|
+
# MyTestPlugin: Info message 4 (cyan)
|
13
|
+
# .
|
14
|
+
# MyPlugin: Warn message 1 (yellow)
|
15
|
+
# MyTestPlugin: Warn message 2 (yellow)
|
16
|
+
# MyPlugin: Error message 1 (red)
|
17
|
+
# MyTestPlugin: Error message 2 (red)
|
18
|
+
|
19
|
+
class MyTestPlugin
|
20
|
+
instance = PluginMetaLogger.instance
|
21
|
+
logger = instance.new_logger(self) # Should generate a warning
|
22
|
+
instance.setup({})
|
23
|
+
PluginMetaLogger.instance.info { "How now, brown cow" }
|
24
|
+
PluginMetaLogger.instance.debug { "How now, brown cow" }
|
25
|
+
PluginMetaLogger.instance.warn { "How now, brown cow" }
|
26
|
+
PluginMetaLogger.instance.error { "How now, brown cow" }
|
27
|
+
|
28
|
+
logger = PluginMetaLogger.instance.new_logger(self)
|
29
|
+
logger.debug { "3 fleas fleeing freedom" }
|
30
|
+
logger.info { "3 fleas fleeing freedom" }
|
31
|
+
logger.warn { "3 fleas fleeing freedom" }
|
32
|
+
logger.error { "3 fleas fleeing freedom" }
|
33
|
+
|
34
|
+
_yaml = <<~END_YAML
|
35
|
+
plugin_loggers:
|
36
|
+
PluginMetaLogger: debug
|
37
|
+
SiteInspector: warn
|
38
|
+
MakeArchive: error
|
39
|
+
ArchiveDisplayTag: debug
|
40
|
+
END_YAML
|
41
|
+
|
42
|
+
def self.exercise(logger)
|
43
|
+
puts
|
44
|
+
# puts "\ncalling_class_name=#{logger.send(:calling_class_name)}"
|
45
|
+
logger.debug("Debug message 1")
|
46
|
+
# logger.debug("MyPlugin", "Debug message 2")
|
47
|
+
# logger.debug("MyPlugin") { "Debug message 3" }
|
48
|
+
logger.debug { "Debug message 4" }
|
49
|
+
|
50
|
+
logger.info("Info message 1")
|
51
|
+
# logger.info("MyPlugin", "Info message 2")
|
52
|
+
# logger.info("MyPlugin") { "Info message 3" }
|
53
|
+
logger.info { "Info message 4" }
|
54
|
+
|
55
|
+
logger.warn("Warn message 1")
|
56
|
+
# logger.warn("MyPlugin", "Warn message 2")
|
57
|
+
# logger.warn("MyPlugin") { "Warn message 3" }
|
58
|
+
logger.warn { "Warn message 4" }
|
59
|
+
|
60
|
+
logger.error("Error message 1")
|
61
|
+
# logger.error("MyPlugin", "Error message 2")
|
62
|
+
# logger.error("MyPlugin") { "Error message 3" }
|
63
|
+
logger.error { "Error message 4" }
|
64
|
+
end
|
65
|
+
|
66
|
+
RSpec.describe JekyllPluginLogger do
|
67
|
+
it "outputs at debug level" do
|
68
|
+
MyTestPlugin.exercise(PluginMetaLogger.instance.new_logger(self, $stdout))
|
69
|
+
end
|
70
|
+
|
71
|
+
it "uses config warn" do
|
72
|
+
logger = PluginMetaLogger.instance.new_logger("SiteInspector", $stdout)
|
73
|
+
MyTestPlugin.exercise(logger)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "uses config error" do
|
77
|
+
logger = PluginMetaLogger.instance.new_logger(:MakeArchive)
|
78
|
+
MyTestPlugin.exercise(logger)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "jekyll"
|
4
|
+
require_relative "../lib/jekyll_plugin_logger"
|
5
|
+
|
6
|
+
Jekyll.logger.log_level = :info
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
config.order = "random"
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll_plugin_logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Slinn
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-03-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
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
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ruby-debug-ide
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: 'Generates Jekyll logger with colored output.
|
56
|
+
|
57
|
+
'
|
58
|
+
email:
|
59
|
+
- mslinn@mslinn.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".rubocop.yml"
|
65
|
+
- CHANGELOG.md
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- jekyll_plugin_logger.gemspec
|
70
|
+
- lib/jekyll_plugin_logger.rb
|
71
|
+
- lib/jekyll_plugin_logger/version.rb
|
72
|
+
- spec/jekyll_plugin_logger.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
homepage: https://www.mslinn.com/blog/2020/12/28/custom-logging-in-jekyll-plugins.html
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata:
|
78
|
+
allowed_push_host: https://rubygems.org
|
79
|
+
bug_tracker_uri: https://github.com/mslinn/jekyll_plugin_logger/issues
|
80
|
+
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
|
82
|
+
source_code_uri: https://github.com/mslinn/jekyll_plugin_logger
|
83
|
+
post_install_message: |2+
|
84
|
+
|
85
|
+
Thanks for installing jekyll_plugin_logger!
|
86
|
+
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 2.6.0
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubygems_version: 3.1.4
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Generates Jekyll logger with colored output.
|
105
|
+
test_files:
|
106
|
+
- spec/jekyll_plugin_logger.rb
|
107
|
+
- spec/spec_helper.rb
|