hedgelog 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzJmODIwYjUzZjJhZjgwY2E2M2EyODQ2NzY2YTcyY2RlYThlMjllZQ==
4
+ ODU3YjJkYTc4ODU2ZGQ4YTNiMmY0YjZiODIzYTZiMjk1ZjA4ZmZmNA==
5
5
  data.tar.gz: !binary |-
6
- ZmQ4OWI5NmQ2ODQ5MDk4ODYxZjEyMTYwZDkwZTFkMjIxYTk4YzVkMA==
6
+ YjkwNTQyZjNjYmE4ZWIxNDMyNTliMGNkZDFhYzQ5MzJlMzM2NmJiNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTgyM2U3ZmIzZmYxN2I4OWMzZmQyOTg3MmJlMmNmY2Y2YWEzNzVlN2IyYTYx
10
- NDM3NGViMjEzNmEzMzRjN2MwNzEwZTA0NTcyMTU4ODQ0MTEyN2M4NzI1Mzhi
11
- Yjg2NDM4ZTdlZjM4YmM3NjZiMzk5Y2I4YWJkMWM3ZTNkZmEyZWU=
9
+ NDQxNTQ3OWNjM2Y0YTUyMWE0OTQyMWYyMzNhZDA1NTM1NzkxOTI2NjlmNzFh
10
+ MDA3YmI0YTgzZWVjNzk3ZDJjM2QzMDFhOTAyNzI1NTZkMzNiMmZhZjU5YjM3
11
+ ZDY1NzhkZWNiNWNiN2IzNTQ1NmZmNmM4YTQ5ODdlODlhZDZhMDc=
12
12
  data.tar.gz: !binary |-
13
- MDBjNzFlMjgyMGU3Y2IwMGVmZmQ5YTM3NGI5ZDlmZThlZTQzYTIwOTY4ZWJl
14
- YTI0NmUzYmJjMzRkODI4NGE2ODczYjVmZTQwYjM0Y2E0YzdmZjU2MjQ4MjMy
15
- YjNlNmJiMmU0YTNkZTUzYjYyYzZiNmEwY2YyMzIxNWM2ODYxNGE=
13
+ MjgxZjEwM2E0MmQzZDUyMjdjOGJlZGE3YzdjNjI0YWEwODczZjFlYTViYzA2
14
+ ZWI3ZWNhODBlNzI5MjQzN2UzZmViYzU1NTdiOWNjNzMzZjAzZGRhZjMyMzAy
15
+ ZmRlZGY2NDIwYjcwMjc4OTk0N2E2NzU2OWM5NmNjYTc0OWQyZjU=
@@ -1,12 +1,14 @@
1
1
  require 'hedgelog/scrubber'
2
+ require 'hedgelog/normalizer'
2
3
 
3
4
  class Hedgelog
4
5
  class Context
5
- def initialize(scrubber, data = {})
6
+ def initialize(scrubber, normalizer, data = {})
6
7
  raise ::ArgumentError, "#{self.class}: argument must be Hash got #{data.class}." unless data.is_a? Hash
7
8
  check_reserved_keys(data)
8
9
  @data = data
9
10
  @scrubber = scrubber
11
+ @normalizer = normalizer
10
12
  end
11
13
 
12
14
  def []=(key, val)
@@ -50,6 +52,11 @@ class Hedgelog
50
52
  self
51
53
  end
52
54
 
55
+ def normalize!
56
+ @data = @normalizer.normalize(@data)
57
+ self
58
+ end
59
+
53
60
  def to_h
54
61
  @data
55
62
  end
@@ -0,0 +1,33 @@
1
+ class Hedgelog
2
+ class Normalizer
3
+ def normalize(data)
4
+ # Need to Marshal.dump/Marshal.load to deep copy the input so that scrubbing doesn't change global state
5
+ d = Marshal.load(Marshal.dump(data))
6
+ normalize_hash(d)
7
+ end
8
+
9
+ def normalize_struct(struct)
10
+ normalize_hash(Hash[struct.each_pair.to_a])
11
+ end
12
+
13
+ def normalize_hash(hash)
14
+ Hash[hash.map do |key, val|
15
+ [key, normalize_thing(val)]
16
+ end]
17
+ end
18
+
19
+ def normalize_array(array)
20
+ array.to_json
21
+ end
22
+
23
+ private
24
+
25
+ def normalize_thing(thing)
26
+ return '' if thing.nil?
27
+ return normalize_struct(thing) if thing.is_a?(Struct)
28
+ return normalize_array(thing) if thing.is_a?(Array)
29
+ return normalize_hash(thing) if thing.is_a?(Hash)
30
+ thing
31
+ end
32
+ end
33
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class Hedgelog
3
- VERSION = '0.1.5'.freeze
3
+ VERSION = '0.1.6'.freeze
4
4
  end
data/lib/hedgelog.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  require 'hedgelog/version'
3
3
  require 'hedgelog/context'
4
4
  require 'hedgelog/scrubber'
5
+ require 'hedgelog/normalizer'
5
6
  require 'logger'
6
7
  require 'yajl'
7
8
 
@@ -26,7 +27,8 @@ class Hedgelog
26
27
  @logdev = nil
27
28
  @app = nil
28
29
  @scrubber = Hedgelog::Scrubber.new
29
- @channel_context = Hedgelog::Context.new(@scrubber)
30
+ @normalizer = Hedgelog::Normalizer.new
31
+ @channel_context = Hedgelog::Context.new(@scrubber, @normalizer)
30
32
 
31
33
  if logdev.is_a?(self.class)
32
34
  @channel = logdev
@@ -51,7 +53,7 @@ class Hedgelog
51
53
  message, context = *yield if block
52
54
  context ||= {}
53
55
 
54
- context = Hedgelog::Context.new(@scrubber, context) unless context.is_a? Hedgelog::Context
56
+ context = Hedgelog::Context.new(@scrubber, @normalizer, context) unless context.is_a? Hedgelog::Context
55
57
  context.merge!(@channel_context)
56
58
  context[:message] ||= message
57
59
 
@@ -119,6 +121,7 @@ class Hedgelog
119
121
  def write(severity, context)
120
122
  return true if @logdev.nil?
121
123
 
124
+ context.normalize!
122
125
  context.scrub!
123
126
 
124
127
  data = context.merge(default_data(severity))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hedgelog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Utter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-24 00:00:00.000000000 Z
11
+ date: 2016-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yajl-ruby
@@ -64,6 +64,7 @@ files:
64
64
  - hedgelog.gemspec
65
65
  - lib/hedgelog.rb
66
66
  - lib/hedgelog/context.rb
67
+ - lib/hedgelog/normalizer.rb
67
68
  - lib/hedgelog/scrub_replacement.rb
68
69
  - lib/hedgelog/scrubber.rb
69
70
  - lib/hedgelog/version.rb