semantic_logger 2.11.0 → 2.12.0

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: d8ef6f216370a6763f9cd28aa1c5a098c1cc584e
4
- data.tar.gz: c02264af59deef219f5970e8ec51b4af852ed48e
3
+ metadata.gz: 1a76d0de5e08c9768042187ab19b2546d5c91b3a
4
+ data.tar.gz: b04d51de5d531ec57ce382e77ddfd21bd69a420a
5
5
  SHA512:
6
- metadata.gz: e5bf5e189ddccbcf52c57be758a53d8224777ec4a35c2beea4502a3c271cb15e82078ca67ab1aec4da5f5d80a1cf01ef4e8ccea20d9623c442eba0bc272a39b0
7
- data.tar.gz: 4299412a428431a41126a3e6ba47ea6a3c19867c2393162dd61e02d8c6cda8ca5b084405cb1203bb7fc25044d5a47b6cf9e790ddf34fdccbd7b538d57903c1d0
6
+ metadata.gz: 7fc60fcfef8e8c255720de4a4972ae2f0b919dd022eccc68afef004ad1f3fd0870f6c4adc54d190d0ff109a6671be910dbfafdf63f9ade57e9c8caedc66bead1
7
+ data.tar.gz: 2c73e2cf3ac75e19097a3acb6b0437df745c4d60e7c8c3a5a02ef846a9b1ba1b16e37b49e07bbde4851c4ba77e63c1d22e027bf65ea3882150c1608f98db0f93
@@ -81,6 +81,12 @@ module SemanticLogger
81
81
  # An appender can implement a flush method if it supports it.
82
82
  end
83
83
 
84
+ # Returns the current log level if set, otherwise it returns the global
85
+ # default log level
86
+ def level
87
+ @level || :trace
88
+ end
89
+
84
90
  ############################################################################
85
91
  protected
86
92
 
@@ -105,6 +111,13 @@ module SemanticLogger
105
111
  super(self.class, level, filter)
106
112
  end
107
113
 
114
+ # Return the level index for fast comparisons
115
+ # Returns the lowest level index if the level has not been explicitly
116
+ # set for this instance
117
+ def level_index
118
+ @level_index || 0
119
+ end
120
+
108
121
  # For JRuby include the Thread name rather than its id
109
122
  if defined? Java
110
123
  # Return the Time as a formatted string
@@ -0,0 +1,18 @@
1
+ module SemanticLogger
2
+ # Custom logger that maps all calls to debug to trace calls
3
+ # This is useful for existing gems / libraries that log too much to debug
4
+ # when most of the debug logging should be at the trace level
5
+ class DebugAsTraceLogger < Logger
6
+ def debug(*args, &block)
7
+ trace(*args, &block)
8
+ end
9
+
10
+ def debug?
11
+ trace?
12
+ end
13
+
14
+ def benchmark_debug(*args, &block)
15
+ benchmark_trace(*args, &block)
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module SemanticLogger #:nodoc
2
- VERSION = "2.11.0"
2
+ VERSION = "2.12.0"
3
3
  end
@@ -3,9 +3,10 @@ require 'semantic_logger/version'
3
3
  require 'semantic_logger/semantic_logger'
4
4
 
5
5
  module SemanticLogger
6
- autoload :Base, 'semantic_logger/base'
7
- autoload :Logger, 'semantic_logger/logger'
8
- autoload :Loggable, 'semantic_logger/loggable'
6
+ autoload :Base, 'semantic_logger/base'
7
+ autoload :Logger, 'semantic_logger/logger'
8
+ autoload :Loggable, 'semantic_logger/loggable'
9
+ autoload :DebugAsTraceLogger, 'semantic_logger/debug_as_trace_logger'
9
10
 
10
11
  module Appender
11
12
  autoload :Base, 'semantic_logger/appender/base'
@@ -0,0 +1,98 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
+ require 'test_helper'
3
+
4
+ # Unit Test for SemanticLogger::Logger
5
+ class DebugAsTraceLoggerTest < Minitest::Test
6
+ context SemanticLogger::Logger do
7
+ # Test each filter
8
+ [ nil, /\ADebugAsTraceLoggerTest/, Proc.new{|l| (/\AExclude/ =~ l.message).nil? } ].each do |filter|
9
+ context "filter: #{filter.class.name}" do
10
+ setup do
11
+ # Use a mock logger that just keeps the last logged entry in an instance
12
+ # variable
13
+ SemanticLogger.default_level = :trace
14
+ @mock_logger = MockLogger.new
15
+ appender = SemanticLogger.add_appender(@mock_logger)
16
+ appender.filter = filter
17
+
18
+ # Use this test's class name as the application name in the log output
19
+ @logger = SemanticLogger::DebugAsTraceLogger.new(self.class)
20
+ @hash = { :session_id => 'HSSKLEU@JDK767', :tracking_number => 12345 }
21
+ @hash_str = @hash.inspect.sub("{", "\\{").sub("}", "\\}")
22
+ assert_equal [], @logger.tags
23
+ end
24
+
25
+ teardown do
26
+ # Remove all appenders
27
+ SemanticLogger.appenders.each{|appender| SemanticLogger.remove_appender(appender)}
28
+ end
29
+
30
+ context '.level?' do
31
+ should 'return true for debug? with :trace level' do
32
+ SemanticLogger.default_level = :trace
33
+ assert_equal :trace, @logger.level
34
+ assert_equal true, @logger.debug?
35
+ assert_equal true, @logger.trace?
36
+ end
37
+
38
+ should 'return false for debug? with global :debug level' do
39
+ SemanticLogger.default_level = :debug
40
+ assert_equal :debug, @logger.level, @logger.inspect
41
+ assert_equal false, @logger.debug?, @logger.inspect
42
+ assert_equal false, @logger.trace?, @logger.inspect
43
+ end
44
+
45
+ should 'return true for debug? with global :info level' do
46
+ SemanticLogger.default_level = :info
47
+ assert_equal :info, @logger.level, @logger.inspect
48
+ assert_equal false, @logger.debug?, @logger.inspect
49
+ assert_equal false, @logger.trace?, @logger.inspect
50
+ end
51
+
52
+ should 'return false for debug? with instance :debug level' do
53
+ @logger.level = :debug
54
+ assert_equal :debug, @logger.level, @logger.inspect
55
+ assert_equal false, @logger.debug?, @logger.inspect
56
+ assert_equal false, @logger.trace?, @logger.inspect
57
+ end
58
+
59
+ should 'return true for debug? with instance :info level' do
60
+ @logger.level = :info
61
+ assert_equal :info, @logger.level, @logger.inspect
62
+ assert_equal false, @logger.debug?, @logger.inspect
63
+ assert_equal false, @logger.trace?, @logger.inspect
64
+ end
65
+ end
66
+
67
+ should 'not log trace when level is debug' do
68
+ @logger.level = :debug
69
+ @logger.trace('hello world', @hash) { "Calculations" }
70
+ SemanticLogger.flush
71
+ assert_nil @mock_logger.message
72
+ end
73
+
74
+ should 'not log debug when level is debug' do
75
+ @logger.level = :debug
76
+ @logger.debug('hello world', @hash) { "Calculations" }
77
+ SemanticLogger.flush
78
+ assert_nil @mock_logger.message
79
+ end
80
+
81
+ should 'map trace to debug' do
82
+ @logger.level = :trace
83
+ @logger.debug('hello world', @hash) { "Calculations" }
84
+ SemanticLogger.flush
85
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ T \[\d+:.+\] DebugAsTraceLoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message
86
+ end
87
+
88
+ should 'log trace as trace' do
89
+ @logger.level = :trace
90
+ @logger.trace('hello world', @hash) { "Calculations" }
91
+ SemanticLogger.flush
92
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ T \[\d+:.+\] DebugAsTraceLoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message
93
+ end
94
+ end
95
+ end
96
+
97
+ end
98
+ end
data/test/logger_test.rb CHANGED
@@ -97,128 +97,196 @@ class LoggerTest < Minitest::Test
97
97
  end
98
98
  end
99
99
  end
100
+ end
100
101
 
101
- context "Ruby Logger" do
102
- # Ensure that any log level can be logged
103
- Logger::Severity.constants.each do |level|
104
- should "log Ruby logger #{level} info" do
105
- @logger.level = Logger::Severity.const_get(level)
106
- if level.to_s == 'UNKNOWN'
107
- assert_equal Logger::Severity.const_get('ERROR')+1, @logger.send(:level_index)
108
- else
109
- assert_equal Logger::Severity.const_get(level)+1, @logger.send(:level_index)
110
- end
102
+ context "Ruby Logger" do
103
+ # Ensure that any log level can be logged
104
+ Logger::Severity.constants.each do |level|
105
+ should "log Ruby logger #{level} info" do
106
+ @logger.level = Logger::Severity.const_get(level)
107
+ if level.to_s == 'UNKNOWN'
108
+ assert_equal Logger::Severity.const_get('ERROR')+1, @logger.send(:level_index)
109
+ else
110
+ assert_equal Logger::Severity.const_get(level)+1, @logger.send(:level_index)
111
111
  end
112
112
  end
113
113
  end
114
+ end
114
115
 
115
- context "benchmark" do
116
- # Ensure that any log level can be benchmarked and logged
117
- SemanticLogger::LEVELS.each do |level|
118
- level_char = level.to_s.upcase[0]
116
+ context "benchmark" do
117
+ # Ensure that any log level can be benchmarked and logged
118
+ SemanticLogger::LEVELS.each do |level|
119
+ level_char = level.to_s.upcase[0]
119
120
 
120
- context 'direct method' do
121
- should "log #{level} info" do
122
- assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world') { "result" } # Measure duration of the supplied block
123
- SemanticLogger.flush
124
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
125
- end
121
+ context 'direct method' do
122
+ should "log #{level} info" do
123
+ assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world') { "result" } # Measure duration of the supplied block
124
+ SemanticLogger.flush
125
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
126
+ end
126
127
 
127
- should "log #{level} info with payload" do
128
- assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', payload: @hash) { "result" } # Measure duration of the supplied block
129
- SemanticLogger.flush
130
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
131
- end
128
+ should "log #{level} info with payload" do
129
+ assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', payload: @hash) { "result" } # Measure duration of the supplied block
130
+ SemanticLogger.flush
131
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
132
+ end
132
133
 
133
- should "not log #{level} info when block is faster than :min_duration" do
134
- assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', :min_duration => 500) { "result" } # Measure duration of the supplied block
135
- SemanticLogger.flush
136
- assert_nil @mock_logger.message
137
- end
134
+ should "not log #{level} info when block is faster than :min_duration" do
135
+ assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', :min_duration => 500) { "result" } # Measure duration of the supplied block
136
+ SemanticLogger.flush
137
+ assert_nil @mock_logger.message
138
+ end
138
139
 
139
- should "log #{level} info when block duration exceeds :min_duration" do
140
- assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', :min_duration => 200, payload: @hash) { sleep 0.5; "result" } # Measure duration of the supplied block
141
- SemanticLogger.flush
142
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
143
- end
140
+ should "log #{level} info when block duration exceeds :min_duration" do
141
+ assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', :min_duration => 200, payload: @hash) { sleep 0.5; "result" } # Measure duration of the supplied block
142
+ SemanticLogger.flush
143
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
144
+ end
144
145
 
145
- should "log #{level} info with an exception" do
146
- assert_raises RuntimeError do
147
- @logger.send("benchmark_#{level}", 'hello world', payload: @hash) { raise RuntimeError.new("Test") } # Measure duration of the supplied block
148
- end
149
- SemanticLogger.flush
150
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message
146
+ should "log #{level} info with an exception" do
147
+ assert_raises RuntimeError do
148
+ @logger.send("benchmark_#{level}", 'hello world', payload: @hash) { raise RuntimeError.new("Test") } # Measure duration of the supplied block
151
149
  end
150
+ SemanticLogger.flush
151
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message
152
+ end
152
153
 
153
- should "change log #{level} info with an exception" do
154
- assert_raises RuntimeError do
155
- @logger.send("benchmark_#{level}", 'hello world', payload: @hash, on_exception_level: :fatal) { raise RuntimeError.new("Test") } # Measure duration of the supplied block
156
- end
157
- SemanticLogger.flush
158
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ F \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message
154
+ should "change log #{level} info with an exception" do
155
+ assert_raises RuntimeError do
156
+ @logger.send("benchmark_#{level}", 'hello world', payload: @hash, on_exception_level: :fatal) { raise RuntimeError.new("Test") } # Measure duration of the supplied block
159
157
  end
158
+ SemanticLogger.flush
159
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ F \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message
160
+ end
160
161
 
161
- should "log #{level} info with metric" do
162
- metric_name = '/my/custom/metric'
163
- assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', :metric => metric_name) { "result" } # Measure duration of the supplied block
164
- SemanticLogger.flush
165
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
166
- assert metric_name, $last_metric.metric
167
- end
162
+ should "log #{level} info with metric" do
163
+ metric_name = '/my/custom/metric'
164
+ assert_equal "result", @logger.send("benchmark_#{level}".to_sym, 'hello world', :metric => metric_name) { "result" } # Measure duration of the supplied block
165
+ SemanticLogger.flush
166
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
167
+ assert metric_name, $last_metric.metric
168
168
  end
169
+ end
169
170
 
170
- context 'generic method' do
171
- should "log #{level} info" do
172
- assert_equal "result", @logger.benchmark(level, 'hello world') { "result" } # Measure duration of the supplied block
173
- SemanticLogger.flush
174
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
175
- end
171
+ context 'generic method' do
172
+ should "log #{level} info" do
173
+ assert_equal "result", @logger.benchmark(level, 'hello world') { "result" } # Measure duration of the supplied block
174
+ SemanticLogger.flush
175
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
176
+ end
176
177
 
177
- should "log #{level} info with payload" do
178
- assert_equal "result", @logger.benchmark(level, 'hello world', payload: @hash) { "result" } # Measure duration of the supplied block
179
- SemanticLogger.flush
180
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
181
- end
178
+ should "log #{level} info with payload" do
179
+ assert_equal "result", @logger.benchmark(level, 'hello world', payload: @hash) { "result" } # Measure duration of the supplied block
180
+ SemanticLogger.flush
181
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
182
+ end
182
183
 
183
- should "not log #{level} info when block is faster than :min_duration" do
184
- assert_equal "result", @logger.benchmark(level, 'hello world', :min_duration => 500) { "result" } # Measure duration of the supplied block
185
- SemanticLogger.flush
186
- assert_nil @mock_logger.message
187
- end
184
+ should "not log #{level} info when block is faster than :min_duration" do
185
+ assert_equal "result", @logger.benchmark(level, 'hello world', :min_duration => 500) { "result" } # Measure duration of the supplied block
186
+ SemanticLogger.flush
187
+ assert_nil @mock_logger.message
188
+ end
188
189
 
189
- should "log #{level} info when block duration exceeds :min_duration" do
190
- assert_equal "result", @logger.benchmark(level, 'hello world', :min_duration => 200, payload: @hash) { sleep 0.5; "result" } # Measure duration of the supplied block
191
- SemanticLogger.flush
192
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
193
- end
190
+ should "log #{level} info when block duration exceeds :min_duration" do
191
+ assert_equal "result", @logger.benchmark(level, 'hello world', :min_duration => 200, payload: @hash) { sleep 0.5; "result" } # Measure duration of the supplied block
192
+ SemanticLogger.flush
193
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
194
+ end
194
195
 
195
- should "log #{level} info with an exception" do
196
- assert_raises RuntimeError do
197
- @logger.benchmark(level, 'hello world', payload: @hash) { raise RuntimeError.new("Test") } # Measure duration of the supplied block
198
- end
199
- SemanticLogger.flush
200
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message
196
+ should "log #{level} info with an exception" do
197
+ assert_raises RuntimeError do
198
+ @logger.benchmark(level, 'hello world', payload: @hash) { raise RuntimeError.new("Test") } # Measure duration of the supplied block
201
199
  end
200
+ SemanticLogger.flush
201
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- Exception: RuntimeError: Test -- #{@hash_str}/, @mock_logger.message
202
+ end
202
203
 
203
- should "log #{level} info with metric" do
204
- metric_name = '/my/custom/metric'
205
- assert_equal "result", @logger.benchmark(level, 'hello world', :metric => metric_name) { "result" } # Measure duration of the supplied block
206
- SemanticLogger.flush
207
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
208
- assert metric_name, $last_metric.metric
209
- end
204
+ should "log #{level} info with metric" do
205
+ metric_name = '/my/custom/metric'
206
+ assert_equal "result", @logger.benchmark(level, 'hello world', :metric => metric_name) { "result" } # Measure duration of the supplied block
207
+ SemanticLogger.flush
208
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world/, @mock_logger.message
209
+ assert metric_name, $last_metric.metric
210
210
  end
211
211
  end
212
+ end
212
213
 
213
- should "log when the block performs a return" do
214
- assert_equal "Good", function_with_return(@logger)
215
- SemanticLogger.flush
216
- assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
217
- end
214
+ should "log when the block performs a return" do
215
+ assert_equal "Good", function_with_return(@logger)
216
+ SemanticLogger.flush
217
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:.+\] \(\d+\.\dms\) LoggerTest -- hello world -- #{@hash_str}/, @mock_logger.message
218
+ end
219
+ end
220
+
221
+ context '.default_level' do
222
+ setup do
223
+ SemanticLogger.default_level = :debug
224
+ end
225
+
226
+ should 'not log at a level below the global default' do
227
+ assert_equal :debug, @logger.level
228
+ @logger.trace('hello world', @hash) { "Calculations" }
229
+ SemanticLogger.flush
230
+ assert_nil @mock_logger.message
231
+ end
232
+
233
+ should 'log at the instance level' do
234
+ @logger.level = :trace
235
+ assert_equal :trace, @logger.level
236
+ @logger.trace('hello world', @hash) { "Calculations" }
237
+ SemanticLogger.flush
238
+ assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ T \[\d+:.+\] LoggerTest -- hello world -- Calculations -- #{@hash_str}/, @mock_logger.message
239
+ end
240
+
241
+ should 'not log at a level below the instance level' do
242
+ @logger.level = :warn
243
+ assert_equal :warn, @logger.level
244
+ @logger.debug('hello world', @hash) { "Calculations" }
245
+ SemanticLogger.flush
246
+ assert_nil @mock_logger.message
247
+ end
248
+ end
249
+
250
+ context '.level?' do
251
+ should 'return true for debug? with :trace level' do
252
+ SemanticLogger.default_level = :trace
253
+ assert_equal :trace, @logger.level
254
+ assert_equal true, @logger.debug?
255
+ assert_equal true, @logger.trace?
256
+ end
257
+
258
+ should 'return false for debug? with global :debug level' do
259
+ SemanticLogger.default_level = :debug
260
+ assert_equal :debug, @logger.level, @logger.inspect
261
+ assert_equal true, @logger.debug?, @logger.inspect
262
+ assert_equal false, @logger.trace?, @logger.inspect
263
+ end
264
+
265
+ should 'return true for debug? with global :info level' do
266
+ SemanticLogger.default_level = :info
267
+ assert_equal :info, @logger.level, @logger.inspect
268
+ assert_equal false, @logger.debug?, @logger.inspect
269
+ assert_equal false, @logger.trace?, @logger.inspect
270
+ end
271
+
272
+ should 'return false for debug? with instance :debug level' do
273
+ @logger.level = :debug
274
+ assert_equal :debug, @logger.level, @logger.inspect
275
+ assert_equal true, @logger.debug?, @logger.inspect
276
+ assert_equal false, @logger.trace?, @logger.inspect
277
+ end
278
+
279
+ should 'return true for debug? with instance :info level' do
280
+ @logger.level = :info
281
+ assert_equal :info, @logger.level, @logger.inspect
282
+ assert_equal false, @logger.debug?, @logger.inspect
283
+ assert_equal false, @logger.trace?, @logger.inspect
218
284
  end
219
285
  end
286
+
220
287
  end
221
288
  end
289
+
222
290
  end
223
291
 
224
292
  # Make sure that benchmark still logs when a block uses return to return from
data/test/test_helper.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # Allow test to be run in-place without requiring a gem install
2
2
  $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
3
 
4
- #require 'rubygems'
4
+ # Configure Rails Environment
5
+ ENV['RAILS_ENV'] = 'test'
6
+
5
7
  require 'minitest/autorun'
6
8
  require 'minitest/reporters'
7
9
  require 'minitest/stub_any_instance'
@@ -10,4 +12,4 @@ require 'semantic_logger'
10
12
  require 'logger'
11
13
  require 'mock_logger'
12
14
 
13
- Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
15
+ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantic_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.0
4
+ version: 2.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-02 00:00:00.000000000 Z
11
+ date: 2015-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sync_attr
@@ -59,6 +59,7 @@ files:
59
59
  - lib/semantic_logger/appender/wrapper.rb
60
60
  - lib/semantic_logger/base.rb
61
61
  - lib/semantic_logger/core_ext/thread.rb
62
+ - lib/semantic_logger/debug_as_trace_logger.rb
62
63
  - lib/semantic_logger/loggable.rb
63
64
  - lib/semantic_logger/logger.rb
64
65
  - lib/semantic_logger/semantic_logger.rb
@@ -69,6 +70,7 @@ files:
69
70
  - test/appender_splunk_test.rb
70
71
  - test/appender_syslog_test.rb
71
72
  - test/appender_wrapper_test.rb
73
+ - test/debug_as_trace_logger_test.rb
72
74
  - test/loggable_test.rb
73
75
  - test/logger_test.rb
74
76
  - test/mock_logger.rb
@@ -105,6 +107,7 @@ test_files:
105
107
  - test/appender_splunk_test.rb
106
108
  - test/appender_syslog_test.rb
107
109
  - test/appender_wrapper_test.rb
110
+ - test/debug_as_trace_logger_test.rb
108
111
  - test/loggable_test.rb
109
112
  - test/logger_test.rb
110
113
  - test/mock_logger.rb