sonnet 0.1.6 → 0.1.7

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: 3961783bc4eb8f519c30df1a232e34031827335f1e4804f5c5d444ef15bfb57c
4
- data.tar.gz: 2fccb0e4851778f673a1ff10de4a6ed771a919c7692612d0320cfabf3728d849
3
+ metadata.gz: bdf5b36a10d488d4e99a45a1341adae68639e2cf7b78177c4b5a343768676f56
4
+ data.tar.gz: 766ea1806f922074e2524ab6d430c6dcd4cd596edcefcd29c76e50deafdccf8a
5
5
  SHA512:
6
- metadata.gz: 133fb98a3a340477a2076b35d7256aaeb52f6b43e62c1f1b7703d0b4b16a599dabd7defbd7127f3d7ad1463a4de175946db9ca4d05735e63616be0a5b6749c4c
7
- data.tar.gz: bde201a3bddec39c6179d0b371aabfae9d2a9039f1975bb155ad68db0ccb4bebeb5c416f3ab5c933334a03b3196edde874360699823c4afa6f3c0c2d5cc14463
6
+ metadata.gz: 17a5c66a3641e776facb3bcdcac5e85722a31e5aca95915e8e639d2e7415bc94dcd7e1be4b856b99883d03df73fa53a78ec4d1d0b10fb362b0fe977af320f0ea
7
+ data.tar.gz: 9b6c95572efa27e5179134c92eda5650490de3dc8ad856f1bbad171e86a4836976631a49f30e9cd5f36a0c843f3299cc5a39e0a9d065197c796f2e5a46e87db3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sonnet (0.1.6)
4
+ sonnet (0.1.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -54,7 +54,8 @@ module Sonnet
54
54
 
55
55
  def context
56
56
  self.class.current_context.inject({}) do |memo, context|
57
- tags = memo.fetch(:tags, []) + [*context.delete(:tags)].compact
57
+ context = context.dup
58
+ tags = memo.fetch(:tags, []) + [*context.delete(:tags)].flatten.compact
58
59
  tag_context = tags.empty? ? {} : { tags: tags }
59
60
  memo.merge(context).merge(tag_context)
60
61
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sonnet
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.7"
5
5
  end
data/test/logger_test.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "test_helper"
2
4
 
3
5
  class LoggerTest < Minitest::Test
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ # Stub out some Rails constants and methods
6
+ Rails = Module.new
7
+ Rails::Engine = Class.new do
8
+ def self.config
9
+ OpenStruct.new
10
+ end
11
+ end
12
+ ActiveSupport = Module.new
13
+ ActiveSupport::LoggerThreadSafeLevel = Module.new
14
+ LoggerSilence = Module.new
15
+
16
+ class Array
17
+ def present?
18
+ length > 0
19
+ end
20
+ end
21
+
22
+ require 'sonnet/rails'
23
+
24
+ class RailsLoggerTest < Minitest::Test
25
+ def setup
26
+ logger.extend(Sonnet::Logger)
27
+ end
28
+
29
+ def test_tagged_string
30
+ logger.tagged('request_id') do
31
+ logger.info("What's the story, morning glory?")
32
+ end
33
+ assert_equal log[0][:tags], ['request_id']
34
+ end
35
+
36
+ def test_tagged_array
37
+ logger.tagged(['request_id']) do
38
+ logger.info("What's the story, morning glory?")
39
+ end
40
+ assert_equal log[0][:tags], ['request_id']
41
+ end
42
+ 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.6
4
+ version: 0.1.7
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-05-15 00:00:00.000000000 Z
11
+ date: 2019-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -104,8 +104,8 @@ files:
104
104
  - lib/sonnet/version.rb
105
105
  - sonnet.gemspec
106
106
  - test/logger_test.rb
107
+ - test/rails_logger_test.rb
107
108
  - test/sonnet/formatter_test.rb
108
- - test/sonnet_test.rb
109
109
  - test/test_helper.rb
110
110
  homepage: https://github.com/allspiritseve/sonnet
111
111
  licenses:
data/test/sonnet_test.rb DELETED
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class SonnetTest < Minitest::Test
6
- Error = Class.new(StandardError)
7
-
8
- def test_log_info
9
- logger.info("What's the story, morning glory?")
10
- assert_log_line log[0], level: "info", message: "What's the story, morning glory?"
11
- end
12
-
13
- def test_log_debug
14
- logger.debug("this should not be logged")
15
- assert_nil log[0]
16
- logger.level = Logger::DEBUG
17
- logger.debug("this should be logged")
18
- assert_log_line log[0], level: "debug", message: "this should be logged"
19
- end
20
-
21
- def test_log_exception
22
- logger.error(Error.new("something went wrong"))
23
- assert_log_line log[0], message: "something went wrong"
24
- end
25
-
26
- def test_log_with_context
27
- logger.with_context(color: "blue") { logger.info("What's the story, morning glory?") }
28
- logger.info("definitely maybe")
29
- assert_log_line log[0], color: "blue", message: "What's the story, morning glory?"
30
- assert_log_line log[1], message: "definitely maybe"
31
- end
32
-
33
- def test_new
34
- logger = Sonnet::Logger.new(Logger.new(io))
35
- assert_equal logger.formatter, Sonnet::Formatter
36
- logger.info("What's the story, morning glory?")
37
- assert_log_line log[0], level: "info", message: "What's the story, morning glory?"
38
- end
39
-
40
- def assert_log_line(actual, expected)
41
- assert_equal expected, actual.slice(*expected.keys)
42
- end
43
-
44
- def logger
45
- @logger ||= Logger.new(io).tap { |logger| logger.extend(Sonnet::Logger) }
46
- end
47
-
48
- def io
49
- @io ||= StringIO.new
50
- end
51
-
52
- def log
53
- io.string.each_line.map { |line| JSON.parse(line, symbolize_names: true) }
54
- end
55
- end