appydays 0.5.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80170682f5494542ea76d2d6fd4301acbbfd7c5b8388b3d431ae2c7daa7e03d0
4
- data.tar.gz: 1dae7bcb7f56835bc39f8562d708fada45e3dd8e555f26246a3165bcd2970ab4
3
+ metadata.gz: 664f5e1c23eb4359cdbc71c7f9e9b62648764ef727b35110fb450e2418cc181f
4
+ data.tar.gz: 6f74c5970b4f8932e879ff342d63c19f92bbe606c51af846fab1497b8acf936e
5
5
  SHA512:
6
- metadata.gz: 2110baac67b50e765f0b7d2306f71f007d75b89cbc25dde2f5602e25882a1ce01592c94919f1bff6f0093066f30e8983dd73e4b8b420a0ffde94ed301f72e78d
7
- data.tar.gz: 98b244ba6540e6a53e437d32278db78e5451f74553924cf2d09df0237e089e44d1ce2922440faf6dc381a85d2ccbbdd415fc1f27dfb73537b9703efe0e012cc4
6
+ metadata.gz: abc2c53d7ec2b119cbc80f71b253968cb3767197019fef2d0f71e3377d917efd24685d4f06a66df22ec6c444c03b7db46cf1196d1c4fa6b4ae12598530772ecf
7
+ data.tar.gz: af84d1800825fe54cd8d9182c2d15139a86da3e14040db1ac71b79de386df3f60e662aa04a93c36f5aa6e46124a44b372af1871a50e4668e19d699015e45c23f
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "appydays/configurable"
4
+
5
+ module Appydays::Configurable::SpecHelpers
6
+ def self.included(context)
7
+ context.around(:each) do |example|
8
+ to_reset = example.metadata[:reset_configuration]
9
+ if to_reset
10
+ to_reset = [to_reset] unless to_reset.respond_to?(:to_ary)
11
+ to_reset.each(&:reset_configuration)
12
+ end
13
+ begin
14
+ example.run
15
+ ensure
16
+ to_reset&.each(&:reset_configuration)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "httparty"
4
+
5
+ # Formatter that sends structred log information to HTTParty.
6
+ # After requiring this module, use
7
+ # `HTTParty.<method>(..., logger: semantic_logger, log_format: :appydays)`
8
+ # to write out a nice structured log.
9
+ # You can also subclass this formatter to use your own message (default to httparty_request),
10
+ # and modify the fields (override #fields).
11
+ class Appydays::Loggable::HTTPartyFormatter
12
+ attr_accessor :level, :logger, :message
13
+ attr_reader :request, :response
14
+
15
+ def initialize(logger, level)
16
+ @logger = logger
17
+ @level = level.to_sym
18
+ @message = "httparty_request"
19
+ end
20
+
21
+ def format(request, response)
22
+ @request = request
23
+ @response = response
24
+ self.logger.public_send(self.level, self.message, **self.fields)
25
+ end
26
+
27
+ def fields
28
+ return {
29
+ "content_length" => content_length || "-",
30
+ "http_method" => http_method,
31
+ "path" => path,
32
+ "response_code" => response.code,
33
+ }
34
+ end
35
+
36
+ def http_method
37
+ @http_method ||= request.http_method.name.split("::").last.upcase
38
+ end
39
+
40
+ def path
41
+ @path ||= request.path.to_s
42
+ end
43
+
44
+ def content_length
45
+ @content_length ||= response.respond_to?(:headers) ? response.headers["Content-Length"] : response["Content-Length"]
46
+ end
47
+ end
48
+
49
+ HTTParty::Logger.add_formatter(:appydays, Appydays::Loggable::HTTPartyFormatter)
@@ -4,6 +4,32 @@
4
4
  require "sequel/database/logging"
5
5
 
6
6
  class Sequel::Database
7
+ # Helpers for the Appydays Sequel logger.
8
+ # Very long messages may end up getting logged; the logger will truncate anything
9
+ # longer than +truncate_messages_over+, with +truncation_context+ number of chars
10
+ # at the beginning and at the end.
11
+ #
12
+ # If a message is truncated, the full message is logged at +log_full_message_level+ (default :debug).
13
+ # Use nil to disable the full message logging.
14
+ module AppydaysLogger
15
+ class << self
16
+ attr_accessor :truncate_messages_over, :truncation_message, :truncation_context, :log_full_message_level
17
+
18
+ def setdefaults
19
+ @truncate_messages_over = 2000
20
+ @truncation_message = "<truncated, full message logged at debug>"
21
+ @truncation_context = 200
22
+ end
23
+
24
+ def truncate_message(message)
25
+ return message if message.size <= self.truncate_messages_over
26
+ msg = message[...self.truncation_context] + self.truncation_message + message[-self.truncation_context..]
27
+ return msg
28
+ end
29
+ end
30
+ end
31
+ AppydaysLogger.setdefaults
32
+
7
33
  def log_exception(exception, message)
8
34
  level = message.match?(/^SELECT NULL AS "?nil"? FROM .* LIMIT 1$/i) ? :debug : :error
9
35
  log_each(
@@ -30,10 +56,25 @@ class Sequel::Database
30
56
  # warn level if duration is greater than log_warn_duration.
31
57
  def log_duration(duration, message)
32
58
  lwd = log_warn_duration
59
+ was_truncated = false
33
60
  log_each(
34
61
  lwd && (duration >= lwd) ? :warn : sql_log_level,
35
62
  proc { "(#{'%0.6fs' % duration}) #{message}" },
36
- proc { ["sequel_query", {duration: duration * 1000, query: message}] },
63
+ proc do
64
+ query = AppydaysLogger.truncate_message(message)
65
+ params = {duration: duration * 1000, query: query}
66
+ if query != message
67
+ params[:truncated] = true
68
+ was_truncated = true
69
+ end
70
+ ["sequel_query", params]
71
+ end,
72
+ )
73
+ return unless was_truncated && Sequel::Database::AppydaysLogger.log_full_message_level
74
+ log_each(
75
+ Sequel::Database::AppydaysLogger.log_full_message_level,
76
+ nil,
77
+ proc { ["sequel_query_debug", {duration: duration * 1000, query: message}] },
37
78
  )
38
79
  end
39
80
 
@@ -41,7 +82,7 @@ class Sequel::Database
41
82
  @loggers.each do |logger|
42
83
  if logger.is_a?(SemanticLogger::Base)
43
84
  logger.public_send(level, *semantic.call)
44
- else
85
+ elsif std
45
86
  logger.public_send(level, std.call)
46
87
  end
47
88
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Appydays
4
- VERSION = "0.5.1"
4
+ VERSION = "0.7.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appydays
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lithic Tech
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-24 00:00:00.000000000 Z
11
+ date: 2023-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '4.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.20'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.20'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: monetize
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -128,56 +142,56 @@ dependencies:
128
142
  requirements:
129
143
  - - "~>"
130
144
  - !ruby/object:Gem::Version
131
- version: '1.11'
145
+ version: 1.31.1
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - "~>"
137
151
  - !ruby/object:Gem::Version
138
- version: '1.11'
152
+ version: 1.31.1
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: rubocop-performance
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
157
  - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: '1.10'
159
+ version: 1.14.2
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: '1.10'
166
+ version: 1.14.2
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: rubocop-rake
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - "~>"
158
172
  - !ruby/object:Gem::Version
159
- version: '0.5'
173
+ version: 0.6.0
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
178
  - - "~>"
165
179
  - !ruby/object:Gem::Version
166
- version: '0.5'
180
+ version: 0.6.0
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: rubocop-sequel
169
183
  requirement: !ruby/object:Gem::Requirement
170
184
  requirements:
171
185
  - - "~>"
172
186
  - !ruby/object:Gem::Version
173
- version: '0.2'
187
+ version: 0.3.4
174
188
  type: :development
175
189
  prerelease: false
176
190
  version_requirements: !ruby/object:Gem::Requirement
177
191
  requirements:
178
192
  - - "~>"
179
193
  - !ruby/object:Gem::Version
180
- version: '0.2'
194
+ version: 0.3.4
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: sequel
183
197
  requirement: !ruby/object:Gem::Requirement
@@ -206,6 +220,20 @@ dependencies:
206
220
  - - "~>"
207
221
  - !ruby/object:Gem::Version
208
222
  version: '6.0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: webmock
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: '3.1'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: '3.1'
209
237
  description: 'appydays provides support for env-based configuration, and common structured
210
238
  logging capabilities
211
239
 
@@ -216,8 +244,10 @@ extensions: []
216
244
  extra_rdoc_files: []
217
245
  files:
218
246
  - lib/appydays/configurable.rb
247
+ - lib/appydays/configurable/spec_helpers.rb
219
248
  - lib/appydays/dotenviable.rb
220
249
  - lib/appydays/loggable.rb
250
+ - lib/appydays/loggable/httparty_formatter.rb
221
251
  - lib/appydays/loggable/request_logger.rb
222
252
  - lib/appydays/loggable/sequel_logger.rb
223
253
  - lib/appydays/loggable/sidekiq_job_logger.rb