belt 0.5.0 → 0.5.2
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/CHANGELOG.md +11 -0
- data/lib/belt/cli/logs_command.rb +22 -4
- data/lib/belt/helpers/response.rb +11 -1
- data/lib/belt/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6bc7f1c9dc1e95a012e77ad0b45dd86f387d51d9d84868fc833e64a86875bf32
|
|
4
|
+
data.tar.gz: 4bdb7b2e6aa73f0dbb327b4639e95bbf0c19edd9200110f61e7cbd099984b6a2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 360ffa36c8bd746241454b4298ee0804d192e21b899817e2c31ba348683d00501894615cb5896afd2a49c5e36228de101a72efd566add9ca5ff96ce9c21bb7f5
|
|
7
|
+
data.tar.gz: 3a0d97d2ead9d8a2c22e074cc0ad10bfdc3727c6de25e7f5eb4ab2efe91ddbd2a402109d3b3bc33d6b7ca3dbe011c34d1579677b132089419aeb1f582ebf8fbb
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.2
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **`belt logs` now surfaces extra structured fields on each log line.** Any custom
|
|
8
|
+
keys passed to the structured logger (e.g. `sku`, `mode`, `user_id`) are rendered as
|
|
9
|
+
dim `key=value` pairs appended to ERROR, WARN, and generic leveled log lines. Keys
|
|
10
|
+
already shown elsewhere or too noisy to repeat (`level`, `message`, `timestamp`,
|
|
11
|
+
`request_id`, `action`, `backtrace`, etc.) are filtered out, and `nil` values are
|
|
12
|
+
skipped. Non-string values are JSON-encoded so structured context stays readable.
|
|
13
|
+
|
|
3
14
|
## 0.5.0
|
|
4
15
|
|
|
5
16
|
### Added
|
|
@@ -62,6 +62,12 @@ module Belt
|
|
|
62
62
|
USAGE
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
+
# Structured log keys already rendered elsewhere or too noisy to repeat per line.
|
|
66
|
+
HIDDEN_CONTEXT_KEYS = %w[
|
|
67
|
+
level message timestamp time ts request_id function_name function_version
|
|
68
|
+
action path backtrace error_class error_message
|
|
69
|
+
].freeze
|
|
70
|
+
|
|
65
71
|
def initialize(args)
|
|
66
72
|
@lambda_name = nil
|
|
67
73
|
@env = nil
|
|
@@ -496,7 +502,7 @@ module Belt
|
|
|
496
502
|
|
|
497
503
|
def format_error_log(json, message, timestamp, prefix_str)
|
|
498
504
|
puts "#{prefix_str}#{c(:gray)}#{timestamp}#{c(:reset)} " \
|
|
499
|
-
"#{c(:red)}ERROR#{c(:reset)} #{c(:bold)}#{message}#{c(:reset)}"
|
|
505
|
+
"#{c(:red)}ERROR#{c(:reset)} #{c(:bold)}#{message}#{c(:reset)}#{format_context(json)}"
|
|
500
506
|
puts " #{c(:dim)}Action:#{c(:reset)} #{json['action']}" if json['action']
|
|
501
507
|
if json['error_class']
|
|
502
508
|
puts " #{c(:dim)}Error:#{c(:reset)} " \
|
|
@@ -507,7 +513,8 @@ module Belt
|
|
|
507
513
|
end
|
|
508
514
|
|
|
509
515
|
def format_warn_log(json, message, timestamp, prefix_str)
|
|
510
|
-
puts "#{prefix_str}#{c(:gray)}#{timestamp}#{c(:reset)}
|
|
516
|
+
puts "#{prefix_str}#{c(:gray)}#{timestamp}#{c(:reset)} " \
|
|
517
|
+
"#{c(:yellow)}WARN#{c(:reset)} #{message}#{format_context(json)}"
|
|
511
518
|
if json['error_class']
|
|
512
519
|
puts " #{c(:dim)}Error:#{c(:reset)} " \
|
|
513
520
|
"#{c(:red)}#{json['error_class']}#{c(:reset)}: #{json['error_message']}"
|
|
@@ -530,11 +537,22 @@ module Belt
|
|
|
530
537
|
"#{c(:cyan)}Completed#{c(:reset)} #{c(sc_color)}#{sc}#{c(:reset)} #{path}"
|
|
531
538
|
else
|
|
532
539
|
level = json['level']
|
|
533
|
-
|
|
534
|
-
|
|
540
|
+
return unless level
|
|
541
|
+
|
|
542
|
+
puts "#{prefix_str}#{c(:gray)}#{timestamp}#{c(:reset)} " \
|
|
543
|
+
"#{level_color_for(level)}#{level}#{c(:reset)} #{message}#{format_context(json)}"
|
|
535
544
|
end
|
|
536
545
|
end
|
|
537
546
|
|
|
547
|
+
# Renders extra structured fields (e.g. sku, mode) as dim key=value pairs.
|
|
548
|
+
def format_context(json)
|
|
549
|
+
pairs = json.reject { |k, v| HIDDEN_CONTEXT_KEYS.include?(k) || v.nil? }
|
|
550
|
+
return '' if pairs.empty?
|
|
551
|
+
|
|
552
|
+
formatted = pairs.map { |k, v| "#{k}=#{v.is_a?(String) ? v : v.to_json}" }.join(' ')
|
|
553
|
+
" #{c(:dim)}#{formatted}#{c(:reset)}"
|
|
554
|
+
end
|
|
555
|
+
|
|
538
556
|
def format_aws_error(json, prefix: nil)
|
|
539
557
|
prefix_str = prefix ? "#{c(:blue)}[#{prefix}]#{c(:reset)} " : ''
|
|
540
558
|
puts "#{prefix_str} #{c(:dim)}Error Type:#{c(:reset)} #{c(:red)}#{json['errorType']}#{c(:reset)}"
|
|
@@ -28,8 +28,18 @@ module Belt
|
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
# JSON success. Status accepts Integer or Symbol (:created, :ok, …).
|
|
31
|
+
#
|
|
32
|
+
# The body is deep-serialized the same way implicit assigns are, so handing
|
|
33
|
+
# it a model (or a hash/array containing models) produces real JSON instead
|
|
34
|
+
# of the model's #to_s. This keeps `success_response(thing: @thing)` and the
|
|
35
|
+
# implicit `@thing = ...` path consistent — without it, an explicit
|
|
36
|
+
# success_response silently falls through to `JSON.generate` on the bare
|
|
37
|
+
# object and emits "#<Thing:0x...>". Falls back to the raw body when the
|
|
38
|
+
# serializer isn't mixed in (e.g. the lambda handler, which only ever passes
|
|
39
|
+
# plain hashes).
|
|
31
40
|
def success_response(body, status_code = 200)
|
|
32
|
-
|
|
41
|
+
serialized = respond_to?(:serialize_for_response, true) ? serialize_for_response(body) : body
|
|
42
|
+
{ statusCode: resolve_status(status_code), headers: cors_headers, body: JSON.generate(serialized) }
|
|
33
43
|
end
|
|
34
44
|
|
|
35
45
|
# JSON error. Status accepts Integer or Symbol (:unprocessable_entity, :not_found, …).
|
data/lib/belt/version.rb
CHANGED