luna_park 0.11.6 → 0.11.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/luna_park/notifiers/log/formatters.rb +70 -0
- data/lib/luna_park/notifiers/log.rb +26 -59
- data/lib/luna_park/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17f27391a9cf68f27141e6cf1c408abf3d62e68914252311fb2ee9542ec14704
|
4
|
+
data.tar.gz: c434508390a2ae07e71ad5578c5e82f251051b7e2008c8d0383609de5c399dca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d806ea403698a4cbcbae094abd3257418e2920d9ba1cb793ef92d250380594c89e71f6e24d0e583b2ef87074bd0e8b7a15c06c8252da8d379726ab1a1aee9dc
|
7
|
+
data.tar.gz: d777a213dfd32208477d1af5291a357c3639df8e3d6dd1d4c586d4b19d2c3221cdaab045928245ef7a97308141b8bbede2d7cf55a49f85dca0fcae4b908cebf5
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [0.11.7] - 2022-10-07
|
8
|
+
Changed
|
9
|
+
- Added `formatter` to `Notifiers::Log`. Using `format` in initializer is now deprecated.
|
10
|
+
|
7
11
|
## [0.11.6] - 2021-10-06
|
8
12
|
Changed
|
9
13
|
- in `UseCases::Scenario` now abstract method is `#perform` - not `call!`. It is backward-compatible change: `call!` still works as abstract, and public interface was not changed.
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
3
|
+
require 'pp'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module LunaPark
|
7
|
+
module Notifiers
|
8
|
+
class Log
|
9
|
+
module Formatters
|
10
|
+
# Fomatter - callable object to format log messages. Out of the box there are four types:
|
11
|
+
|
12
|
+
# - SINGLE - output is a single line string message.
|
13
|
+
# notifier = LunaPark::Notifiers::Log.new(formatter: LunaPark::Notifiers::Log::Formatters::SINGLE)
|
14
|
+
# notifier.info('You hear', dog: 'wow', cats: {chloe: 'mow', timmy: 'mow'})
|
15
|
+
#
|
16
|
+
# # I, [2022-09-29T10:51:15.753646 #28763] INFO -- : String - You hear {:dog=>"wow", :cats=>{:chloe=>"mow", :timmy=>"mow"}}
|
17
|
+
#
|
18
|
+
SINGLE = lambda do |klass, message, details = {}|
|
19
|
+
details.empty? ? "#<#{klass}> #{message}" : "#<#{klass}> #{message} #{details}"
|
20
|
+
end
|
21
|
+
|
22
|
+
# - MULTILINE - this format may become more preferred for development mode.
|
23
|
+
# notifier = LunaPark::Notifiers::Log.new(formatter: LunaPark::Notifiers::Log::Formatters::MULTILINE)
|
24
|
+
# notifier.info('You hear', dog: 'wow', cat: {timmy:'purr'}, cow: 'moo', duck: 'quack', horse: 'yell' )
|
25
|
+
#
|
26
|
+
# # I, [2022-09-29T10:56:21.463211 #28763] INFO -- : {:class=>String,
|
27
|
+
# # :message=>"You hear",
|
28
|
+
# # :details=>
|
29
|
+
# # {:dog=>"wow",
|
30
|
+
# # :cat=>{:timmy=>"purr"},
|
31
|
+
# # :cow=>"moo",
|
32
|
+
# # :duck=>"quack",
|
33
|
+
# # :horse=>"yell"}}
|
34
|
+
MULTILINE = lambda do |klass, message, details = {}|
|
35
|
+
PP.pp({ class: klass, message: message, details: details }, '')
|
36
|
+
end
|
37
|
+
|
38
|
+
# - JSON - this format should be good choose for logger which be processed by external logger system
|
39
|
+
# notifier = LunaPark::Notifiers::Log.new(formatter: LunaPark::Notifiers::Log::Formatters::JSON)
|
40
|
+
# notifier.info('You hear', dog: 'wow', cats: {chloe: 'mow', timmy: 'mow'})
|
41
|
+
#
|
42
|
+
# # I, [2022-09-29T12:00:47.600052 #90508] INFO -- : {"class":"String", "message":"You hear",
|
43
|
+
# # "details":{"dog":"wow","cats":{"chloe":"mow","timmy":"mow"}}}
|
44
|
+
JSON = lambda do |klass, message, details = {}|
|
45
|
+
::JSON.generate(class: klass, message: message, details: details)
|
46
|
+
end
|
47
|
+
|
48
|
+
# - PRETTY_JSON - pretty json output
|
49
|
+
# notifier = LunaPark::Notifiers::Log.new(formatter: LunaPark::Notifiers::Log::Formatters::PRETTY_JSON)
|
50
|
+
# notifier.info('You hear', dog: 'wow', cat: {timmy:'purr'}, cow: 'moo', duck: 'quack', horse: 'yell')
|
51
|
+
#
|
52
|
+
# # I, [2022-09-29T12:02:25.236301 #90508] INFO -- : {
|
53
|
+
# # "class": "String",
|
54
|
+
# # "message": "You hear",
|
55
|
+
# # "details": {
|
56
|
+
# # "dog": "wow",
|
57
|
+
# # "cat": {
|
58
|
+
# # "timmy": "purr"
|
59
|
+
# # },
|
60
|
+
# # "cow": "moo",
|
61
|
+
# # "duck": "quack",
|
62
|
+
# # "horse": "yell"
|
63
|
+
# # }
|
64
|
+
PRETTY_JSON = lambda do |klass, message, details = {}|
|
65
|
+
::JSON.pretty_generate(class: klass, message: message, details: details)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -1,9 +1,8 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
require 'json'
|
4
|
-
require 'pp'
|
5
3
|
require 'logger'
|
6
4
|
require 'luna_park/extensions/severity_levels'
|
5
|
+
require 'luna_park/notifiers/log/formatters'
|
7
6
|
require 'luna_park/errors'
|
8
7
|
|
9
8
|
module LunaPark
|
@@ -30,52 +29,14 @@ module LunaPark
|
|
30
29
|
class Log
|
31
30
|
include Extensions::SeverityLevels
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
# Format of log output. Define output format of log message. It can be four types.
|
36
|
-
#
|
37
|
-
# - :single or :string - Then you will get single line string message. This is default
|
38
|
-
# format for the logger.
|
39
|
-
# notifier = LunaPark::Notifiers::Log.new(format: :single)
|
40
|
-
# notifier.message('You hear', dog: 'wow', cats: {chloe: 'mow', timmy: 'mow'})
|
41
|
-
#
|
42
|
-
# # E, [2020-06-13T14:50:22 #20538] ERROR -- : You hear {:dog=>"wow", :cats=>{:chloe=>"mow", :timmy=>"mow"}}
|
43
|
-
#
|
44
|
-
# - :multiline - this format may become more preferred for development mode.
|
45
|
-
# notifier = LunaPark::Notifiers::Log.new(format: :multiline)
|
46
|
-
# notifier.message('You hear', dog: 'wow', cat: {timmy:'purr'}, cow: 'moo', duck: 'quack', horse: 'yell' )
|
47
|
-
#
|
48
|
-
# # E, [2020-06-13T18:24:37.592652 #22786] ERROR -- : {:message=>"You hear",
|
49
|
-
# # :details=>
|
50
|
-
# # {:dog=>"wow",
|
51
|
-
# # :cat=>{:timmy=>"purr"},
|
52
|
-
# # :cow=>"moo",
|
53
|
-
# # :duck=>"quack",
|
54
|
-
# # :horse=>"yell"}}
|
32
|
+
# Callable object to format log messages.
|
55
33
|
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
34
|
+
# pretty_formatter = ->(klass, message, details) { "#{klass} - #{message} - #{details}" }
|
35
|
+
# notifier = LunaPark::Notifiers::Log.new(formatter: pretty_formatter)
|
36
|
+
# notifier.info('You hear', dog: 'wow', cats: {chloe: 'mow', timmy: 'mow'})
|
37
|
+
# => I, [2022-09-29T10:51:15.753646 #28763] INFO -- : String - You hear - {:dog=>"wow", :cats=>{:chloe=>"mow", :timmy=>"mow"}}
|
59
38
|
#
|
60
|
-
|
61
|
-
# # "cats":{"chloe":"mow","timmy":"mow"}}}
|
62
|
-
#
|
63
|
-
# - :pretty_json - pretty json output
|
64
|
-
# notifier = LunaPark::Notifiers::Log.new(format: :pretty_json)
|
65
|
-
# notifier.message('You hear', dog: 'wow', cat: {timmy:'purr'}, cow: 'moo', duck: 'quack', horse: 'yell')
|
66
|
-
#
|
67
|
-
# # E, [2020-06-13T18:30:26.856084 #22786] ERROR -- : {
|
68
|
-
# # "message": "You hear",
|
69
|
-
# # "details": {
|
70
|
-
# # "dog": "wow",
|
71
|
-
# # "cat": {
|
72
|
-
# # "timmy": "purr"
|
73
|
-
# # },
|
74
|
-
# # "cow": "moo",
|
75
|
-
# # "duck": "quack",
|
76
|
-
# # "horse": "yell"
|
77
|
-
# # }
|
78
|
-
attr_reader :format
|
39
|
+
attr_reader :formatter
|
79
40
|
|
80
41
|
# Logger which used for output all notify. Should be instance of Logger class.
|
81
42
|
# You can define it in two ways.
|
@@ -97,14 +58,18 @@ module LunaPark
|
|
97
58
|
|
98
59
|
# Create new log notifier
|
99
60
|
#
|
100
|
-
# @param logger
|
101
|
-
# @param
|
102
|
-
# @param
|
103
|
-
|
104
|
-
|
105
|
-
|
61
|
+
# @param logger - Logger which used for output all notify see #logger
|
62
|
+
# @param formatter - Log messages formatter see #formatter
|
63
|
+
# @param format - Formatter name. Deprecated and will be removed in a future version
|
64
|
+
# @param min_lvl - What level should a message be for it to be processed by a notifier
|
65
|
+
def initialize(logger: nil, format: nil, formatter: nil, min_lvl: :debug)
|
106
66
|
@logger = logger || self.class.default_logger
|
107
|
-
@
|
67
|
+
@formatter = formatter || Formatters::SINGLE
|
68
|
+
# @todo Remove format param in the future version
|
69
|
+
unless format.nil?
|
70
|
+
@formatter = formatter_by_name(format)
|
71
|
+
warn 'warn [DEPRECATION] `format` parameter is deprecated, use `formatter` instead'
|
72
|
+
end
|
108
73
|
self.min_lvl = min_lvl
|
109
74
|
end
|
110
75
|
|
@@ -160,13 +125,15 @@ module LunaPark
|
|
160
125
|
|
161
126
|
def serialize(obj, **details)
|
162
127
|
details = extend(details, with: obj)
|
163
|
-
|
128
|
+
formatter.call(obj.class, String(obj), details)
|
129
|
+
end
|
164
130
|
|
165
|
-
|
166
|
-
|
167
|
-
when :
|
168
|
-
when :
|
169
|
-
|
131
|
+
def formatter_by_name(name)
|
132
|
+
case name
|
133
|
+
when :json then Formatters::JSON
|
134
|
+
when :multiline then Formatters::MULTILINE
|
135
|
+
when :pretty_json then Formatters::PRETTY_JSON
|
136
|
+
else Formatters::SINGLE
|
170
137
|
end
|
171
138
|
end
|
172
139
|
end
|
data/lib/luna_park/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: luna_park
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Kudrin
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-11-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bugsnag
|
@@ -375,6 +375,7 @@ files:
|
|
375
375
|
- lib/luna_park/mappers/simple.rb
|
376
376
|
- lib/luna_park/notifiers/bugsnag.rb
|
377
377
|
- lib/luna_park/notifiers/log.rb
|
378
|
+
- lib/luna_park/notifiers/log/formatters.rb
|
378
379
|
- lib/luna_park/notifiers/sentry.rb
|
379
380
|
- lib/luna_park/repositories/postgres.rb
|
380
381
|
- lib/luna_park/repositories/sequel.rb
|