catamaran 0.10.0 → 0.11.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de217e176b2cb0c6ac1dc6e0b99b4bb2297383ea
4
- data.tar.gz: d062ac5460294965d8ced97e2431d8c24f039b07
3
+ metadata.gz: 993f73e0ae0754e71b927dd3f0ad660e9ebb2c7c
4
+ data.tar.gz: fae6d060490c7c3d492ef39f0b505d4e7da827e3
5
5
  SHA512:
6
- metadata.gz: cb3e3f5099b0e621064b25d2a55365d3c48557fd991bc11989ea61c0242784825e80c487425cb9fb176fd02c10f294689bfad561918079b760278d33c62bef70
7
- data.tar.gz: b975c7e774b21315aa50ea6ff8a1245db8b6df63da987aabe40c7b38dd7ee7cbbd1386a3534a27bdee12b910ca10b5ac47891bc3c69df1d419200941f1f06406
6
+ metadata.gz: 471327f5ea17493c978f516eafb5ae2ddc153584a18aab2d3d6d6ed1f447eff12723ce7ce8cc3e91d75cc87c579c086e5e4180e34c428c720c5bfb785f17ceb5
7
+ data.tar.gz: 568cbd354d876a26053b94ea9f484f8749ef14316ec23e9f631a7cf8f07d5bf4b6a8bb598f8b5bca6ed2fc8c67f9ef684cb2e248c097c58cb8f4a9fc09bfa0e1
data/README.md CHANGED
@@ -6,7 +6,7 @@ Logging is a powerful and often undervalued tool in software development. When
6
6
  Gemfile
7
7
  -------
8
8
 
9
- gem 'catamaran', '~> 0.10.0'
9
+ gem 'catamaran', '~> 0.11.0'
10
10
 
11
11
  Rails-related setup:
12
12
 
@@ -74,7 +74,7 @@ Load the `index` page and check out your `development.log` file
74
74
 
75
75
  Log Levels
76
76
  ----------
77
- Available log levels: `TRACE` (verbose and trivial log messages), `DEBUG`, `INFO`, `NOTICE`, `WARN`, `ERROR`, `SEVERE` (logs related to very serious error conditions)
77
+ Available log levels: `TRACE` (verbose and trivial log messages), `DEBUG`, `INFO`, `NOTICE`, `WARN`, `ERROR`, `SEVERE` (logs related to very serious error conditions), `FATAL`
78
78
 
79
79
  The `NOTICE` log level severity is the default. Any logs with `NOTICE` or higher severity will be captured.
80
80
 
@@ -206,7 +206,7 @@ LOGGER.debug "This is a DEBUG log" if LOGGER.debug?
206
206
  LOGGER.info "This is a INFO log" if LOGGER.info?
207
207
  ```
208
208
 
209
- * For log messages that are usually *enabled* in the production environment ( NOTICE, WARN, ERROR, SEVERE ), it's generally better to invoke the log WITHOUT first testing the log level
209
+ * For log messages that are usually *enabled* in the production environment ( NOTICE, WARN, ERROR, SEVERE, FATAL ), it's generally better to invoke the log WITHOUT first testing the log level
210
210
 
211
211
  ex:
212
212
 
@@ -215,6 +215,7 @@ LOGGER.notice "This is a NOTICE log"
215
215
  LOGGER.warn "This is a WARN log"
216
216
  LOGGER.error "This is a ERROR log"
217
217
  LOGGER.severe "This is a SEVERE log"
218
+ LOGGER.severe "This is a FATAL log"
218
219
  ```
219
220
 
220
221
  ### NoCallerFormatter vs CallerFormatter
@@ -268,6 +269,247 @@ end
268
269
 
269
270
  Because of this performance difference, `NoCallerFormatter` is the Catamaran default. Though `CallerFormatter` tends to be especially useful in the development and test environments when debugging problems during the course of functional testing.
270
271
 
272
+ ### Ruby Profiler
273
+ ```ruby
274
+ require 'catamaran'
275
+ require 'ruby-prof'
276
+
277
+
278
+ class FirstRubyDemo
279
+ LOGGER = Catamaran.logger( "com.mycompany.FirstRubyDemo" )
280
+ # or equivalently:
281
+ # LOGGER = Catamaran.logger.com.mycompany.FirstRubyDemo
282
+
283
+ def run
284
+ # Disabled by default
285
+ LOGGER.trace( "TRACE logs are NOT captured by default" ) if LOGGER.trace?
286
+ LOGGER.debug( "DEBUG logs are NOT captured by default" ) if LOGGER.debug?
287
+ LOGGER.info( "INFO logs are NOT captured by default" ) if LOGGER.info?
288
+
289
+ # Enabled by default
290
+ LOGGER.notice( "NOTICE logs are captured by default" )
291
+ LOGGER.warn( "WARN logs are captured by default" )
292
+ LOGGER.error( "ERROR logs are captured by default" )
293
+ LOGGER.severe( "SEVERE logs are captured by default" )
294
+ LOGGER.fatal( "FATAL logs are captured by default" )
295
+ end
296
+ end
297
+
298
+
299
+ RubyProf.start
300
+
301
+ demo = FirstRubyDemo.new
302
+ 1000.times do
303
+ demo.run
304
+ end
305
+
306
+ result = RubyProf.stop
307
+
308
+ printer = RubyProf::GraphPrinter.new(result)
309
+
310
+ printer.print(STDOUT)
311
+ ```
312
+
313
+ #### Summary
314
+
315
+ ```
316
+ Thread ID: 2156341060
317
+ Fiber ID: 2164637460
318
+ Total Time: 0.8493040000000001
319
+ Sort by: total_time
320
+
321
+ %total %self total self wait child calls Name
322
+ --------------------------------------------------------------------------------
323
+ 100.00% 0.00% 0.849 0.000 0.000 0.849 1 Global#[No method]
324
+ 0.849 0.003 0.000 0.846 1/1 Integer#times
325
+ 0.000 0.000 0.000 0.000 1/1 Class#new
326
+ --------------------------------------------------------------------------------
327
+ 0.849 0.003 0.000 0.846 1/1 Global#[No method]
328
+ 99.99% 0.38% 0.849 0.003 0.000 0.846 1 Integer#times
329
+ 0.846 0.023 0.000 0.823 1000/1000 FirstRubyDemo#run
330
+ --------------------------------------------------------------------------------
331
+ 0.846 0.023 0.000 0.823 1000/1000 Integer#times
332
+ 99.62% 2.72% 0.846 0.023 0.000 0.823 1000 FirstRubyDemo#run
333
+ 0.164 0.008 0.000 0.156 1000/1000 Catamaran::Logger#severe
334
+ 0.158 0.011 0.000 0.147 1000/1000 Catamaran::Logger#warn
335
+ 0.150 0.007 0.000 0.142 1000/1000 Catamaran::Logger#error
336
+ 0.149 0.008 0.000 0.141 1000/1000 Catamaran::Logger#fatal
337
+ 0.139 0.007 0.000 0.132 1000/1000 Catamaran::Logger#notice
338
+ 0.022 0.007 0.000 0.016 1000/1000 Catamaran::Logger#trace?
339
+ 0.021 0.006 0.000 0.016 1000/1000 Catamaran::Logger#debug?
340
+ 0.020 0.005 0.000 0.015 1000/1000 Catamaran::Logger#info?
341
+ --------------------------------------------------------------------------------
342
+ 0.118 0.006 0.000 0.112 1000/5000 Catamaran::Logger#notice
343
+ 0.126 0.007 0.000 0.119 1000/5000 Catamaran::Logger#fatal
344
+ 0.126 0.007 0.000 0.119 1000/5000 Catamaran::Logger#error
345
+ 0.131 0.007 0.000 0.125 1000/5000 Catamaran::Logger#warn
346
+ 0.140 0.007 0.000 0.134 1000/5000 Catamaran::Logger#severe
347
+ 75.52% 3.91% 0.641 0.033 0.000 0.608 5000 Catamaran::Logger#log
348
+ 0.438 0.028 0.000 0.409 5000/5000 Catamaran::Logger#_format_msg
349
+ 0.170 0.048 0.000 0.123 5000/5000 <Class::Catamaran::Outputter>#write
350
+ --------------------------------------------------------------------------------
351
+ 0.438 0.028 0.000 0.409 5000/5000 Catamaran::Logger#log
352
+ 51.55% 3.34% 0.438 0.028 0.000 0.409 5000 Catamaran::Logger#_format_msg
353
+ 0.339 0.040 0.000 0.299 5000/5000 <Class::Catamaran::Formatter::NoCallerFormatter>#construct_formatted_message
354
+ 0.053 0.033 0.000 0.021 5000/5000 Catamaran::Logger#path_to_s
355
+ 0.017 0.017 0.000 0.000 5000/5000 <Class::Catamaran::Manager>#formatter_class
356
+ --------------------------------------------------------------------------------
357
+ 0.339 0.040 0.000 0.299 5000/5000 Catamaran::Logger#_format_msg
358
+ 39.95% 4.71% 0.339 0.040 0.000 0.299 5000 <Class::Catamaran::Formatter::NoCallerFormatter>#construct_formatted_message
359
+ 0.261 0.077 0.000 0.184 5000/5000 <Class::Catamaran::Formatter::BaseFormatter>#base_construct_formatted_message
360
+ 0.021 0.021 0.000 0.000 5000/5000 <Class::Catamaran::Formatter::BaseFormatter>#contruct_suffix_info
361
+ 0.017 0.017 0.000 0.000 5000/5000 <Class::Catamaran::Formatter::BaseFormatter>#construct_backtrace_info
362
+ --------------------------------------------------------------------------------
363
+ 0.261 0.077 0.000 0.184 5000/5000 <Class::Catamaran::Formatter::NoCallerFormatter>#construct_formatted_message
364
+ 30.77% 9.07% 0.261 0.077 0.000 0.184 5000 <Class::Catamaran::Formatter::BaseFormatter>#base_construct_formatted_message
365
+ 0.085 0.060 0.000 0.024 5000/5000 Time#strftime
366
+ 0.039 0.019 0.000 0.020 5000/5000 <Class::Time>#now
367
+ 0.027 0.027 0.000 0.000 5000/5000 Kernel#sprintf
368
+ 0.014 0.014 0.000 0.000 5000/5000 <Class::Catamaran::LogLevel>#severity_to_s
369
+ 0.013 0.013 0.000 0.000 5000/5000 Fixnum#to_s
370
+ 0.007 0.007 0.000 0.000 5000/5000 <Module::Process>#pid
371
+ --------------------------------------------------------------------------------
372
+ 0.170 0.048 0.000 0.123 5000/5000 Catamaran::Logger#log
373
+ 20.05% 5.61% 0.170 0.048 0.000 0.123 5000 <Class::Catamaran::Outputter>#write
374
+ 0.089 0.020 0.000 0.069 5000/5000 IO#puts
375
+ 0.018 0.018 0.000 0.000 5000/5000 <Class::Catamaran::Manager>#stdout?
376
+ 0.015 0.015 0.000 0.000 5000/5000 <Class::Catamaran::Manager>#stderr?
377
+ --------------------------------------------------------------------------------
378
+ 0.164 0.008 0.000 0.156 1000/1000 FirstRubyDemo#run
379
+ 19.26% 0.90% 0.164 0.008 0.000 0.156 1000 Catamaran::Logger#severe
380
+ 0.140 0.007 0.000 0.134 1000/5000 Catamaran::Logger#log
381
+ 0.016 0.013 0.000 0.002 1000/8003 Catamaran::Logger#log_level
382
+ --------------------------------------------------------------------------------
383
+ 0.158 0.011 0.000 0.147 1000/1000 FirstRubyDemo#run
384
+ 18.60% 1.34% 0.158 0.011 0.000 0.147 1000 Catamaran::Logger#warn
385
+ 0.131 0.007 0.000 0.125 1000/5000 Catamaran::Logger#log
386
+ 0.015 0.013 0.000 0.002 1000/8003 Catamaran::Logger#log_level
387
+ --------------------------------------------------------------------------------
388
+ 0.150 0.007 0.000 0.142 1000/1000 FirstRubyDemo#run
389
+ 17.61% 0.88% 0.150 0.007 0.000 0.142 1000 Catamaran::Logger#error
390
+ 0.126 0.007 0.000 0.119 1000/5000 Catamaran::Logger#log
391
+ 0.016 0.013 0.000 0.002 1000/8003 Catamaran::Logger#log_level
392
+ --------------------------------------------------------------------------------
393
+ 0.149 0.008 0.000 0.141 1000/1000 FirstRubyDemo#run
394
+ 17.52% 0.89% 0.149 0.008 0.000 0.141 1000 Catamaran::Logger#fatal
395
+ 0.126 0.007 0.000 0.119 1000/5000 Catamaran::Logger#log
396
+ 0.016 0.013 0.000 0.002 1000/8003 Catamaran::Logger#log_level
397
+ --------------------------------------------------------------------------------
398
+ 0.139 0.007 0.000 0.132 1000/1000 FirstRubyDemo#run
399
+ 16.37% 0.77% 0.139 0.007 0.000 0.132 1000 Catamaran::Logger#notice
400
+ 0.118 0.006 0.000 0.112 1000/5000 Catamaran::Logger#log
401
+ 0.014 0.012 0.000 0.002 1000/8003 Catamaran::Logger#log_level
402
+ --------------------------------------------------------------------------------
403
+ 0.000 0.000 0.000 0.000 3/8003 Catamaran::Logger#log_level
404
+ 0.014 0.012 0.000 0.002 1000/8003 Catamaran::Logger#notice
405
+ 0.015 0.013 0.000 0.002 1000/8003 Catamaran::Logger#info?
406
+ 0.015 0.013 0.000 0.002 1000/8003 Catamaran::Logger#warn
407
+ 0.016 0.013 0.000 0.002 1000/8003 Catamaran::Logger#debug?
408
+ 0.016 0.013 0.000 0.002 1000/8003 Catamaran::Logger#severe
409
+ 0.016 0.013 0.000 0.002 1000/8003 Catamaran::Logger#fatal
410
+ 0.016 0.013 0.000 0.002 1000/8003 Catamaran::Logger#trace?
411
+ 0.016 0.013 0.000 0.002 1000/8003 Catamaran::Logger#error
412
+ 14.49% 12.32% 0.123 0.105 0.000 0.018 8003 *Catamaran::Logger#log_level
413
+ 0.018 0.018 0.000 0.000 16001/16001 Kernel#nil?
414
+ 0.000 0.000 0.000 0.000 4/4 NilClass#nil?
415
+ 0.000 0.000 0.000 0.000 3/8003 Catamaran::Logger#log_level
416
+ --------------------------------------------------------------------------------
417
+ 0.089 0.020 0.000 0.069 5000/5000 <Class::Catamaran::Outputter>#write
418
+ 10.48% 2.40% 0.089 0.020 0.000 0.069 5000 IO#puts
419
+ 0.069 0.069 0.000 0.000 10000/10000 IO#write
420
+ --------------------------------------------------------------------------------
421
+ 0.085 0.060 0.000 0.024 5000/5000 <Class::Catamaran::Formatter::BaseFormatter>#base_construct_formatted_message
422
+ 9.96% 7.09% 0.085 0.060 0.000 0.024 5000 Time#strftime
423
+ 0.018 0.018 0.000 0.000 10000/10000 Fixnum#divmod
424
+ 0.006 0.006 0.000 0.000 5000/5000 Fixnum#%
425
+ --------------------------------------------------------------------------------
426
+ 0.069 0.069 0.000 0.000 10000/10000 IO#puts
427
+ 8.08% 8.08% 0.069 0.069 0.000 0.000 10000 IO#write
428
+ --------------------------------------------------------------------------------
429
+ 0.053 0.033 0.000 0.021 5000/5000 Catamaran::Logger#_format_msg
430
+ 6.28% 3.85% 0.053 0.033 0.000 0.021 5000 Catamaran::Logger#path_to_s
431
+ 0.021 0.021 0.000 0.000 5000/5000 Array#join
432
+ 0.000 0.000 0.000 0.000 1/1 <Class::Catamaran::Manager>#delimiter
433
+ --------------------------------------------------------------------------------
434
+ 0.039 0.019 0.000 0.020 5000/5000 <Class::Catamaran::Formatter::BaseFormatter>#base_construct_formatted_message
435
+ 4.62% 2.29% 0.039 0.019 0.000 0.020 5000 <Class::Time>#now
436
+ 0.020 0.014 0.000 0.006 5000/5000 Time#initialize
437
+ --------------------------------------------------------------------------------
438
+ 0.027 0.027 0.000 0.000 5000/5000 <Class::Catamaran::Formatter::BaseFormatter>#base_construct_formatted_message
439
+ 3.21% 3.21% 0.027 0.027 0.000 0.000 5000 Kernel#sprintf
440
+ --------------------------------------------------------------------------------
441
+ 0.022 0.007 0.000 0.016 1000/1000 FirstRubyDemo#run
442
+ 2.63% 0.78% 0.022 0.007 0.000 0.016 1000 Catamaran::Logger#trace?
443
+ 0.016 0.013 0.000 0.002 1000/8003 Catamaran::Logger#log_level
444
+ --------------------------------------------------------------------------------
445
+ 0.021 0.006 0.000 0.016 1000/1000 FirstRubyDemo#run
446
+ 2.53% 0.70% 0.021 0.006 0.000 0.016 1000 Catamaran::Logger#debug?
447
+ 0.016 0.013 0.000 0.002 1000/8003 Catamaran::Logger#log_level
448
+ --------------------------------------------------------------------------------
449
+ 0.021 0.021 0.000 0.000 5000/5000 <Class::Catamaran::Formatter::NoCallerFormatter>#construct_formatted_message
450
+ 2.52% 2.52% 0.021 0.021 0.000 0.000 5000 <Class::Catamaran::Formatter::BaseFormatter>#contruct_suffix_info
451
+ --------------------------------------------------------------------------------
452
+ 0.021 0.021 0.000 0.000 5000/5000 Catamaran::Logger#path_to_s
453
+ 2.42% 2.42% 0.021 0.021 0.000 0.000 5000 Array#join
454
+ --------------------------------------------------------------------------------
455
+ 0.020 0.005 0.000 0.015 1000/1000 FirstRubyDemo#run
456
+ 2.38% 0.64% 0.020 0.005 0.000 0.015 1000 Catamaran::Logger#info?
457
+ 0.015 0.013 0.000 0.002 1000/8003 Catamaran::Logger#log_level
458
+ --------------------------------------------------------------------------------
459
+ 0.020 0.014 0.000 0.006 5000/5000 <Class::Time>#now
460
+ 2.33% 1.62% 0.020 0.014 0.000 0.006 5000 Time#initialize
461
+ 0.006 0.006 0.000 0.000 5000/5000 Fixnum#+
462
+ --------------------------------------------------------------------------------
463
+ 0.018 0.018 0.000 0.000 16001/16001 Catamaran::Logger#log_level
464
+ 2.16% 2.16% 0.018 0.018 0.000 0.000 16001 Kernel#nil?
465
+ --------------------------------------------------------------------------------
466
+ 0.018 0.018 0.000 0.000 5000/5000 <Class::Catamaran::Outputter>#write
467
+ 2.16% 2.16% 0.018 0.018 0.000 0.000 5000 <Class::Catamaran::Manager>#stdout?
468
+ --------------------------------------------------------------------------------
469
+ 0.018 0.018 0.000 0.000 10000/10000 Time#strftime
470
+ 2.15% 2.15% 0.018 0.018 0.000 0.000 10000 Fixnum#divmod
471
+ --------------------------------------------------------------------------------
472
+ 0.017 0.017 0.000 0.000 5000/5000 Catamaran::Logger#_format_msg
473
+ 1.98% 1.98% 0.017 0.017 0.000 0.000 5000 <Class::Catamaran::Manager>#formatter_class
474
+ --------------------------------------------------------------------------------
475
+ 0.017 0.017 0.000 0.000 5000/5000 <Class::Catamaran::Formatter::NoCallerFormatter>#construct_formatted_message
476
+ 1.96% 1.96% 0.017 0.017 0.000 0.000 5000 <Class::Catamaran::Formatter::BaseFormatter>#construct_backtrace_info
477
+ --------------------------------------------------------------------------------
478
+ 0.015 0.015 0.000 0.000 5000/5000 <Class::Catamaran::Outputter>#write
479
+ 1.81% 1.81% 0.015 0.015 0.000 0.000 5000 <Class::Catamaran::Manager>#stderr?
480
+ --------------------------------------------------------------------------------
481
+ 0.014 0.014 0.000 0.000 5000/5000 <Class::Catamaran::Formatter::BaseFormatter>#base_construct_formatted_message
482
+ 1.61% 1.61% 0.014 0.014 0.000 0.000 5000 <Class::Catamaran::LogLevel>#severity_to_s
483
+ --------------------------------------------------------------------------------
484
+ 0.013 0.013 0.000 0.000 5000/5000 <Class::Catamaran::Formatter::BaseFormatter>#base_construct_formatted_message
485
+ 1.52% 1.52% 0.013 0.013 0.000 0.000 5000 Fixnum#to_s
486
+ --------------------------------------------------------------------------------
487
+ 0.007 0.007 0.000 0.000 5000/5000 <Class::Catamaran::Formatter::BaseFormatter>#base_construct_formatted_message
488
+ 0.78% 0.78% 0.007 0.007 0.000 0.000 5000 <Module::Process>#pid
489
+ --------------------------------------------------------------------------------
490
+ 0.006 0.006 0.000 0.000 5000/5000 Time#strftime
491
+ 0.72% 0.72% 0.006 0.006 0.000 0.000 5000 Fixnum#%
492
+ --------------------------------------------------------------------------------
493
+ 0.006 0.006 0.000 0.000 5000/5000 Time#initialize
494
+ 0.70% 0.70% 0.006 0.006 0.000 0.000 5000 Fixnum#+
495
+ --------------------------------------------------------------------------------
496
+ 0.000 0.000 0.000 0.000 1/1 Global#[No method]
497
+ 0.00% 0.00% 0.000 0.000 0.000 0.000 1 Class#new
498
+ 0.000 0.000 0.000 0.000 1/1 BasicObject#initialize
499
+ --------------------------------------------------------------------------------
500
+ 0.000 0.000 0.000 0.000 4/4 Catamaran::Logger#log_level
501
+ 0.00% 0.00% 0.000 0.000 0.000 0.000 4 NilClass#nil?
502
+ --------------------------------------------------------------------------------
503
+ 0.000 0.000 0.000 0.000 1/1 Class#new
504
+ 0.00% 0.00% 0.000 0.000 0.000 0.000 1 BasicObject#initialize
505
+ --------------------------------------------------------------------------------
506
+ 0.000 0.000 0.000 0.000 1/1 Catamaran::Logger#path_to_s
507
+ 0.00% 0.00% 0.000 0.000 0.000 0.000 1 <Class::Catamaran::Manager>#delimiter
508
+
509
+ * indicates recursively called methods
510
+ ```
511
+
512
+
271
513
 
272
514
  Ideas around what's next
273
515
  ------------------------
@@ -281,6 +523,7 @@ Ideas around what's next
281
523
  * Log rotation
282
524
  * Heroku support (https://blog.heroku.com/archives/2013/7/15/logging-on-heroku)
283
525
  * Buffered file I/O considerations
526
+ * Revisit how the formatters work
284
527
 
285
528
 
286
529
 
@@ -14,18 +14,17 @@ module Catamaran
14
14
 
15
15
  # TODO: Abstract out the logger so that it's easy to use different formats
16
16
  # Implicit return
17
- retval = sprintf( "%6s pid-#{Process.pid} [#{Time.now.strftime( "%G-%m-%d %H:%M:%S:%L" )}] %47s - #{msg}", LogLevel.severity_to_s( severity ), updated_path )
17
+ sprintf( "%6s pid-#{Process.pid} [#{Time.now.strftime( "%G-%m-%d %H:%M:%S:%L" )}] %47s - #{msg}", LogLevel.severity_to_s( severity ), updated_path )
18
18
  end
19
19
 
20
20
  def self.construct_backtrace_info( opts )
21
21
  if opts && opts[:backtrace] == true
22
- msg = " from:\n#{caller(5).take(10).join("\n")}"
22
+ # Implicit return
23
+ " from:\n#{caller(5).take(10).join("\n")}"
23
24
  else
24
- msg = ''
25
+ # Implicit return
26
+ ''
25
27
  end
26
-
27
- # Implicit return
28
- msg
29
28
  end
30
29
 
31
30
 
@@ -26,6 +26,21 @@ module Catamaran
26
26
 
27
27
  IO = IO_LESS_CRITICAL_THAN_INFO
28
28
 
29
+
30
+ SEVERITY_TO_STRING_MAP = {
31
+ TRACE => 'TRACE',
32
+ DEBUG => 'DEBUG',
33
+ INFO => 'INFO',
34
+ NOTICE => 'NOTICE',
35
+ WARN => 'WARN',
36
+ ERROR => 'ERROR',
37
+ SEVERE => 'SEVERE',
38
+ FATAL => 'FATAL',
39
+ IO_LESS_CRITICAL_THAN_TRACE => 'IO',
40
+ IO_LESS_CRITICAL_THAN_INFO => 'IO',
41
+ IO_LESS_CRITICAL_THAN_DEBUG => 'IO'
42
+ }
43
+
29
44
  def self.reset
30
45
  self.send( :remove_const, 'IO' ) if self.const_defined?( 'IO' )
31
46
  self.const_set( 'IO', IO_LESS_CRITICAL_THAN_INFO )
@@ -35,34 +50,10 @@ module Catamaran
35
50
 
36
51
 
37
52
  def self.severity_to_s( severity )
38
- case severity
39
- when TRACE
40
- 'TRACE'
41
- when DEBUG
42
- 'DEBUG'
43
- when INFO
44
- 'INFO'
45
- when NOTICE
46
- 'NOTICE'
47
- when WARN
48
- 'WARN'
49
- when ERROR
50
- 'ERROR'
51
- when SEVERE
52
- 'SEVERE'
53
- when FATAL
54
- 'FATAL'
55
- when IO_LESS_CRITICAL_THAN_TRACE
56
- 'IO'
57
- when IO_LESS_CRITICAL_THAN_INFO
58
- 'IO'
59
- when IO_LESS_CRITICAL_THAN_DEBUG
60
- 'IO'
61
- else
62
- # Unknown
63
- ''
64
- end
65
- end
53
+ SEVERITY_TO_STRING_MAP[severity] || ''
54
+ end
55
+
56
+
66
57
 
67
58
  def self.log_level_io=( value )
68
59
  self.send( :remove_const, 'IO' ) if self.const_defined?( 'IO' )
@@ -293,7 +293,8 @@ module Catamaran
293
293
  end
294
294
 
295
295
  def fatal( msg, opts = nil )
296
- if fatal?
296
+ # Duplicated the logic from fatal?() (rather than calling it directly) for performance considerations
297
+ if self.log_level( { :be_populated => true } ) <= LogLevel::FATAL
297
298
  log( LogLevel::FATAL, msg, opts )
298
299
  end
299
300
  end
@@ -373,10 +374,14 @@ module Catamaran
373
374
  # Human-readable path
374
375
 
375
376
  def path_to_s
377
+ unless @memoized_delimiter
378
+ @memoized_delimiter = Catamaran::Manager.delimiter
379
+ end
380
+
376
381
  _path = self.path
377
382
  if _path
378
383
  # Implicit return
379
- _path.join( Catamaran::Manager.delimiter )
384
+ _path.join( @memoized_delimiter )
380
385
  else
381
386
  # Implicit return
382
387
  nil
@@ -423,6 +428,7 @@ module Catamaran
423
428
  @log_level = nil
424
429
  @backtrace_log_level = nil
425
430
  @memoized_backtrace_log_level = nil
431
+ @memoized_delimiter = nil
426
432
 
427
433
  self.name = @initialized_name
428
434
  self.path = @initialized_path_so_far ? @initialized_path_so_far.dup : []
@@ -1,4 +1,4 @@
1
1
  module Catamaran
2
- VERSION = '0.10.0'
2
+ VERSION = '0.11.0'
3
3
  end
4
4
 
@@ -125,44 +125,46 @@ describe Catamaran do
125
125
  end
126
126
 
127
127
  context "after a (soft) reset" do
128
- describe "the Root Logger" do
129
- it "should have a log level of NOTICE" do
130
- logger = Catamaran.logger
131
- logger.log_level = Catamaran::LogLevel::ERROR
128
+ context "the Root Logger" do
129
+ let(:logger){ Catamaran.logger }
130
+
131
+ before(:each){ logger.log_level = Catamaran::LogLevel::ERROR }
132
+
133
+ it "should have a log level of ERROR and a backtrace log level of WARN" do
132
134
  logger.log_level.should == Catamaran::LogLevel::ERROR
133
- Catamaran::Manager.reset
134
- logger.log_level.should == Catamaran::LogLevel::NOTICE
135
+ logger.backtrace_log_level.should == Catamaran::LogLevel::WARN
135
136
  end
136
137
 
137
- it "should have a backtrace log level of WARN" do
138
- logger = Catamaran.logger
139
- logger.backtrace_log_level = Catamaran::LogLevel::ERROR
140
- logger.backtrace_log_level.should == Catamaran::LogLevel::ERROR
138
+ it "should have a log level of NOTICE and a backtrace log level of WARN" do
141
139
  Catamaran::Manager.reset
142
- logger.backtrace_log_level.should == Catamaran::LogLevel::WARN
143
- end
144
- end
140
+ logger.log_level.should == Catamaran::LogLevel::NOTICE
141
+ logger.backtrace_log_level.should == Catamaran::LogLevel::WARN
142
+ end
145
143
 
146
- it "should have the same number of loggers" do
147
- Catamaran.logger
148
- Catamaran::Manager.num_loggers.should == 1
149
- Catamaran.logger.com.mycompany.myrailsproject.app.models.User
150
- Catamaran::Manager.num_loggers.should == 7
151
- Catamaran::Manager.reset
152
- Catamaran::Manager.num_loggers.should == 7
144
+ it "should have the same root logger object before and after the reset" do
145
+ before_logger = Catamaran.logger
146
+ Catamaran::Manager.reset
147
+ Catamaran.logger.object_id.should == before_logger.object_id
148
+ end
153
149
  end
154
150
 
155
- it "should have the same root logger object before and after the reset" do
156
- before_logger = Catamaran.logger
157
- Catamaran::Manager.reset
158
- Catamaran.logger.object_id.should == before_logger.object_id
159
- end
151
+ context "non-root loggers" do
152
+ let( :subloggers){ "com.mycompany.railsproject.app.models.User" }
153
+ let!(:rootlogger_count){ Catamaran.logger.num_loggers }
154
+ let( :total_loggers){ subloggers.split(".").count + rootlogger_count }
160
155
 
161
- it "should reuse the same logger non-root logger instance" do
162
- before_logger = Catamaran.logger.com.mycompany.myrailsproject.app.models.User
163
- Catamaran::Manager.reset
164
- before_logger.object_id.should == Catamaran.logger.com.mycompany.myrailsproject.app.models.User.object_id
165
- end
156
+ it "should have the same number of loggers" do
157
+ Catamaran.logger.com.mycompany.myrailsproject.app.models.User
158
+ Catamaran::Manager.reset
159
+ Catamaran::Manager.num_loggers.should == total_loggers
160
+ end
161
+
162
+ it "should reuse the same logger non-root logger instance" do
163
+ before_logger = Catamaran.logger.com.mycompany.myrailsproject.app.models.User
164
+ Catamaran::Manager.reset
165
+ before_logger.object_id.should == Catamaran.logger.com.mycompany.myrailsproject.app.models.User.object_id
166
+ end
167
+ end
166
168
  end
167
169
 
168
170
  context "after a hard reset" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catamaran
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-03 00:00:00.000000000 Z
11
+ date: 2014-01-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A logging utility
14
14
  email: