name_tagged_cee_syslogger 0.1.1 → 0.1.2

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: aeab107545167ccb6d92669e82e64df3311f4e86
4
- data.tar.gz: 4dca636114f5651fb623c00f7c85b491b4f5b10f
3
+ metadata.gz: f7ab6cd6d124341745a11abee92226e346f3ec3d
4
+ data.tar.gz: 7c6dacabc576404f4548d24268385b5c54463dae
5
5
  SHA512:
6
- metadata.gz: 3af615533add45e42f124c83a8078dec87a3f03edfb98127d83ed60cd29051d9fd0b08aab35785a2732a05da69c254e18cd58e7b3ac5493ef0dd21b786487181
7
- data.tar.gz: efd78341b1b015e6d2e8fac62001fb5a1783c127baad4fe60dbe5361928918c9ec0cf89a6d064d9b1c16e04ac9b79e19e9029ee0454fde90850ad27b66fde8bb
6
+ metadata.gz: c4447185ef037b01ceb52240371a2f144b71bb45b5a545f4c99302a2aa672596b1e228affafb7f4274165aa01710f9c2d9c05cb4df85381584c74e564ad4c8c2
7
+ data.tar.gz: c9d74ebe9964c4a732c606acba7921d2da1aeb361ce2ec6c2d2eb0ed53f1b23e25e0b6f32cff67752ea5c621f7f5a0270bfe143860dd75aa1c60a93a3e9f9ca3
@@ -22,17 +22,47 @@ module NameTaggedCeeSyslogger
22
22
  end
23
23
 
24
24
  def merge_tags(message)
25
- unless message.is_a?(Hash)
25
+ if message.is_a?(Hash)
26
+ message = message.each_with_object({}) do |(k,v), acc|
27
+ acc[k.to_sym] = v
28
+ end
29
+ else
26
30
  message = { msg: message }
27
31
  end
28
32
 
29
- current_tags.each_with_index do |tag, index|
30
- if tag.is_a?(Hash)
31
- message.merge!(tag)
32
- end
33
- end
33
+ message = current_tags.merge(message)
34
34
 
35
35
  message
36
36
  end
37
+
38
+ def tagged(tags)
39
+ old_tags = current_tags.dup
40
+
41
+ begin
42
+ add_tags(tags)
43
+ yield self
44
+ ensure
45
+ set_tags(old_tags)
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def add_tags(tags)
52
+ return unless tags.is_a?(Hash)
53
+
54
+ tags.each do |(k,v)|
55
+ current_tags[k.to_sym] = v
56
+ end
57
+ end
58
+
59
+ def set_tags(tags)
60
+ clear_tags!
61
+ add_tags(tags)
62
+ end
63
+
64
+ def current_tags
65
+ Thread.current[:name_tagged_logger_tags] ||= {}
66
+ end
37
67
  end
38
68
  end
@@ -1,3 +1,3 @@
1
1
  module NameTaggedCeeSyslogger
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: name_tagged_cee_syslogger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donald Plummer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-03 00:00:00.000000000 Z
11
+ date: 2015-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: syslogger