catamaran 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -135,41 +135,15 @@ module Catamaran
135
135
 
136
136
 
137
137
 
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
138
  ##
160
139
  # Is trace-level logging currently enabled?
161
140
 
162
141
  def trace?
163
- if self.log_level( { :be_populated => true } ) <= LogLevel::TRACE
164
- true
165
- else
166
- false
167
- end
142
+ default_trace?
168
143
  end
169
144
 
170
145
  def trace( msg, opts = nil )
171
- # Duplicated the logic from trace?() (rather than calling it directly) for performance considerations
172
- if self.log_level( { :be_populated => true } ) <= LogLevel::TRACE
146
+ if trace?
173
147
  log( LogLevel::TRACE, msg, opts )
174
148
  end
175
149
  end
@@ -178,16 +152,11 @@ module Catamaran
178
152
  # Is debug-level logging currently enabled?
179
153
 
180
154
  def debug?
181
- if self.log_level( { :be_populated => true } ) <= LogLevel::DEBUG
182
- true
183
- else
184
- false
185
- end
155
+ default_debug?
186
156
  end
187
157
 
188
158
  def debug( msg, opts = nil )
189
- # Duplicated the logic from debug?() (rather than calling it directly) for performance considerations
190
- if self.log_level( { :be_populated => true } ) <= LogLevel::DEBUG
159
+ if debug?
191
160
  log( LogLevel::DEBUG, msg, opts )
192
161
  end
193
162
  end
@@ -197,16 +166,11 @@ module Catamaran
197
166
  # Is io-level logging currently enabled?
198
167
 
199
168
  def io?
200
- if self.log_level( { :be_populated => true } ) <= LogLevel::IO
201
- true
202
- else
203
- false
204
- end
169
+ default_io?
205
170
  end
206
171
 
207
172
  def io( msg, opts = nil )
208
- # Duplicated the logic from io?() (rather than calling it directly) for performance considerations
209
- if self.log_level( { :be_populated => true } ) <= LogLevel::IO
173
+ if io?
210
174
  log( LogLevel::IO, msg, opts )
211
175
  end
212
176
  end
@@ -215,16 +179,11 @@ module Catamaran
215
179
  # Is info-level logging currently enabled?
216
180
 
217
181
  def info?
218
- if self.log_level( { :be_populated => true } ) <= LogLevel::INFO
219
- true
220
- else
221
- false
222
- end
182
+ default_info?
223
183
  end
224
184
 
225
185
  def info( msg, opts = nil )
226
- # Duplicated the logic from info?() (rather than calling it directly) for performance considerations
227
- if self.log_level( { :be_populated => true } ) <= LogLevel::INFO
186
+ if info?
228
187
  log( LogLevel::INFO, msg, opts )
229
188
  end
230
189
  end
@@ -233,16 +192,11 @@ module Catamaran
233
192
  # Is notice-level logging currently enabled?
234
193
 
235
194
  def notice?
236
- if self.log_level( { :be_populated => true } ) <= LogLevel::NOTICE
237
- true
238
- else
239
- false
240
- end
195
+ default_notice?
241
196
  end
242
197
 
243
198
  def notice( msg, opts = nil )
244
- # Duplicated the logic from notice?() (rather than calling it directly) for performance considerations
245
- if self.log_level( { :be_populated => true } ) <= LogLevel::NOTICE
199
+ if notice?
246
200
  log( LogLevel::NOTICE, msg, opts )
247
201
  end
248
202
  end
@@ -251,16 +205,11 @@ module Catamaran
251
205
  # Is warn-level logging currently enabled?
252
206
 
253
207
  def warn?
254
- if self.log_level( { :be_populated => true } ) <= LogLevel::WARN
255
- true
256
- else
257
- false
258
- end
208
+ default_warn?
259
209
  end
260
210
 
261
211
  def warn( msg, opts = nil )
262
- # Duplicated the logic from warn?() (rather than calling it directly) for performance considerations
263
- if self.log_level( { :be_populated => true } ) <= LogLevel::WARN
212
+ if warn?
264
213
  log( LogLevel::WARN, msg, opts )
265
214
  end
266
215
  end
@@ -269,16 +218,11 @@ module Catamaran
269
218
  # Is error-level logging currently enabled?
270
219
 
271
220
  def error?
272
- if self.log_level( { :be_populated => true } ) <= LogLevel::ERROR
273
- true
274
- else
275
- false
276
- end
221
+ default_error?
277
222
  end
278
223
 
279
224
  def error( msg, opts = nil )
280
- # Duplicated the logic from error?() (rather than calling it directly) for performance considerations
281
- if self.log_level( { :be_populated => true } ) <= LogLevel::ERROR
225
+ if error?
282
226
  log( LogLevel::ERROR, msg, opts )
283
227
  end
284
228
  end
@@ -287,16 +231,11 @@ module Catamaran
287
231
  # Is severe-level logging currently enabled?
288
232
 
289
233
  def severe?
290
- if self.log_level( { :be_populated => true } ) <= LogLevel::SEVERE
291
- true
292
- else
293
- false
294
- end
234
+ default_severe?
295
235
  end
296
236
 
297
237
  def severe( msg, opts = nil )
298
- # Duplicated the logic from severe?() (rather than calling it directly) for performance considerations
299
- if self.log_level( { :be_populated => true } ) <= LogLevel::SEVERE
238
+ if severe?
300
239
  log( LogLevel::SEVERE, msg, opts )
301
240
  end
302
241
  end
@@ -305,16 +244,11 @@ module Catamaran
305
244
  # Is fatal-level logging currently enabled?
306
245
 
307
246
  def fatal?
308
- if self.smart_log_level() <= LogLevel::FATAL
309
- true
310
- else
311
- false
312
- end
247
+ default_fatal?
313
248
  end
314
249
 
315
250
  def fatal( msg, opts = nil )
316
- # Duplicated the logic from fatal?() (rather than calling it directly) for performance considerations
317
- if self.log_level( { :be_populated => true } ) <= LogLevel::FATAL
251
+ if fatal?
318
252
  log( LogLevel::FATAL, msg, opts )
319
253
  end
320
254
  end
@@ -416,11 +350,26 @@ module Catamaran
416
350
  @memoized_backtrace_log_level = nil
417
351
  @memoized_delimiter = nil
418
352
 
353
+ # This is arguably a form of memoization
354
+ define_all_logging_conditional_defaults()
355
+
419
356
  @sub_loggers.values.each do |logger|
420
357
  logger.forget_memoizations()
421
358
  end
422
359
  end
423
360
 
361
+ def define_all_logging_conditional_defaults
362
+ [ :io, :trace, :debug, :info, :notice, :warn, :error, :severe, :fatal ].each do |log_level_as_symbol|
363
+ define_default_logging_conditional( log_level_as_symbol )
364
+ end
365
+ end
366
+
367
+ def define_default_logging_conditional( log_level_as_symbol )
368
+ singleton = class << self; self end
369
+ singleton.send( :define_method, "#{log_level_as_symbol}?".to_sym ) do
370
+ send( "default_#{log_level_as_symbol}?".to_sym )
371
+ end
372
+ end
424
373
 
425
374
  ##
426
375
  # Number of loggers known about by this logger (including sub-loggers)
@@ -444,12 +393,10 @@ module Catamaran
444
393
  # Unless otherwise specified, a reset() is a soft reset by default.
445
394
 
446
395
  def reset( opts = {} )
447
-
448
- @memoized_log_level = nil
449
396
  @log_level = nil
450
397
  @backtrace_log_level = nil
451
- @memoized_backtrace_log_level = nil
452
- @memoized_delimiter = nil
398
+
399
+ forget_memoizations()
453
400
 
454
401
  self.name = @initialized_name
455
402
  self.path = @initialized_path_so_far ? @initialized_path_so_far.dup : []
@@ -513,6 +460,169 @@ module Catamaran
513
460
 
514
461
  protected
515
462
 
463
+ def default_trace?
464
+ if self.log_level( { :be_populated => true } ) <= LogLevel::TRACE
465
+ singleton = class << self; self end
466
+ singleton.send( :define_method, :trace? ) do
467
+ true
468
+ end
469
+
470
+ true
471
+ else
472
+ singleton = class << self; self end
473
+ singleton.send( :define_method, :trace? ) do
474
+ false
475
+ end
476
+
477
+ false
478
+ end
479
+ end
480
+
481
+ def default_debug?
482
+ if self.log_level( { :be_populated => true } ) <= LogLevel::DEBUG
483
+ singleton = class << self; self end
484
+ singleton.send( :define_method, :debug? ) do
485
+ true
486
+ end
487
+
488
+ true
489
+ else
490
+ singleton = class << self; self end
491
+ singleton.send( :define_method, :debug? ) do
492
+ false
493
+ end
494
+
495
+ false
496
+ end
497
+ end
498
+
499
+ def default_io?
500
+ if self.log_level( { :be_populated => true } ) <= LogLevel::IO
501
+ singleton = class << self; self end
502
+ singleton.send( :define_method, :io? ) do
503
+ true
504
+ end
505
+
506
+ true
507
+ else
508
+ singleton = class << self; self end
509
+ singleton.send( :define_method, :io? ) do
510
+ false
511
+ end
512
+
513
+ false
514
+ end
515
+ end
516
+
517
+ def default_info?
518
+ if self.log_level( { :be_populated => true } ) <= LogLevel::INFO
519
+ singleton = class << self; self end
520
+ singleton.send( :define_method, :info? ) do
521
+ true
522
+ end
523
+
524
+ true
525
+ else
526
+ singleton = class << self; self end
527
+ singleton.send( :define_method, :info? ) do
528
+ false
529
+ end
530
+
531
+ false
532
+ end
533
+ end
534
+
535
+ def default_notice?
536
+ if self.log_level( { :be_populated => true } ) <= LogLevel::NOTICE
537
+ singleton = class << self; self end
538
+ singleton.send( :define_method, :notice? ) do
539
+ true
540
+ end
541
+
542
+ true
543
+ else
544
+ singleton = class << self; self end
545
+ singleton.send( :define_method, :notice? ) do
546
+ false
547
+ end
548
+
549
+ false
550
+ end
551
+ end
552
+
553
+ def default_warn?
554
+ if self.log_level( { :be_populated => true } ) <= LogLevel::WARN
555
+ singleton = class << self; self end
556
+ singleton.send( :define_method, :warn? ) do
557
+ true
558
+ end
559
+
560
+ true
561
+ else
562
+ singleton = class << self; self end
563
+ singleton.send( :define_method, :warn? ) do
564
+ false
565
+ end
566
+
567
+ false
568
+ end
569
+ end
570
+
571
+ def default_error?
572
+ if self.log_level( { :be_populated => true } ) <= LogLevel::ERROR
573
+ singleton = class << self; self end
574
+ singleton.send( :define_method, :error? ) do
575
+ true
576
+ end
577
+
578
+ true
579
+ else
580
+ singleton = class << self; self end
581
+ singleton.send( :define_method, :error? ) do
582
+ false
583
+ end
584
+
585
+ false
586
+ end
587
+ end
588
+
589
+ def default_severe?
590
+ if self.log_level( { :be_populated => true } ) <= LogLevel::SEVERE
591
+ singleton = class << self; self end
592
+ singleton.send( :define_method, :severe? ) do
593
+ true
594
+ end
595
+
596
+ true
597
+ else
598
+ singleton = class << self; self end
599
+ singleton.send( :define_method, :severe? ) do
600
+ false
601
+ end
602
+
603
+ false
604
+ end
605
+ end
606
+
607
+ def default_fatal?
608
+ if self.log_level( { :be_populated => true } ) <= LogLevel::FATAL
609
+ singleton = class << self; self end
610
+ singleton.send( :define_method, :fatal? ) do
611
+ true
612
+ end
613
+
614
+ true
615
+ else
616
+ singleton = class << self; self end
617
+ singleton.send( :define_method, :fatal? ) do
618
+ false
619
+ end
620
+
621
+ false
622
+ end
623
+ end
624
+
625
+
516
626
  def determine_path_and_opts_arguments( *args )
517
627
  Catamaran.debugging( "Catamaran::Logger#reset() - Entering with args = #{args}" ) if Catamaran.debugging?
518
628
 
@@ -1,4 +1,4 @@
1
1
  module Catamaran
2
- VERSION = '2.2.0'
2
+ VERSION = '2.3.0'
3
3
  end
4
4
 
@@ -373,6 +373,39 @@ describe Catamaran do
373
373
  Catamaran.logger.trace?.should be_true
374
374
  end
375
375
 
376
+ it "should support the INFO log severity and info()" do
377
+ Catamaran.logger.log_level = Catamaran::LogLevel::INFO
378
+ Catamaran.logger.should_receive( :log ).once
379
+ Catamaran.logger.info( "A INFO log should be received" )
380
+ end
381
+
382
+ it "should support the INFO log severity and info?()" do
383
+ Catamaran.logger.log_level = Catamaran::LogLevel::INFO
384
+ Catamaran.logger.info?.should be_true
385
+ end
386
+
387
+ it "should support the NOTICE log severity and notice()" do
388
+ Catamaran.logger.log_level = Catamaran::LogLevel::NOTICE
389
+ Catamaran.logger.should_receive( :log ).once
390
+ Catamaran.logger.notice( "A NOTICE log should be received" )
391
+ end
392
+
393
+ it "should support the NOTICE log severity and notice?()" do
394
+ Catamaran.logger.log_level = Catamaran::LogLevel::NOTICE
395
+ Catamaran.logger.notice?.should be_true
396
+ end
397
+
398
+ it "should support the SEVERE log severity and severe()" do
399
+ Catamaran.logger.smart_log_level.should < Catamaran::LogLevel::SEVERE
400
+ Catamaran.logger.should_receive( :log ).once
401
+ Catamaran.logger.severe( "A SEVERE log should be received" )
402
+ end
403
+
404
+ it "should support the SEVERE log severity and severe?()" do
405
+ Catamaran.logger.smart_log_level.should < Catamaran::LogLevel::SEVERE
406
+ Catamaran.logger.severe?.should be_true
407
+ end
408
+
376
409
  it "should support the FATAL log severity and fatal()" do
377
410
  Catamaran.logger.smart_log_level.should < Catamaran::LogLevel::FATAL
378
411
  Catamaran.logger.should_receive( :log ).once
@@ -434,6 +467,26 @@ describe Catamaran do
434
467
  end
435
468
  end
436
469
 
470
+ describe "#debug?" do
471
+ it "should call default_debug? the first time" do
472
+ Catamaran.logger.should_receive( :default_debug? ).once
473
+ Catamaran.logger.debug?
474
+ end
475
+
476
+ it "should only call default_debug? once" do
477
+ Catamaran.logger.debug?
478
+ Catamaran.logger.should_not_receive( :default_debug? )
479
+ Catamaran.logger.debug?
480
+ end
481
+
482
+ it "should call default_debug? again after the memoizations have " do
483
+ Catamaran.logger.debug?
484
+ Catamaran::Manager.forget_memoizations()
485
+ Catamaran.logger.should_receive( :default_debug? ).once
486
+ Catamaran.logger.debug?
487
+ end
488
+ end
489
+
437
490
  it "should inherit the log level (via smart_log_level) from it's ancestors" do
438
491
  Catamaran.logger.log_level = Catamaran::LogLevel::INFO
439
492
  Catamaran.logger.com.mycompany.myrailsproject.app.models.log_level = Catamaran::LogLevel::ERROR
metadata CHANGED
@@ -1,28 +1,22 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: catamaran
3
- version: !ruby/object:Gem::Version
4
- version: 2.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.3.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Jeano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2014-01-08 00:00:00 -06:00
13
- default_executable:
11
+ date: 2014-01-09 00:00:00.000000000 Z
14
12
  dependencies: []
15
-
16
13
  description: A logging utility
17
- email:
14
+ email:
18
15
  - catamaran@jeano.net
19
16
  executables: []
20
-
21
17
  extensions: []
22
-
23
18
  extra_rdoc_files: []
24
-
25
- files:
19
+ files:
26
20
  - .gitignore
27
21
  - LICENSE
28
22
  - README.md
@@ -30,6 +24,7 @@ files:
30
24
  - examples/benchmarking_conditional_log_statements.rb
31
25
  - examples/benchmarking_the_caller.rb
32
26
  - examples/quickstart_with_ruby.rb
27
+ - examples/simple_benchmark.rb
33
28
  - examples/with_double_colon_delimiter.rb
34
29
  - examples/with_the_ruby_profiler.rb
35
30
  - init.rb
@@ -50,33 +45,28 @@ files:
50
45
  - lib/generators/catamaran/templates/catamaran/test.rb
51
46
  - spec/catamaran_spec.rb
52
47
  - spec/spec_helper.rb
53
- has_rdoc: true
54
48
  homepage: http://github.com/jgithub/catamaran
55
- licenses:
49
+ licenses:
56
50
  - MIT
51
+ metadata: {}
57
52
  post_install_message:
58
53
  rdoc_options: []
59
-
60
- require_paths:
54
+ require_paths:
61
55
  - lib
62
- required_ruby_version: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: "0"
67
- version:
68
- required_rubygems_version: !ruby/object:Gem::Requirement
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: "0"
73
- version:
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
74
66
  requirements: []
75
-
76
67
  rubyforge_project:
77
- rubygems_version: 1.3.5
68
+ rubygems_version: 2.0.3
78
69
  signing_key:
79
- specification_version: 3
70
+ specification_version: 4
80
71
  summary: Catamaran Logger
81
72
  test_files: []
82
-