sonnet 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +42 -3
- data/lib/sonnet/logger.rb +4 -0
- data/lib/sonnet/version.rb +1 -1
- data/test/sonnet_test.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fde1c29033040450a05efda38fc80a4ab39647af542de057bf1a51a12ae9c98
|
4
|
+
data.tar.gz: e02bacca362f4992aa567576d88720c961e3b733e7c9abdba5bdba9487aad0ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bb24a4c08a4429764bd50319d088e342147fbf794ccb908213bd0dc74f010d01acafe9aa2c39f87b3b09396f9d29f072ae3f37a76fd6b2ef2730cd437ba8f0e
|
7
|
+
data.tar.gz: 65509aff4d33b784ec8576e3e78f2ef6bfe2fb9ffea11f9cf03f2877955eba628b12a7051667c68f679ecaf8381d7ac2142bf6f8b4448bcb5a86acfd6f8fc281
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,23 @@
|
|
1
1
|
# Sonnet
|
2
2
|
|
3
|
-
|
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
data/lib/sonnet/version.rb
CHANGED
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
|
+
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-
|
11
|
+
date: 2019-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|