log15 1.0.3 → 1.0.4

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
  SHA1:
3
- metadata.gz: dc7bd26109546f67e0556515b429e95b0f65fe02
4
- data.tar.gz: b8ead02627bebec876eb1c9bee8b141bd19b8843
3
+ metadata.gz: e01f445f52a76ab784ee5c34797355a07b96b429
4
+ data.tar.gz: 242e7e18857ea8d4cec45dbcf9e3b78c6908d43d
5
5
  SHA512:
6
- metadata.gz: 89864de477680aa98a3c2d63f973818f37f2e70e8c1510f68f0d16126662da3a7fd1246238d290d4eabc8cef97347820f922ef3272674943d098410d677e7a74
7
- data.tar.gz: 76e7ac7077f10b7a0e7e2c2e1298fa1779f7826e0b37aa961203ab87c9c6d7b5cfb566b2d035a1ec3aa27e2d8824e22eaef597a55a6f5d4743819aa9d232c0b2
6
+ metadata.gz: 26b682457017190b65fee527c0d7074b79cbddb5e736d7400f3f49b2db79427060603b97a8d9f14173fb1032716e990cd6c5a55293ab6ab241eac624d0ef0626
7
+ data.tar.gz: f814112d003a4a75a2a1283d22b91b27e972373a9a05662f471d40a9399f16eb77a3af1592d68c0bc575b7f5e73a5e4c462d7192343a0a80734faa026c429ed9
@@ -3,8 +3,9 @@ require 'json'
3
3
 
4
4
  module Log15
5
5
  class Logger
6
- attr_accessor :logger
7
- def initialize(logger=Rails.logger)
6
+ attr_accessor :logger, :context
7
+ def initialize(logger=Rails.logger, context={})
8
+ @context = context
8
9
  @logger = logger.dup
9
10
  @logger.formatter = proc do |severity, datetime, progname, msg|
10
11
  date = "#{datetime.month}-#{datetime.day}"
@@ -54,9 +55,14 @@ module Log15
54
55
  logger.error(process(msg, data))
55
56
  end
56
57
 
58
+ def new_context(new_context={})
59
+ self.class.new(logger, self.context.merge(new_context))
60
+ end
61
+
57
62
  private
58
63
 
59
64
  def process(msg, data)
65
+ data.merge!(context)
60
66
  output = ["msg=#{msg.inspect}"]
61
67
  if data.keys.count > 0
62
68
  data.each do |k, v|
@@ -1,3 +1,3 @@
1
1
  module Log15
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -37,6 +37,15 @@ describe Log15 do
37
37
  expect(output).to match(/\[\d{2}-\d{2}|\d{2}:\d{2}:\d{2}\]/)
38
38
  expect(output).to match(/msg="message goes here" foo="\[\\\"bar\\\",\\\"baz\\\"\]" lvl=info\n$/)
39
39
  end
40
+
41
+ it "adds context" do
42
+ new_logger = subject.new_context(foo: "context")
43
+ new_logger.info("message goes here")
44
+ output = log.string
45
+ expect(output).to match(/^INFO/)
46
+ expect(output).to match(/\[\d{2}-\d{2}|\d{2}:\d{2}:\d{2}\]/)
47
+ expect(output).to match(/msg="message goes here" foo="context" lvl=info\n$/)
48
+ end
40
49
  end
41
50
 
42
51
  context "debug" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log15
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-16 00:00:00.000000000 Z
11
+ date: 2015-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json