sonnet 0.1.4 → 0.1.5

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: 273fb36aa6154de4836aae0cb4f44ccb4b9799652f8dfebbd08a9ee04d2fa669
4
- data.tar.gz: d8f9d7f79f4a5b436754c7ee7adab6d39a30440b041e306e5e37861592ba7beb
3
+ metadata.gz: 2fde1c29033040450a05efda38fc80a4ab39647af542de057bf1a51a12ae9c98
4
+ data.tar.gz: e02bacca362f4992aa567576d88720c961e3b733e7c9abdba5bdba9487aad0ac
5
5
  SHA512:
6
- metadata.gz: d4ec687ec2c6e93d459a30065d6c4849dff9533cca1dbd6861c9cf18591b490b52e0f250d9e07e4c107d543b83546afb0160f4a23d0ff8ccc2b6663a09c477c5
7
- data.tar.gz: 83305c920737815295ddfc792ae7b979247d3b334a848ff726afa1ea2e16ff73974be8d53513bc9376a5c38235cb7de44b025d4aa02c857bcbd42b8ab33af850
6
+ metadata.gz: 1bb24a4c08a4429764bd50319d088e342147fbf794ccb908213bd0dc74f010d01acafe9aa2c39f87b3b09396f9d29f072ae3f37a76fd6b2ef2730cd437ba8f0e
7
+ data.tar.gz: 65509aff4d33b784ec8576e3e78f2ef6bfe2fb9ffea11f9cf03f2877955eba628b12a7051667c68f679ecaf8381d7ac2142bf6f8b4448bcb5a86acfd6f8fc281
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sonnet (0.1.4)
4
+ sonnet (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,11 +1,23 @@
1
1
  # Sonnet
2
2
 
3
- Structured logging for Ruby applications.
3
+ JSON logging for Ruby applications.
4
+
5
+ ## Philosophy
6
+
7
+ * Adhere to Ruby conventions as much as possible. Keep API as close as possible
8
+ to
9
+ [Logger](https://ruby-doc.org/stdlib-2.6.2/libdoc/logger/rdoc/Logger.html).
10
+ If Sonnet were removed, your log lines should continue to work (though they
11
+ might be ugly).
12
+ * Configurable, to a point
13
+ * For advanced use cases, see below alternatives.
14
+ * Work as well for Ruby application as for Rails
4
15
 
5
16
  ## Alternatives
6
17
 
7
18
  * [Ougai](https://github.com/tilfin/ougai)
8
19
  * [Semantic Logger](https://github.com/rocketjob/semantic_logger)
20
+ * Custom log formatter (seriously, it's really easy!)
9
21
 
10
22
  ## Installation
11
23
 
@@ -27,10 +39,37 @@ Or install it yourself as:
27
39
 
28
40
  ```ruby
29
41
  require "sonnet"
30
- logger = Logger.new(STDOUT)
31
- logger.extend(Sonnet::Logger)
42
+ logger = Sonnet::Logger.new(Logger.new(STDOUT))
32
43
  ```
33
44
 
45
+ ## Ruby on Rails
46
+
47
+ It shouldn't be as much of a pain as it is to configure Rails to log JSON. Even
48
+ if you're able to do it, every gem introduces another logger that might have to
49
+ be configured.
50
+
51
+ ### ActiveSupport::TaggedLogger
52
+
53
+ The easiest workaround is to just not use it. However, Rails uses it
54
+ internally, and _it modifies the logger passed to it_! So you (currently) can't
55
+ escape monkeypatching Rails.
56
+
57
+ Additionally, it is useful to be able to specify context info that gets logged
58
+ with every line inside of a block. I have plans to possibly support `#tagged`,
59
+ but I'm not sure what a sensible default is for converting string tags into a
60
+ hash. Some options:
61
+ * store in a `tags` array
62
+ * attempt to guess at keys for each tag (possble if passing symbols to
63
+ `log_tags`, but probably can't handle every use case).
64
+ * Allow user to define keys for each tag
65
+
66
+ ### ActionDispatch::DebugExceptions
67
+
68
+ This middleware logs exceptions as strings. Since it is included by default,
69
+ the easiest workaround is to monkeypatch it to log the exception rather than
70
+ strings, which means we can handle it with our usual exception logging in
71
+ Sonnet::Formatter.
72
+
34
73
  ## Contributing
35
74
 
36
75
  Bug reports and pull requests are welcome on GitHub at https://github.com/allspiritseve/sonnet.
data/lib/sonnet/logger.rb CHANGED
@@ -11,6 +11,10 @@ module Sonnet
11
11
  ::Logger.const_get((ENV["LOG_LEVEL"] || "INFO").upcase)
12
12
  end
13
13
 
14
+ def self.new(logger)
15
+ logger.extend(self)
16
+ end
17
+
14
18
  def with_context(context = {})
15
19
  formatter.current_context.push(context)
16
20
  yield self
@@ -1,3 +1,3 @@
1
1
  module Sonnet
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
data/test/sonnet_test.rb CHANGED
@@ -28,6 +28,13 @@ class SonnetTest < Minitest::Test
28
28
  assert_log_line log[1], message: "definitely maybe"
29
29
  end
30
30
 
31
+ def test_new
32
+ logger = Sonnet::Logger.new(Logger.new(io))
33
+ assert_equal logger.formatter, Sonnet::Formatter
34
+ logger.info("What's the story, morning glory?")
35
+ assert_log_line log[0], level: "info", message: "What's the story, morning glory?"
36
+ end
37
+
31
38
  def assert_log_line(actual, expected)
32
39
  assert_equal expected, actual.slice(*expected.keys)
33
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sonnet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cory Kaufman-Schofield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-29 00:00:00.000000000 Z
11
+ date: 2019-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler