mr_loga_loga 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +0 -1
- data/.github/workflows/release.yml +79 -0
- data/.tool-versions +1 -0
- data/Gemfile.lock +1 -3
- data/README.md +2 -1
- data/lib/mr_loga_loga/extensions/active_support_logger_patch.rb +94 -0
- data/lib/mr_loga_loga/extensions/lograge_patch.rb +0 -2
- data/lib/mr_loga_loga/formatters/json.rb +1 -1
- data/lib/mr_loga_loga/formatters/key_value.rb +1 -1
- data/lib/mr_loga_loga/instance_methods.rb +2 -2
- data/lib/mr_loga_loga/logger.rb +20 -9
- data/lib/mr_loga_loga/logger_proxy.rb +9 -8
- data/lib/mr_loga_loga/version.rb +1 -1
- data/lib/mr_loga_loga.rb +1 -2
- data/mr_loga_loga.gemspec +1 -2
- metadata +10 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96771984713e671c4d386e6f2736e7f5fd1e929912a8536f735df46f5df80de1
|
4
|
+
data.tar.gz: 636178d39697f664b5093b49758c478a5dc3739bfceadf03d092ebd777c5d861
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cee5fb5dd81654e5f32fdcc061a23de27e93b6f3dd5d514f2e8a0009b71a795014dc7b4077c4129c614ac96b26369e80e217e8dea25c56c9009d765b92204d7a
|
7
|
+
data.tar.gz: d53465a1153ab221eb2b4039dd987dc56ced93a0ece700fd653f7464bc95f5975a69f6e71cc894c3e3b6d03593c2e45b8be21f6a345304ef8286b97d3fd669a1
|
data/.github/workflows/main.yml
CHANGED
@@ -0,0 +1,79 @@
|
|
1
|
+
name: release
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ main ]
|
6
|
+
workflow_dispatch:
|
7
|
+
inputs:
|
8
|
+
version:
|
9
|
+
description: 'The release version'
|
10
|
+
required: true
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
prepare-release:
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
outputs:
|
16
|
+
release_created: ${{ steps.release.outputs.release_created }}
|
17
|
+
version: ${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}.${{ steps.release.outputs.patch }}
|
18
|
+
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v2
|
21
|
+
- name: Generate Release 🗒️
|
22
|
+
uses: GoogleCloudPlatform/release-please-action@v2
|
23
|
+
id: release
|
24
|
+
with:
|
25
|
+
release-type: ruby
|
26
|
+
package-name: mr-loga-loga
|
27
|
+
bump-minor-pre-major: true
|
28
|
+
version-file: 'dummy.rb' # Don't set the version file, we do version increments ourselves on release
|
29
|
+
|
30
|
+
release:
|
31
|
+
needs: prepare-release
|
32
|
+
runs-on: ubuntu-latest
|
33
|
+
if: needs.prepare-release.outputs.release_created || github.event_name == 'workflow_dispatch'
|
34
|
+
|
35
|
+
steps:
|
36
|
+
- uses: actions/checkout@v2
|
37
|
+
|
38
|
+
- name: Set up Ruby
|
39
|
+
uses: ruby/setup-ruby@v1
|
40
|
+
with:
|
41
|
+
bundler-cache: true
|
42
|
+
env:
|
43
|
+
BUNDLE_WITHOUT: 'development'
|
44
|
+
|
45
|
+
- name: Release Version
|
46
|
+
id: release-version
|
47
|
+
run: |
|
48
|
+
if [[ ${{github.event_name}} == 'workflow_dispatch' ]]; then
|
49
|
+
version=${{ github.event.inputs.version }}
|
50
|
+
else
|
51
|
+
version=${{ needs.prepare-release.outputs.version }}
|
52
|
+
fi
|
53
|
+
echo "::set-output name=version::$version"
|
54
|
+
|
55
|
+
- name: Bump Gem Version
|
56
|
+
run: |
|
57
|
+
sed -i "s|\(VERSION = \)'.*'|\1'${{ steps.release-version.outputs.version }}'|" lib/mr_loga_loga/version.rb
|
58
|
+
|
59
|
+
- name: Update Gemfile.lock
|
60
|
+
run: |
|
61
|
+
bundle config unset deployment
|
62
|
+
bundle install --jobs 4
|
63
|
+
|
64
|
+
- name: Publish Gem 💎
|
65
|
+
run: |
|
66
|
+
mkdir -p $HOME/.gem
|
67
|
+
touch $HOME/.gem/credentials
|
68
|
+
chmod 0600 $HOME/.gem/credentials
|
69
|
+
printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}\n" > $HOME/.gem/credentials
|
70
|
+
gem build *.gemspec
|
71
|
+
gem push *.gem
|
72
|
+
env:
|
73
|
+
RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
|
74
|
+
|
75
|
+
- name: Commit Updated Files 📤
|
76
|
+
uses: EndBug/add-and-commit@v7
|
77
|
+
with:
|
78
|
+
add: "['Gemfile.lock', 'package.json', 'package-lock.json']"
|
79
|
+
message: "chore: post-release ${{ steps.release-version.outputs.version }}"
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.0.0
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mr_loga_loga (0.1.
|
4
|
+
mr_loga_loga (0.1.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
ast (2.4.2)
|
10
|
-
byebug (11.1.3)
|
11
10
|
diff-lcs (1.4.4)
|
12
11
|
docile (1.4.0)
|
13
12
|
parallel (1.21.0)
|
@@ -55,7 +54,6 @@ PLATFORMS
|
|
55
54
|
x86_64-linux
|
56
55
|
|
57
56
|
DEPENDENCIES
|
58
|
-
byebug
|
59
57
|
mr_loga_loga!
|
60
58
|
rake (~> 13.0)
|
61
59
|
rspec (~> 3.0)
|
data/README.md
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
[![Gem Version](https://badge.fury.io/rb/mr_loga_loga.svg)](https://badge.fury.io/rb/mr_loga_loga)
|
10
10
|
[![Main](https://github.com/hschne/mr-loga-loga/actions/workflows/main.yml/badge.svg)](https://github.com/hschne/mr-loga-loga/actions/workflows/main.yml)
|
11
11
|
![License](https://img.shields.io/github/license/hschne/mr-loga-loga)
|
12
|
+
</div>
|
12
13
|
|
13
14
|
## What's this?
|
14
15
|
|
@@ -167,7 +168,7 @@ logger.debug("my message user=#{user} more_data=#{data}")
|
|
167
168
|
|
168
169
|
This is fine, as long as you do not need to change your log format. Changing your log formatter will not change the format of your message, nor the formatting of the contextual information you provided.
|
169
170
|
|
170
|
-
MrLogaLoga addresses this by allowing you to attach contextual information to your logs and giving you full control over how both message and context are formatted.
|
171
|
+
MrLogaLoga addresses this by allowing you to attach contextual information to your logs and giving you full control over how both message and context are formatted. There are other gems doing similar things, most notably [Semantic Logger](https://logger.rocketjob.io/). Where Semantic Logger provides lots of functionality related to logging, MrLogaLoga focuses on making it nice to write log messages - and nothing more.
|
171
172
|
|
172
173
|
## Credit
|
173
174
|
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MrLogaLoga
|
4
|
+
module Adapters
|
5
|
+
# This patches ActiveSupport::Logger to allow forwarding keyword arguments
|
6
|
+
module ActiveSupportLoggerPatch
|
7
|
+
class << self
|
8
|
+
def apply
|
9
|
+
return unless defined?(ActiveSupport)
|
10
|
+
|
11
|
+
patch_applies = defined?(ActiveSupport::Logger)
|
12
|
+
unless patch_applies
|
13
|
+
puts 'WARNING: Failed to patch ActiveSupprt::Logger. It looks like '\
|
14
|
+
"MrLogaLoga's patch no longer applies in "\
|
15
|
+
"#{__FILE__}. Please contact MrLogaLoga maintainers."
|
16
|
+
return
|
17
|
+
end
|
18
|
+
|
19
|
+
ActiveSupport::Logger.send(:include, self)
|
20
|
+
end
|
21
|
+
|
22
|
+
# rubocop:disable all
|
23
|
+
def included base
|
24
|
+
base.instance_eval do
|
25
|
+
def broadcast(logger)
|
26
|
+
Module.new do
|
27
|
+
# We need to patch this method as otherwise calling add with keyword arguments results in argument errors.
|
28
|
+
# Rails calls `broadcast` for the logger configured in `Rails.logger`, which means that any invocations of
|
29
|
+
# Rails.logger.add result in running through this method.
|
30
|
+
#
|
31
|
+
# TODO: Remove once patched in Rails
|
32
|
+
define_method(:add) do |*args, **kwargs, &block|
|
33
|
+
logger.add(*args, &block)
|
34
|
+
super(*args, **kwargs, &block)
|
35
|
+
end
|
36
|
+
|
37
|
+
define_method(:<<) do |x|
|
38
|
+
logger << x
|
39
|
+
super(x)
|
40
|
+
end
|
41
|
+
|
42
|
+
define_method(:close) do
|
43
|
+
logger.close
|
44
|
+
super()
|
45
|
+
end
|
46
|
+
|
47
|
+
define_method(:progname=) do |name|
|
48
|
+
logger.progname = name
|
49
|
+
super(name)
|
50
|
+
end
|
51
|
+
|
52
|
+
define_method(:formatter=) do |formatter|
|
53
|
+
logger.formatter = formatter
|
54
|
+
super(formatter)
|
55
|
+
end
|
56
|
+
|
57
|
+
define_method(:level=) do |level|
|
58
|
+
logger.level = level
|
59
|
+
super(level)
|
60
|
+
end
|
61
|
+
|
62
|
+
define_method(:local_level=) do |level|
|
63
|
+
logger.local_level = level if logger.respond_to?(:local_level=)
|
64
|
+
super(level) if respond_to?(:local_level=)
|
65
|
+
end
|
66
|
+
|
67
|
+
define_method(:silence) do |level = Logger::ERROR, &block|
|
68
|
+
if logger.respond_to?(:silence)
|
69
|
+
logger.silence(level) do
|
70
|
+
if defined?(super)
|
71
|
+
super(level, &block)
|
72
|
+
else
|
73
|
+
block.call(self)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
else
|
77
|
+
if defined?(super)
|
78
|
+
super(level, &block)
|
79
|
+
else
|
80
|
+
block.call(self)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
# rubocpo:enable all
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
MrLogaLoga::Adapters::ActiveSupportLoggerPatch.apply
|
@@ -24,7 +24,7 @@ module MrLogaLoga
|
|
24
24
|
# @param context [Hash] The log message context
|
25
25
|
#
|
26
26
|
# @return [String] the formatted log message
|
27
|
-
def call(severity, datetime, progname, message, context)
|
27
|
+
def call(severity, datetime, progname, message, **context)
|
28
28
|
message = message.nil? || message.empty? ? nil : msg2str(message)
|
29
29
|
|
30
30
|
message_hash = {
|
@@ -24,7 +24,7 @@ module MrLogaLoga
|
|
24
24
|
# @param context [Hash] The log message context
|
25
25
|
#
|
26
26
|
# @return [String] the formatted log message
|
27
|
-
def call(severity, datetime, progname, message, context)
|
27
|
+
def call(severity, datetime, progname, message, **context)
|
28
28
|
message = context.map { |key, value| "#{key}=#{value}" }
|
29
29
|
.prepend(message)
|
30
30
|
.compact
|
data/lib/mr_loga_loga/logger.rb
CHANGED
@@ -20,6 +20,11 @@ module MrLogaLoga
|
|
20
20
|
# logger.debug("Default")
|
21
21
|
# logger.context(user: 1).debug('with context')
|
22
22
|
class Logger < ::Logger
|
23
|
+
def initialize(*args, **kwargs)
|
24
|
+
super
|
25
|
+
@default_formatter = MrLogaLoga::Formatters::KeyValue.new
|
26
|
+
end
|
27
|
+
|
23
28
|
def context(**kwargs, &block)
|
24
29
|
context = block ? -> { kwargs.merge(block.call) } : kwargs
|
25
30
|
Context.new(self, context)
|
@@ -30,11 +35,21 @@ module MrLogaLoga
|
|
30
35
|
Message.new(self, message)
|
31
36
|
end
|
32
37
|
|
33
|
-
def add(severity, message = nil, progname = nil, **context, &block)
|
38
|
+
def add(severity, message = nil, progname = nil, *_args, **context, &block)
|
34
39
|
severity ||= UNKNOWN
|
35
40
|
return true unless log?(severity)
|
36
41
|
|
37
|
-
|
42
|
+
progname = @progname if progname.nil?
|
43
|
+
|
44
|
+
if message.nil?
|
45
|
+
if block
|
46
|
+
message = block.call
|
47
|
+
else
|
48
|
+
message = progname
|
49
|
+
progname = @progname
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
38
53
|
@logdev.write(format(format_severity(severity), Time.now, progname, message, context))
|
39
54
|
true
|
40
55
|
end
|
@@ -42,10 +57,10 @@ module MrLogaLoga
|
|
42
57
|
alias log add
|
43
58
|
|
44
59
|
%i[debug info warn error fatal unknown].each do |symbol|
|
45
|
-
define_method(symbol) do |
|
60
|
+
define_method(symbol) do |progname = nil, **context, &block|
|
46
61
|
# Map the symbol (e.g. :debug) to the severity constant (e.g. DEBUG)
|
47
62
|
severity = Object.const_get("Logger::Severity::#{symbol.to_s.upcase}")
|
48
|
-
add(severity,
|
63
|
+
add(severity, nil, progname, **context, &block)
|
49
64
|
end
|
50
65
|
end
|
51
66
|
|
@@ -73,11 +88,7 @@ module MrLogaLoga
|
|
73
88
|
end
|
74
89
|
|
75
90
|
def format(severity, datetime, progname, message, context)
|
76
|
-
formatter.call(severity, datetime, progname, message, context)
|
77
|
-
end
|
78
|
-
|
79
|
-
def formatter
|
80
|
-
@formatter ||= MrLogaLoga::Formatters::KeyValue.new
|
91
|
+
(@formatter || @default_formatter).call(severity, datetime, progname, message, **context)
|
81
92
|
end
|
82
93
|
end
|
83
94
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'logger'
|
4
|
+
require 'forwardable'
|
4
5
|
|
5
6
|
module MrLogaLoga
|
6
7
|
# == Description
|
@@ -9,30 +10,30 @@ module MrLogaLoga
|
|
9
10
|
#
|
10
11
|
# @api private
|
11
12
|
class LoggerProxy
|
13
|
+
extend Forwardable
|
14
|
+
|
12
15
|
def initialize(logger, context_proc)
|
13
16
|
@logger = logger
|
14
17
|
@context_proc = context_proc
|
15
18
|
end
|
16
19
|
|
17
|
-
def add(severity, message = nil, **context, &block)
|
20
|
+
def add(severity, message = nil, progname = nil, **context, &block)
|
18
21
|
severity ||= UNKNOWN
|
19
22
|
return true unless @logger.log?(severity)
|
20
23
|
|
21
24
|
context = @context_proc.call.merge(context)
|
22
25
|
|
23
|
-
@logger.add(severity, message, **context, &block)
|
26
|
+
@logger.add(severity, message, progname, **context, &block)
|
24
27
|
end
|
25
28
|
|
26
29
|
alias log add
|
27
30
|
|
28
31
|
%i[debug info warn error fatal unknown].each do |symbol|
|
29
|
-
|
30
|
-
severity = Object.const_get("Logger::Severity::#{symbol.to_s.upcase}")
|
31
|
-
return true unless @logger.log?(severity)
|
32
|
+
def_delegator :@logger, "#{symbol}?".to_sym, "#{symbol}?".to_sym
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
define_method(symbol) do |progname = nil, **context, &block|
|
35
|
+
severity = Object.const_get("Logger::Severity::#{symbol.to_s.upcase}")
|
36
|
+
add(severity, nil, progname, **context, &block)
|
36
37
|
end
|
37
38
|
end
|
38
39
|
end
|
data/lib/mr_loga_loga/version.rb
CHANGED
data/lib/mr_loga_loga.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'byebug'
|
4
|
-
|
5
3
|
require_relative 'mr_loga_loga/version'
|
6
4
|
require_relative 'mr_loga_loga/configuration'
|
7
5
|
require_relative 'mr_loga_loga/logger_proxy'
|
@@ -11,6 +9,7 @@ require_relative 'mr_loga_loga/logger'
|
|
11
9
|
require_relative 'mr_loga_loga/formatters/key_value'
|
12
10
|
require_relative 'mr_loga_loga/formatters/json'
|
13
11
|
|
12
|
+
require_relative 'mr_loga_loga/extensions/active_support_logger_patch'
|
14
13
|
require_relative 'mr_loga_loga/extensions/lograge_patch'
|
15
14
|
|
16
15
|
# == Description
|
data/mr_loga_loga.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
|
17
17
|
spec.metadata['homepage_uri'] = spec.homepage
|
18
18
|
spec.metadata['source_code_uri'] = spec.homepage
|
19
|
-
spec.metadata['changelog_uri'] = "#{spec.homepage}/CHANGELOG.md"
|
19
|
+
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/CHANGELOG.md"
|
20
20
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
21
21
|
|
22
22
|
# Specify which files should be added to the gem when it is released.
|
@@ -33,7 +33,6 @@ Gem::Specification.new do |spec|
|
|
33
33
|
|
34
34
|
# For more information and examples about making a new gem, checkout our
|
35
35
|
# guide at: https://bundler.io/guides/creating_gem.html
|
36
|
-
spec.add_development_dependency 'byebug'
|
37
36
|
spec.add_development_dependency 'rubocop', '~> 1.24'
|
38
37
|
spec.add_development_dependency 'simplecov', '~> 0.21.2'
|
39
38
|
spec.add_development_dependency 'timecop', '~> 0.9.4'
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mr_loga_loga
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hschne
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: byebug
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: rubocop
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -79,9 +65,11 @@ files:
|
|
79
65
|
- ".github/dependabot.yml"
|
80
66
|
- ".github/stale.yml"
|
81
67
|
- ".github/workflows/main.yml"
|
68
|
+
- ".github/workflows/release.yml"
|
82
69
|
- ".gitignore"
|
83
70
|
- ".rspec"
|
84
71
|
- ".rubocop.yml"
|
72
|
+
- ".tool-versions"
|
85
73
|
- CHANGELOG.md
|
86
74
|
- CODE_OF_CONDUCT.md
|
87
75
|
- Gemfile
|
@@ -94,6 +82,7 @@ files:
|
|
94
82
|
- lib/mr_loga_loga.rb
|
95
83
|
- lib/mr_loga_loga/configuration.rb
|
96
84
|
- lib/mr_loga_loga/context.rb
|
85
|
+
- lib/mr_loga_loga/extensions/active_support_logger_patch.rb
|
97
86
|
- lib/mr_loga_loga/extensions/lograge_patch.rb
|
98
87
|
- lib/mr_loga_loga/formatters/json.rb
|
99
88
|
- lib/mr_loga_loga/formatters/key_value.rb
|
@@ -109,9 +98,9 @@ licenses:
|
|
109
98
|
metadata:
|
110
99
|
homepage_uri: https://github.com/hschne/mr-loga-loga
|
111
100
|
source_code_uri: https://github.com/hschne/mr-loga-loga
|
112
|
-
changelog_uri: https://github.com/hschne/mr-loga-loga/CHANGELOG.md
|
101
|
+
changelog_uri: https://github.com/hschne/mr-loga-loga/blob/main/CHANGELOG.md
|
113
102
|
rubygems_mfa_required: 'true'
|
114
|
-
post_install_message:
|
103
|
+
post_install_message:
|
115
104
|
rdoc_options: []
|
116
105
|
require_paths:
|
117
106
|
- lib
|
@@ -126,8 +115,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
115
|
- !ruby/object:Gem::Version
|
127
116
|
version: '0'
|
128
117
|
requirements: []
|
129
|
-
rubygems_version: 3.2.
|
130
|
-
signing_key:
|
118
|
+
rubygems_version: 3.2.3
|
119
|
+
signing_key:
|
131
120
|
specification_version: 4
|
132
121
|
summary: A bombastic, fantastic logger for Ruby
|
133
122
|
test_files: []
|