json_tagged_logger 0.3.0 → 0.4.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: fde9c968aab725f59b4d0002b2e318b286edb8e8b7790222d1002e51ce631e6e
4
- data.tar.gz: 97e23c6b02ec7faa8869659c59ef8ba1f2bc200cd607b4e248d2e8a7e74cab5f
3
+ metadata.gz: f290019420ad4691086787da1f7c2982383eaae9812bc2eb1874778ce5d00718
4
+ data.tar.gz: 9a52e70773163bd3428612d56b1f723bd50550763f84710eda06aec1a02cd9a7
5
5
  SHA512:
6
- metadata.gz: 2c21e9f1e126a80a8160587f04d30ca7ccd83433471e78c017320734d570f3cb43935e78bf8bd0a858d114c98fd2fc2115b45363f9e0e283d4c3d6ba182dd94e
7
- data.tar.gz: be70dcda430a3341613c09c85eebcc66f98c9361658192808ab6fb9b0bd63b498713e8ff907fad6c6ce116dead29c302acb11c8bb51bf91edd5e8a6b3df880ab
6
+ metadata.gz: 902135acc6779b5d4a5f63313a8f0ced0125d08998d61ebf77064dd4159764cb14bac9353a11f0efc70a02cc99bed628eaea25dbbd95169dc79c3ef5b782d786
7
+ data.tar.gz: 3ad70d7851f82976ac866d1ad3553670f3122c8476429de4064d71333214cadbebcfb7e9af1d013151c04f83ff5d8038ce52cc7fd88fb453c7bf8529074aae50
data/README.md CHANGED
@@ -62,7 +62,7 @@ will get you something like
62
62
  }
63
63
  ```
64
64
 
65
- [Note: I've pretty-printed the output in these examples for easier reading. The actual log output will be on a single line without extra whitespace.]
65
+ [_Note_: By default, `JsonTaggedLogger::Formatter` outputs logs as single lines without extra whitespace. Setting `JsonTaggedLogger::Formatter#pretty_print` to `true` will pretty print the logs, as I've done in these examples.]
66
66
 
67
67
  Importantly, if the controller action (or any code it calls along the way) has an explicit call to `Rails.logger.tagged("TAG").info("tagged log message")`, you'll get the same key/value tags (`request_id`, `host`, `my_param`, &c.) in the JSON document along with a `tags` key:
68
68
 
@@ -3,6 +3,12 @@ require 'json'
3
3
 
4
4
  module JsonTaggedLogger
5
5
  class Formatter
6
+ attr_accessor :pretty_print
7
+
8
+ def initialize(pretty_print: false)
9
+ @pretty_pretty = pretty_print
10
+ end
11
+
6
12
  def call(severity, _time, _progname, message)
7
13
  log = {
8
14
  level: severity,
@@ -36,7 +42,7 @@ module JsonTaggedLogger
36
42
  end
37
43
  end
38
44
 
39
- log.compact.to_json + "\n"
45
+ format_for_output(log)
40
46
  end
41
47
 
42
48
  private
@@ -69,5 +75,17 @@ module JsonTaggedLogger
69
75
  message
70
76
  end
71
77
  end
78
+
79
+ def format_for_output(log_hash)
80
+ compacted_log = log_hash.compact
81
+
82
+ output_json = if pretty_print
83
+ JSON.pretty_generate(compacted_log)
84
+ else
85
+ JSON.generate(compacted_log)
86
+ end
87
+
88
+ output_json + "\n"
89
+ end
72
90
  end
73
91
  end
@@ -1,3 +1,3 @@
1
1
  module JsonTaggedLogger
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_tagged_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Santry