whoop 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81bf8fe803a7a41184c6bf4600abc8059665bbc040d621b3cc39235915d0c80a
4
- data.tar.gz: 54f408ce9613144520e6b318af06353d61e997a3891e4c315e712da1b6208159
3
+ metadata.gz: b291c7f848acd58ddae598855d1c2782277ee9da307868db273497e908964636
4
+ data.tar.gz: a3fa8fe8b1a749893b8fe87b36ccac5732d7cde30bd1e6def15f90c83a9c534e
5
5
  SHA512:
6
- metadata.gz: b6be592483ea7056091c04733bba3d5c6642f1b28aa52ef2837d07db13c8c555157fce39effb6055c2c3473c2d536db546eebb52e001fcff81837641c02fe5fe
7
- data.tar.gz: fbad092eb0aca584c4668df1b1682d948d6b67104e14763b3f884019efdf1ba79b6ee6b2c51290defc9dbee4f4c41d01147c5f88c20c2eda27424d21e96816ae
6
+ metadata.gz: 61bfc9e8af8a082dc18be22535c19619ef39a3ac98222cf2951cbd3ec9723a3de021718b42ea134f99a051b81984f10e117d1674810074715fad7e10f35c2f58
7
+ data.tar.gz: bd545734157a5ac01cb11e67cfb913fc501081d0fdd7d5f7e84da9976672dd1a2733c26d09855d9b371acbaa1a5fbc7bfe78f99d223227839528430f5f1f7978
data/Gemfile.lock CHANGED
@@ -1,12 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- whoop (1.1.0)
4
+ whoop (1.3.0)
5
5
  activerecord (>= 6.1.4)
6
6
  activesupport (>= 6.1.4)
7
+ amazing_print
7
8
  anbt-sql-formatter
8
9
  colorize
9
10
  rouge
11
+ semantic_logger
10
12
 
11
13
  GEM
12
14
  remote: https://rubygems.org/
@@ -21,10 +23,10 @@ GEM
21
23
  i18n (>= 1.6, < 2)
22
24
  minitest (>= 5.1)
23
25
  tzinfo (~> 2.0)
26
+ amazing_print (1.5.0)
24
27
  anbt-sql-formatter (0.1.0)
25
28
  ast (2.4.2)
26
29
  bump (0.10.0)
27
- byebug (11.1.3)
28
30
  codecov (0.6.0)
29
31
  simplecov (>= 0.15, < 0.22)
30
32
  coderay (1.1.3)
@@ -53,9 +55,6 @@ GEM
53
55
  pry (0.14.2)
54
56
  coderay (~> 1.1)
55
57
  method_source (~> 1.0)
56
- pry-byebug (3.10.1)
57
- byebug (~> 11.0)
58
- pry (>= 0.13, < 0.15)
59
58
  rainbow (3.1.1)
60
59
  rake (13.0.6)
61
60
  rbs (2.8.4)
@@ -91,6 +90,8 @@ GEM
91
90
  rubocop (>= 1.7.0, < 2.0)
92
91
  rubocop-ast (>= 0.4.0)
93
92
  ruby-progressbar (1.13.0)
93
+ semantic_logger (4.15.0)
94
+ concurrent-ruby (~> 1.0)
94
95
  simplecov (0.21.2)
95
96
  docile (~> 1.1)
96
97
  simplecov-html (~> 0.11)
@@ -114,13 +115,15 @@ GEM
114
115
  yard (0.9.34)
115
116
 
116
117
  PLATFORMS
118
+ arm64-darwin-22
119
+ arm64-darwin-23
117
120
  x86_64-linux
118
121
 
119
122
  DEPENDENCIES
120
123
  bump
121
124
  codecov
122
125
  magic_frozen_string_literal
123
- pry-byebug
126
+ pry
124
127
  rake
125
128
  rspec
126
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
@@ -59,10 +60,11 @@ You can pass any options into the `whoop` method to change the output.
59
60
  - `pattern` - String character to use for the line (default is `-`)
60
61
  - `count` - the number of times to repeat the pattern per line (e.g. 80)
61
62
  - `color` - the color to use for the line (e.g. :red)
62
- - `format` - the format to use for the message (one of `:json`, `:sql`, `:plain`)
63
+ - `format` - the format to use for the message (one of `:json`, `:sql`, `:plain`, `:pretty`)
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
 
@@ -106,6 +108,23 @@ whoop({hello: "world"}, format: :json, color: false)
106
108
  # ┗--------------------------------------------------------------------------------
107
109
  ```
108
110
 
111
+ ```ruby
112
+ user = User.first # or some object
113
+ whoop(user, format: :pretty)
114
+
115
+ # ┏--------------------------------------------------------------------------------
116
+ # ┆ timestamp: 2022-09-26 14:28:06 -0600
117
+ # ┆ source: /spec/whoop_spec.rb:39
118
+ #
119
+ # User {
120
+ # :id => 1,
121
+ # :name => "Eric",
122
+ # :location => "Utah"
123
+ # }
124
+ #
125
+ # ┗--------------------------------------------------------------------------------
126
+ ```
127
+
109
128
  ```ruby
110
129
  whoop("This message includes context", color: false, context: {user: "Eric", ip_address: "127.0.0.1"})
111
130
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Whoop
2
4
  class InstallGenerator < Rails::Generators::Base
3
5
  desc "This generator creates an initializer file for the Whoop gem at config/initializers/whoop.rb, with default settings."
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "amazing_print"
4
+
5
+ module Whoop
6
+ module Formatters
7
+ module PrettyFormatter
8
+ # Format the message using AwesomePrint
9
+ # @param [String] message The object/class/message
10
+ # @return [String] The formatted message
11
+ def self.format(message)
12
+ message.ai
13
+ end
14
+ end
15
+ end
16
+ end
data/lib/whoop/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Whoop
4
- VERSION = "1.1.0"
4
+ VERSION = "1.3.0"
5
5
  end
data/lib/whoop.rb CHANGED
@@ -3,8 +3,11 @@
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"
10
+ require_relative "whoop/formatters/pretty_formatter"
8
11
  require_relative "whoop/formatters/sql_formatter"
9
12
 
10
13
  # Whoop.setup do |config|
@@ -27,7 +30,7 @@ module Whoop
27
30
 
28
31
  module Main
29
32
  COLORS = %i[black red green yellow blue magenta cyan white light_black light_red light_green light_yellow light_blue light_magenta light_cyan light_white default].freeze
30
- FORMATS = %i[plain json sql].freeze
33
+ FORMATS = %i[plain pretty json sql].freeze
31
34
  PATTERN = "-"
32
35
  COUNT = 80
33
36
  INDENT = "┆"
@@ -39,26 +42,48 @@ module Whoop
39
42
  # @param [String] pattern - the pattern to use for the line (e.g. '-')
40
43
  # @param [Integer] count - the number of times to repeat the pattern per line (e.g. 80)
41
44
  # @param [Symbol] color - the color to use for the line (e.g. :red)
42
- # @param [Symbol] format - the format to use for the message (one of :json, :sql, :plain)
45
+ # @param [Symbol] format - the format to use for the message (one of :json, :sql, :plain, :semantic, :pretty (default))
43
46
  # @param [Integer] caller_depth - the depth of the caller to use for the source (default: 0)
44
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
45
49
  # @param [Hash] context - Any additional context you'd like to include in the log
46
50
  def whoop(
47
51
  label = nil,
48
52
  pattern: PATTERN,
49
53
  count: COUNT,
50
54
  color: :default,
51
- format: :plain,
55
+ format: :pretty,
52
56
  caller_depth: 0,
53
57
  explain: false,
58
+ tags: [],
54
59
  context: nil
55
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
+
56
82
  logger_method = detect_logger_method
57
83
  color_method = detect_color_method(color)
58
84
  formatter_method = detect_formatter_method(format, colorize: color.present?, explain: explain)
59
-
60
- line = pattern * count
61
85
  caller_path = clean_caller_path(caller[caller_depth])
86
+ line = pattern * count
62
87
  caller_path_line = [color_method.call(INDENT), "source:".colorize(:light_black).underline, caller_path].join(" ")
63
88
  timestamp_line = [color_method.call(INDENT), "timestamp:".colorize(:light_black).underline, Time.now].join(" ")
64
89
 
@@ -71,38 +96,23 @@ module Whoop
71
96
  []
72
97
  end
73
98
 
74
- if block_given?
75
- result = yield
76
- top_line =
77
- if label.present? && label.is_a?(String)
78
- wrapped_line(label.to_s, pattern: pattern, count: count)
79
- else
80
- pattern * count
81
- end
82
- result.tap do
83
- logger_method.call color_method.call "\n\n#{TOP_LINE_CHAR}#{top_line}"
84
- logger_method.call timestamp_line
85
- logger_method.call caller_path_line
86
- context_lines.each { |l| logger_method.call l }
87
- logger_method.call ""
88
- logger_method.call formatter_method.call(result)
89
- logger_method.call ""
90
- display_invalid_format_message(format, color_method, logger_method)
91
- logger_method.call color_method.call "#{BOTTOM_LINE_CHAR}#{line}\n\n"
92
- end
93
- else
94
- tap do
95
- logger_method.call color_method.call "\n\n#{TOP_LINE_CHAR}#{line}"
96
- logger_method.call timestamp_line
97
- logger_method.call caller_path_line
98
- context_lines.each { |l| logger_method.call l }
99
- logger_method.call ""
100
- logger_method.call formatter_method.call(label)
101
- logger_method.call ""
102
- display_invalid_format_message(format, color_method, logger_method)
103
- 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
104
104
  end
105
- end
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"
106
116
  end
107
117
 
108
118
  private
@@ -139,14 +149,20 @@ module Whoop
139
149
  end
140
150
 
141
151
  # Return the format method to use
142
- # @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
143
155
  # @return [Method] format method
144
- def detect_formatter_method(format, colorize: false, explain: false)
156
+ def detect_formatter_method(format, context: {}, colorize: false, explain: false)
145
157
  case format.to_sym
146
158
  when :json
147
159
  ->(message) { Whoop::Formatters::JsonFormatter.format(message, colorize: colorize) }
148
160
  when :sql
149
161
  ->(message) { Whoop::Formatters::SqlFormatter.format(message, colorize: colorize, explain: explain) }
162
+ when :pretty
163
+ ->(message) { Whoop::Formatters::PrettyFormatter.format(message) }
164
+ when :semantic
165
+ ->(message, context = {}) { Whoop::Formatters::PrettyFormatter.format(message, **context) }
150
166
  else
151
167
  ->(message) { message }
152
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)
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: (Symbol format, ?colorize: untyped, ?explain: untyped) -> 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
@@ -129,5 +186,19 @@ module Whoop
129
186
  # _@return_ — The formatted SQL query
130
187
  def self.format: (String message, ?colorize: bool) -> String
131
188
  end
189
+
190
+ module PrettyFormatter
191
+ # Format the message using AwesomePrint
192
+ #
193
+ # _@param_ `message` — The object/class/message
194
+ #
195
+ # _@return_ — The formatted message
196
+ def self.format: (String message) -> String
197
+ end
198
+ end
199
+
200
+ class InstallGenerator < Rails::Generators::Base
201
+ # sord omit - no YARD return type given, using untyped
202
+ def install: () -> untyped
132
203
  end
133
204
  end
data/whoop.gemspec CHANGED
@@ -31,12 +31,14 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.add_dependency "activerecord", ">= 6.1.4"
33
33
  spec.add_dependency "activesupport", ">= 6.1.4"
34
+ spec.add_dependency "amazing_print"
34
35
  spec.add_dependency "anbt-sql-formatter"
35
36
  spec.add_dependency "colorize"
36
37
  spec.add_dependency "rouge"
38
+ spec.add_dependency "semantic_logger"
37
39
 
38
40
  spec.add_development_dependency "magic_frozen_string_literal"
39
- spec.add_development_dependency "pry-byebug"
41
+ spec.add_development_dependency "pry"
40
42
  spec.add_development_dependency "rspec"
41
43
  spec.add_development_dependency "rake"
42
44
  spec.add_development_dependency "standard"
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.1.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Berry
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-18 00:00:00.000000000 Z
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
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: semantic_logger
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: magic_frozen_string_literal
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +123,7 @@ dependencies:
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0'
97
125
  - !ruby/object:Gem::Dependency
98
- name: pry-byebug
126
+ name: pry
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
129
  - - ">="
@@ -225,6 +253,7 @@ files:
225
253
  - lib/generators/whoop/install_generator.rb
226
254
  - lib/whoop.rb
227
255
  - lib/whoop/formatters/json_formatter.rb
256
+ - lib/whoop/formatters/pretty_formatter.rb
228
257
  - lib/whoop/formatters/sql_formatter.rb
229
258
  - lib/whoop/version.rb
230
259
  - sig/whoop.rbs
@@ -236,7 +265,7 @@ metadata:
236
265
  homepage_uri: https://github.com/coderberry/whoop
237
266
  source_code_uri: https://github.com/coderberry/whoop
238
267
  changelog_uri: https://github.com/coderberry/whoop
239
- post_install_message:
268
+ post_install_message:
240
269
  rdoc_options: []
241
270
  require_paths:
242
271
  - lib
@@ -251,8 +280,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
251
280
  - !ruby/object:Gem::Version
252
281
  version: '0'
253
282
  requirements: []
254
- rubygems_version: 3.4.6
255
- signing_key:
283
+ rubygems_version: 3.5.3
284
+ signing_key:
256
285
  specification_version: 4
257
286
  summary: A simple gem to help you whoop your logs into shape.
258
287
  test_files: []