whoop 1.2.0 → 1.3.0
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 +4 -4
- data/Gemfile.lock +6 -6
- data/README.md +2 -0
- data/lib/whoop/version.rb +1 -1
- data/lib/whoop.rb +49 -36
- data/sig/whoop.rbs +61 -4
- data/whoop.gemspec +49 -0
- metadata +20 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b291c7f848acd58ddae598855d1c2782277ee9da307868db273497e908964636
|
4
|
+
data.tar.gz: a3fa8fe8b1a749893b8fe87b36ccac5732d7cde30bd1e6def15f90c83a9c534e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61bfc9e8af8a082dc18be22535c19619ef39a3ac98222cf2951cbd3ec9723a3de021718b42ea134f99a051b81984f10e117d1674810074715fad7e10f35c2f58
|
7
|
+
data.tar.gz: bd545734157a5ac01cb11e67cfb913fc501081d0fdd7d5f7e84da9976672dd1a2733c26d09855d9b371acbaa1a5fbc7bfe78f99d223227839528430f5f1f7978
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
whoop (1.
|
4
|
+
whoop (1.3.0)
|
5
5
|
activerecord (>= 6.1.4)
|
6
6
|
activesupport (>= 6.1.4)
|
7
7
|
amazing_print
|
8
8
|
anbt-sql-formatter
|
9
9
|
colorize
|
10
10
|
rouge
|
11
|
+
semantic_logger
|
11
12
|
|
12
13
|
GEM
|
13
14
|
remote: https://rubygems.org/
|
@@ -26,7 +27,6 @@ GEM
|
|
26
27
|
anbt-sql-formatter (0.1.0)
|
27
28
|
ast (2.4.2)
|
28
29
|
bump (0.10.0)
|
29
|
-
byebug (11.1.3)
|
30
30
|
codecov (0.6.0)
|
31
31
|
simplecov (>= 0.15, < 0.22)
|
32
32
|
coderay (1.1.3)
|
@@ -55,9 +55,6 @@ GEM
|
|
55
55
|
pry (0.14.2)
|
56
56
|
coderay (~> 1.1)
|
57
57
|
method_source (~> 1.0)
|
58
|
-
pry-byebug (3.10.1)
|
59
|
-
byebug (~> 11.0)
|
60
|
-
pry (>= 0.13, < 0.15)
|
61
58
|
rainbow (3.1.1)
|
62
59
|
rake (13.0.6)
|
63
60
|
rbs (2.8.4)
|
@@ -93,6 +90,8 @@ GEM
|
|
93
90
|
rubocop (>= 1.7.0, < 2.0)
|
94
91
|
rubocop-ast (>= 0.4.0)
|
95
92
|
ruby-progressbar (1.13.0)
|
93
|
+
semantic_logger (4.15.0)
|
94
|
+
concurrent-ruby (~> 1.0)
|
96
95
|
simplecov (0.21.2)
|
97
96
|
docile (~> 1.1)
|
98
97
|
simplecov-html (~> 0.11)
|
@@ -117,13 +116,14 @@ GEM
|
|
117
116
|
|
118
117
|
PLATFORMS
|
119
118
|
arm64-darwin-22
|
119
|
+
arm64-darwin-23
|
120
120
|
x86_64-linux
|
121
121
|
|
122
122
|
DEPENDENCIES
|
123
123
|
bump
|
124
124
|
codecov
|
125
125
|
magic_frozen_string_literal
|
126
|
-
pry
|
126
|
+
pry
|
127
127
|
rake
|
128
128
|
rspec
|
129
129
|
simplecov
|
data/README.md
CHANGED
@@ -36,6 +36,7 @@ Whoop.setup do |config|
|
|
36
36
|
config.logger = ActiveSupport::Logger.new("log/debug.log")
|
37
37
|
# config.logger = ActiveSupport::Logger.new("log/#{Rails.env}.log")
|
38
38
|
# config.logger = ActiveSupport::Logger.new($stdout)
|
39
|
+
# config.logger = SemanticLogger["WHOOP"]
|
39
40
|
# config.logger = nil # uses `puts`
|
40
41
|
|
41
42
|
config.level = :debug
|
@@ -63,6 +64,7 @@ You can pass any options into the `whoop` method to change the output.
|
|
63
64
|
- `caller_depth` - the depth of the caller to use for the source (default: 0)
|
64
65
|
- `explain` - whether to run `EXPLAIN` on the SQL query (default: false)
|
65
66
|
- `context` - a hash of key/value pairs to include in the output
|
67
|
+
- `tags` - an array of tags to include in the output
|
66
68
|
|
67
69
|
## Examples
|
68
70
|
|
data/lib/whoop/version.rb
CHANGED
data/lib/whoop.rb
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
require "active_support"
|
4
4
|
require "colorize"
|
5
5
|
require "rouge"
|
6
|
+
require "semantic_logger"
|
7
|
+
|
6
8
|
require_relative "whoop/version"
|
7
9
|
require_relative "whoop/formatters/json_formatter"
|
8
10
|
require_relative "whoop/formatters/pretty_formatter"
|
@@ -40,9 +42,10 @@ module Whoop
|
|
40
42
|
# @param [String] pattern - the pattern to use for the line (e.g. '-')
|
41
43
|
# @param [Integer] count - the number of times to repeat the pattern per line (e.g. 80)
|
42
44
|
# @param [Symbol] color - the color to use for the line (e.g. :red)
|
43
|
-
# @param [Symbol] format - the format to use for the message (one of :json, :sql, :plain, :pretty (default))
|
45
|
+
# @param [Symbol] format - the format to use for the message (one of :json, :sql, :plain, :semantic, :pretty (default))
|
44
46
|
# @param [Integer] caller_depth - the depth of the caller to use for the source (default: 0)
|
45
47
|
# @param [Boolean] explain - whether to explain the SQL query (default: false)
|
48
|
+
# @param [Array<String, Symbol>] tags - Any tags you'd like to include in the log
|
46
49
|
# @param [Hash] context - Any additional context you'd like to include in the log
|
47
50
|
def whoop(
|
48
51
|
label = nil,
|
@@ -52,14 +55,35 @@ module Whoop
|
|
52
55
|
format: :pretty,
|
53
56
|
caller_depth: 0,
|
54
57
|
explain: false,
|
58
|
+
tags: [],
|
55
59
|
context: nil
|
56
60
|
)
|
61
|
+
message = block_given? ? yield : label
|
62
|
+
|
63
|
+
if Whoop.logger.is_a?(SemanticLogger::Logger)
|
64
|
+
context ||= {}
|
65
|
+
|
66
|
+
if tags.length > 0
|
67
|
+
Whoop.logger.tagged(*tags) do
|
68
|
+
Whoop.logger.send(Whoop.level.to_sym, message, **context)
|
69
|
+
end
|
70
|
+
else
|
71
|
+
Whoop.logger.send(Whoop.level.to_sym, message, **context)
|
72
|
+
end
|
73
|
+
|
74
|
+
return
|
75
|
+
end
|
76
|
+
|
77
|
+
if tags.length > 0
|
78
|
+
context ||= {}
|
79
|
+
context[:tags] = tags
|
80
|
+
end
|
81
|
+
|
57
82
|
logger_method = detect_logger_method
|
58
83
|
color_method = detect_color_method(color)
|
59
84
|
formatter_method = detect_formatter_method(format, colorize: color.present?, explain: explain)
|
60
|
-
|
61
|
-
line = pattern * count
|
62
85
|
caller_path = clean_caller_path(caller[caller_depth])
|
86
|
+
line = pattern * count
|
63
87
|
caller_path_line = [color_method.call(INDENT), "source:".colorize(:light_black).underline, caller_path].join(" ")
|
64
88
|
timestamp_line = [color_method.call(INDENT), "timestamp:".colorize(:light_black).underline, Time.now].join(" ")
|
65
89
|
|
@@ -72,38 +96,23 @@ module Whoop
|
|
72
96
|
[]
|
73
97
|
end
|
74
98
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
else
|
81
|
-
pattern * count
|
82
|
-
end
|
83
|
-
result.tap do
|
84
|
-
logger_method.call color_method.call "\n\n#{TOP_LINE_CHAR}#{top_line}"
|
85
|
-
logger_method.call timestamp_line
|
86
|
-
logger_method.call caller_path_line
|
87
|
-
context_lines.each { |l| logger_method.call l }
|
88
|
-
logger_method.call ""
|
89
|
-
logger_method.call formatter_method.call(result)
|
90
|
-
logger_method.call ""
|
91
|
-
display_invalid_format_message(format, color_method, logger_method)
|
92
|
-
logger_method.call color_method.call "#{BOTTOM_LINE_CHAR}#{line}\n\n"
|
93
|
-
end
|
94
|
-
else
|
95
|
-
tap do
|
96
|
-
logger_method.call color_method.call "\n\n#{TOP_LINE_CHAR}#{line}"
|
97
|
-
logger_method.call timestamp_line
|
98
|
-
logger_method.call caller_path_line
|
99
|
-
context_lines.each { |l| logger_method.call l }
|
100
|
-
logger_method.call ""
|
101
|
-
logger_method.call formatter_method.call(label)
|
102
|
-
logger_method.call ""
|
103
|
-
display_invalid_format_message(format, color_method, logger_method)
|
104
|
-
logger_method.call color_method.call "#{BOTTOM_LINE_CHAR}#{line}\n\n"
|
99
|
+
top_line =
|
100
|
+
if label.present? && label.is_a?(String)
|
101
|
+
wrapped_line(label.to_s, pattern: pattern, count: count)
|
102
|
+
else
|
103
|
+
pattern * count
|
105
104
|
end
|
106
|
-
|
105
|
+
|
106
|
+
logger_method.call color_method.call top_line
|
107
|
+
logger_method.call color_method.call "\n\n#{TOP_LINE_CHAR}#{top_line}"
|
108
|
+
logger_method.call timestamp_line
|
109
|
+
logger_method.call caller_path_line
|
110
|
+
context_lines.each { |l| logger_method.call l }
|
111
|
+
logger_method.call ""
|
112
|
+
logger_method.call formatter_method.call(message)
|
113
|
+
logger_method.call ""
|
114
|
+
display_invalid_format_message(format, color_method, logger_method)
|
115
|
+
logger_method.call color_method.call "#{BOTTOM_LINE_CHAR}#{line}\n\n"
|
107
116
|
end
|
108
117
|
|
109
118
|
private
|
@@ -140,9 +149,11 @@ module Whoop
|
|
140
149
|
end
|
141
150
|
|
142
151
|
# Return the format method to use
|
143
|
-
# @param [Symbol] format
|
152
|
+
# @param [Symbol] format - one of :json, :sql, :pretty, :semantic, :plain
|
153
|
+
# @param [Hash] context - the context provided
|
154
|
+
# @param [Boolean] explain - if format is sql, execute the explain on the query
|
144
155
|
# @return [Method] format method
|
145
|
-
def detect_formatter_method(format, colorize: false, explain: false)
|
156
|
+
def detect_formatter_method(format, context: {}, colorize: false, explain: false)
|
146
157
|
case format.to_sym
|
147
158
|
when :json
|
148
159
|
->(message) { Whoop::Formatters::JsonFormatter.format(message, colorize: colorize) }
|
@@ -150,6 +161,8 @@ module Whoop
|
|
150
161
|
->(message) { Whoop::Formatters::SqlFormatter.format(message, colorize: colorize, explain: explain) }
|
151
162
|
when :pretty
|
152
163
|
->(message) { Whoop::Formatters::PrettyFormatter.format(message) }
|
164
|
+
when :semantic
|
165
|
+
->(message, context = {}) { Whoop::Formatters::PrettyFormatter.format(message, **context) }
|
153
166
|
else
|
154
167
|
->(message) { message }
|
155
168
|
end
|
data/sig/whoop.rbs
CHANGED
@@ -29,12 +29,14 @@ module Whoop
|
|
29
29
|
#
|
30
30
|
# _@param_ `color` — - the color to use for the line (e.g. :red)
|
31
31
|
#
|
32
|
-
# _@param_ `format` — - the format to use for the message (one of :json, :sql, :plain, :pretty (default))
|
32
|
+
# _@param_ `format` — - the format to use for the message (one of :json, :sql, :plain, :semantic, :pretty (default))
|
33
33
|
#
|
34
34
|
# _@param_ `caller_depth` — - the depth of the caller to use for the source (default: 0)
|
35
35
|
#
|
36
36
|
# _@param_ `explain` — - whether to explain the SQL query (default: false)
|
37
37
|
#
|
38
|
+
# _@param_ `tags` — - Any tags you'd like to include in the log
|
39
|
+
#
|
38
40
|
# _@param_ `context` — - Any additional context you'd like to include in the log
|
39
41
|
def whoop: (
|
40
42
|
?String? label,
|
@@ -44,6 +46,7 @@ module Whoop
|
|
44
46
|
?format: Symbol,
|
45
47
|
?caller_depth: Integer,
|
46
48
|
?explain: bool,
|
49
|
+
?tags: ::Array[(String | Symbol)],
|
47
50
|
?context: ::Hash[untyped, untyped]?
|
48
51
|
) -> untyped
|
49
52
|
|
@@ -65,13 +68,21 @@ module Whoop
|
|
65
68
|
def detect_logger_method: () -> Method
|
66
69
|
|
67
70
|
# sord omit - no YARD type given for "colorize:", using untyped
|
68
|
-
# sord omit - no YARD type given for "explain:", using untyped
|
69
71
|
# Return the format method to use
|
70
72
|
#
|
71
|
-
# _@param_ `format`
|
73
|
+
# _@param_ `format` — - one of :json, :sql, :pretty, :semantic, :plain
|
74
|
+
#
|
75
|
+
# _@param_ `context` — - the context provided
|
76
|
+
#
|
77
|
+
# _@param_ `explain` — - if format is sql, execute the explain on the query
|
72
78
|
#
|
73
79
|
# _@return_ — format method
|
74
|
-
def detect_formatter_method: (
|
80
|
+
def detect_formatter_method: (
|
81
|
+
Symbol format,
|
82
|
+
?context: ::Hash[untyped, untyped],
|
83
|
+
?colorize: untyped,
|
84
|
+
?explain: bool
|
85
|
+
) -> Method
|
75
86
|
|
76
87
|
# sord omit - no YARD type given for "format", using untyped
|
77
88
|
# sord omit - no YARD type given for "color_method", using untyped
|
@@ -89,6 +100,52 @@ module Whoop
|
|
89
100
|
def wrapped_line: (String label, ?count: Integer, ?pattern: String) -> String
|
90
101
|
end
|
91
102
|
|
103
|
+
module Constants
|
104
|
+
class ICONS
|
105
|
+
CHECKMARK: untyped
|
106
|
+
TIMES: untyped
|
107
|
+
PLUS: untyped
|
108
|
+
MINUS: untyped
|
109
|
+
end
|
110
|
+
|
111
|
+
class COLORS
|
112
|
+
BLACK: untyped
|
113
|
+
RED: untyped
|
114
|
+
GREEN: untyped
|
115
|
+
YELLOW: untyped
|
116
|
+
BLUE: untyped
|
117
|
+
MAGENTA: untyped
|
118
|
+
CYAN: untyped
|
119
|
+
WHITE: untyped
|
120
|
+
DEFAULT: untyped
|
121
|
+
LIGHT_BLACK: untyped
|
122
|
+
LIGHT_RED: untyped
|
123
|
+
LIGHT_GREEN: untyped
|
124
|
+
LIGHT_YELLOW: untyped
|
125
|
+
LIGHT_BLUE: untyped
|
126
|
+
LIGHT_MAGENTA: untyped
|
127
|
+
LIGHT_CYAN: untyped
|
128
|
+
LIGHT_WHITE: untyped
|
129
|
+
end
|
130
|
+
|
131
|
+
class MODES
|
132
|
+
DEFAULT: untyped
|
133
|
+
BOLD: untyped
|
134
|
+
DIM: untyped
|
135
|
+
ITALIC: untyped
|
136
|
+
UNDERLINE: untyped
|
137
|
+
BLINK: untyped
|
138
|
+
BLINK_SLOW: untyped
|
139
|
+
BLINK_FAST: untyped
|
140
|
+
INVERT: untyped
|
141
|
+
HIDE: untyped
|
142
|
+
STRIKE: untyped
|
143
|
+
DOUBLE_UNDERLINE: untyped
|
144
|
+
REVEAL: untyped
|
145
|
+
OVERLINED: untyped
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
92
149
|
module Formatters
|
93
150
|
module SqlFormatter
|
94
151
|
PATTERNS_TO_PRESERVE: untyped
|
data/whoop.gemspec
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/whoop/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "whoop"
|
7
|
+
spec.version = Whoop::VERSION
|
8
|
+
spec.authors = ["Eric Berry"]
|
9
|
+
spec.email = ["eric@berry.sh"]
|
10
|
+
|
11
|
+
spec.summary = "A simple gem to help you whoop your logs into shape."
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/coderberry/whoop"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(__dir__) do
|
24
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_dependency "activerecord", ">= 6.1.4"
|
33
|
+
spec.add_dependency "activesupport", ">= 6.1.4"
|
34
|
+
spec.add_dependency "amazing_print"
|
35
|
+
spec.add_dependency "anbt-sql-formatter"
|
36
|
+
spec.add_dependency "colorize"
|
37
|
+
spec.add_dependency "rouge"
|
38
|
+
spec.add_dependency "semantic_logger"
|
39
|
+
|
40
|
+
spec.add_development_dependency "magic_frozen_string_literal"
|
41
|
+
spec.add_development_dependency "pry"
|
42
|
+
spec.add_development_dependency "rspec"
|
43
|
+
spec.add_development_dependency "rake"
|
44
|
+
spec.add_development_dependency "standard"
|
45
|
+
spec.add_development_dependency "bump"
|
46
|
+
spec.add_development_dependency "sord"
|
47
|
+
spec.add_development_dependency "simplecov"
|
48
|
+
spec.add_development_dependency "codecov"
|
49
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whoop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Berry
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 6.1.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: amazing_print
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: anbt-sql-formatter
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,7 +95,7 @@ dependencies:
|
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
98
|
+
name: semantic_logger
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - ">="
|
@@ -109,7 +123,7 @@ dependencies:
|
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
|
-
name: pry
|
126
|
+
name: pry
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
129
|
- - ">="
|
@@ -243,6 +257,7 @@ files:
|
|
243
257
|
- lib/whoop/formatters/sql_formatter.rb
|
244
258
|
- lib/whoop/version.rb
|
245
259
|
- sig/whoop.rbs
|
260
|
+
- whoop.gemspec
|
246
261
|
homepage: https://github.com/coderberry/whoop
|
247
262
|
licenses:
|
248
263
|
- MIT
|
@@ -265,7 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
265
280
|
- !ruby/object:Gem::Version
|
266
281
|
version: '0'
|
267
282
|
requirements: []
|
268
|
-
rubygems_version: 3.
|
283
|
+
rubygems_version: 3.5.3
|
269
284
|
signing_key:
|
270
285
|
specification_version: 4
|
271
286
|
summary: A simple gem to help you whoop your logs into shape.
|