hatchet 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -90,6 +90,16 @@ module Hatchet
90
90
  end
91
91
  end
92
92
 
93
+ # Internal: Removes the caching Hash of every appender so that they will all
94
+ # be re-initialized.
95
+ #
96
+ # Used when a change to logging levels is made so that the caches will not
97
+ # contain stale values.
98
+ #
99
+ def clear_levels_cache!
100
+ appenders.each(&:clear_levels_cache!)
101
+ end
102
+
93
103
  end
94
104
 
95
105
  end
@@ -7,7 +7,7 @@ module Hatchet
7
7
  #
8
8
  module LevelManager
9
9
 
10
- # Private: All the possible levels of log filter in order of severity.
10
+ # Internal: All the possible levels of log filter in order of severity.
11
11
  #
12
12
  LEVELS = [:debug, :info, :warn, :error, :fatal, :off]
13
13
 
@@ -24,6 +24,7 @@ module Hatchet
24
24
  # Returns nothing.
25
25
  def levels=(levels)
26
26
  @levels = levels
27
+ clear_levels_cache!
27
28
  end
28
29
 
29
30
  # Public: Set the lowest level of message to log for the given context.
@@ -31,13 +32,23 @@ module Hatchet
31
32
  # level - The lowest level of message to log for the given context.
32
33
  # context - The context that level applies to (default: nil).
33
34
  #
34
- # Setting a level for nil set the default level for all contexts that have
35
+ # Setting a level for nil sets the default level for all contexts that have
35
36
  # not been specified.
36
37
  #
37
38
  # Returns nothing.
38
39
  def level(level, context = nil)
39
40
  context = context.to_s unless context.nil?
40
41
  self.levels[context] = level
42
+ clear_levels_cache!
43
+ end
44
+
45
+ # Public: Set the lowest level of message to log by default.
46
+ #
47
+ # level - The lowest level of message to log by default.
48
+ #
49
+ # Returns nothing.
50
+ def level=(level)
51
+ self.level(level)
41
52
  end
42
53
 
43
54
  # Internal: Returns true if the appender is configured to log messages of
@@ -50,17 +61,34 @@ module Hatchet
50
61
  # level within the given context, otherwise returns false.
51
62
  #
52
63
  def enabled?(level, context)
53
- unless self.levels.key? context
54
- lvl = self.levels[nil]
64
+ unless self.levels_cache.key? context
65
+ lvl = self.levels_cache[nil]
55
66
  root = []
56
67
  context.to_s.split('::').each do |part|
57
68
  root << part
58
69
  path = root.join '::'
59
- lvl = self.levels[path] if self.levels.key? path
70
+ lvl = self.levels_cache[path] if self.levels_cache.key? path
60
71
  end
61
- self.levels[context] = lvl
72
+ self.levels_cache[context] = lvl
62
73
  end
63
- LEVELS.index(level) >= LEVELS.index(self.levels[context])
74
+ LEVELS.index(level) >= LEVELS.index(self.levels_cache[context])
75
+ end
76
+
77
+ # Internal: Returns a lazily duplicated Hash from the levels Hash which is
78
+ # used to store the calculated logging level for specific contexts to make
79
+ # subsequent lookups more efficient.
80
+ #
81
+ def levels_cache
82
+ @_levels_cache ||= self.levels.dup
83
+ end
84
+
85
+ # Internal: Removes the caching Hash so that it will be re-initialized.
86
+ #
87
+ # Used when a change to logging levels is made so that the cache will not
88
+ # contain stale values.
89
+ #
90
+ def clear_levels_cache!
91
+ @_levels_cache = nil
64
92
  end
65
93
 
66
94
  end
@@ -4,6 +4,6 @@ module Hatchet
4
4
 
5
5
  # Public: The version of Hatchet.
6
6
  #
7
- VERSION = '0.0.12'
7
+ VERSION = '0.0.13'
8
8
 
9
9
  end
@@ -91,6 +91,19 @@ describe 'configuration' do
91
91
  it 'set to info' do
92
92
  assert appender.levels[nil] == :info
93
93
  end
94
+
95
+ describe "when changed the appender's reflect that change" do
96
+ before do
97
+ assert appender.enabled?(:info, 'Foo')
98
+ Hatchet.configure do |config|
99
+ config.level = :fatal
100
+ end
101
+ end
102
+
103
+ it 'should no longer have info enabled' do
104
+ refute appender.enabled?(:info, 'Foo')
105
+ end
106
+ end
94
107
  end
95
108
 
96
109
  describe 'everything wires up' do
@@ -60,6 +60,14 @@ describe LevelManager do
60
60
  assert @manager.enabled?(:info, 'Foo')
61
61
  end
62
62
  end
63
+
64
+ describe 'altering the default level' do
65
+ it 'alters the enabled level for subsequent calls' do
66
+ assert @manager.enabled?(:info, 'Foo::Bar')
67
+ @manager.level = :fatal
68
+ refute @manager.enabled?(:info, 'Foo::Bar')
69
+ end
70
+ end
63
71
  end
64
72
  end
65
73
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hatchet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-30 00:00:00.000000000 Z
12
+ date: 2012-08-05 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Logging library that provides the ability to add class/module specific
15
15
  filters
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  version: '0'
66
66
  requirements: []
67
67
  rubyforge_project:
68
- rubygems_version: 1.8.17
68
+ rubygems_version: 1.8.24
69
69
  signing_key:
70
70
  specification_version: 3
71
71
  summary: Logging library that provides the ability to add class/module specific filters