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 +4 -4
- data/lib/log15/logger.rb +8 -2
- data/lib/log15/version.rb +1 -1
- data/spec/log15/logger_spec.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e01f445f52a76ab784ee5c34797355a07b96b429
|
4
|
+
data.tar.gz: 242e7e18857ea8d4cec45dbcf9e3b78c6908d43d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26b682457017190b65fee527c0d7074b79cbddb5e736d7400f3f49b2db79427060603b97a8d9f14173fb1032716e990cd6c5a55293ab6ab241eac624d0ef0626
|
7
|
+
data.tar.gz: f814112d003a4a75a2a1283d22b91b27e972373a9a05662f471d40a9399f16eb77a3af1592d68c0bc575b7f5e73a5e4c462d7192343a0a80734faa026c429ed9
|
data/lib/log15/logger.rb
CHANGED
@@ -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|
|
data/lib/log15/version.rb
CHANGED
data/spec/log15/logger_spec.rb
CHANGED
@@ -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.
|
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:
|
11
|
+
date: 2015-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|