catamaran 0.6.0 → 0.7.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 +4 -4
- data/README.md +19 -13
- data/lib/catamaran/formatter/base_formatter.rb +1 -1
- data/lib/catamaran/log_level.rb +2 -32
- data/lib/catamaran/logger.rb +122 -27
- data/lib/catamaran/version.rb +1 -1
- data/spec/catamaran_spec.rb +139 -69
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0e807d462b178ce06016ad76babba6ba142928f9
|
|
4
|
+
data.tar.gz: 240ed2615b1b49361f3c49ba5be63bf2a5edafa8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1214f644cbecf098a31703930f6dfe4aed9715faa88ffa7acfcc8dbc8759e69f14104ff6ce72baa8317f35376ae71a7dd41bce1aad194c53b130c4c76f2132eb
|
|
7
|
+
data.tar.gz: 784259e5224043161d3b23bea3088e4f8328cd23b36feeabdebaf3f5edbde2b28d41588577aff6d41864f4935aaed8eeb24eeee225856dda61312842a988586d
|
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.
|
|
9
|
+
gem 'catamaran', '~> 0.7.0'
|
|
10
10
|
|
|
11
11
|
Rails-related setup:
|
|
12
12
|
|
|
@@ -64,14 +64,15 @@ Other Ruby Examples
|
|
|
64
64
|
-------------------
|
|
65
65
|
require 'catamaran'
|
|
66
66
|
|
|
67
|
-
Catamaran
|
|
67
|
+
Catamaran.logger.log_level = Catamaran::LogLevel::INFO
|
|
68
|
+
Catamaran.logger.backtrace_log_level = Catamaran::LogLevel::ERROR
|
|
68
69
|
Catamaran::Manager.formatter_class = Catamaran::Formatter::NoCallerFormatter
|
|
69
70
|
|
|
70
71
|
class SecondRubyDemo
|
|
71
72
|
LOGGER = Catamaran.logger( { :class => name(), :file => __FILE__ } )
|
|
72
73
|
|
|
73
74
|
def run
|
|
74
|
-
LOGGER.
|
|
75
|
+
LOGGER.info( "Sample INFO statement", { :line => __LINE__, :method => 'run'} ) if LOGGER.info?
|
|
75
76
|
end
|
|
76
77
|
end
|
|
77
78
|
|
|
@@ -79,8 +80,9 @@ Other Ruby Examples
|
|
|
79
80
|
LOGGER = Catamaran.logger( "com.mycompany.ThirdRubyDemo", { :class => name(), :file => __FILE__ } )
|
|
80
81
|
|
|
81
82
|
def run
|
|
82
|
-
LOGGER.
|
|
83
|
-
LOGGER.
|
|
83
|
+
LOGGER.warn( "Sample WARN statement", { :line => __LINE__, :method => 'run' } ) if LOGGER.warn?
|
|
84
|
+
LOGGER.warn( "Sample WARN statement with backtrace option", { :line => __LINE__, :method => 'run', :backtrace => true } ) if LOGGER.warn?
|
|
85
|
+
LOGGER.error( "Sample ERROR statement with backtrace option", { :line => __LINE__, :method => 'run', :backtrace => true } ) if LOGGER.error?
|
|
84
86
|
end
|
|
85
87
|
end
|
|
86
88
|
|
|
@@ -89,11 +91,13 @@ Other Ruby Examples
|
|
|
89
91
|
|
|
90
92
|
And the output
|
|
91
93
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
catamaran_ruby_demos.rb:
|
|
94
|
+
INFO pid-5973 [2013-12-27 17:18:09:115] - Sample INFO statement (catamaran_ruby_demos.rb:12:in `SecondRubyDemo.run')
|
|
95
|
+
WARN pid-5973 [2013-12-27 17:18:09:115] com.mycompany.ThirdRubyDemo - Sample WARN statement (catamaran_ruby_demos.rb:20:in `ThirdRubyDemo.run')
|
|
96
|
+
WARN pid-5973 [2013-12-27 17:18:09:115] com.mycompany.ThirdRubyDemo - Sample WARN statement with backtrace option (catamaran_ruby_demos.rb:21:in `ThirdRubyDemo.run')
|
|
97
|
+
ERROR pid-5973 [2013-12-27 17:18:09:115] com.mycompany.ThirdRubyDemo - Sample ERROR statement with backtrace option (catamaran_ruby_demos.rb:22:in `ThirdRubyDemo.run') from:
|
|
98
|
+
catamaran_ruby_demos.rb:22:in `run'
|
|
99
|
+
catamaran_ruby_demos.rb:27:in `<main>'
|
|
100
|
+
|
|
97
101
|
|
|
98
102
|
|
|
99
103
|
|
|
@@ -108,7 +112,9 @@ I'm looking for a logging utility that:
|
|
|
108
112
|
* supports the TRACE log level (or other log level less critical than DEBUG).
|
|
109
113
|
* is capable of capturing logs at different log level thresholds from different parts of the app simultaneously
|
|
110
114
|
* readily works with Rails
|
|
111
|
-
|
|
115
|
+
* http://stackoverflow.com/questions/462651/rails-logger-format-string-configuration
|
|
116
|
+
* http://stackoverflow.com/questions/3654827/logging-in-rails-app
|
|
117
|
+
* http://stackoverflow.com/questions/11991967/rails-log-too-verbose
|
|
112
118
|
|
|
113
119
|
Performance Considerations
|
|
114
120
|
--------------------------
|
|
@@ -185,7 +191,6 @@ ex:
|
|
|
185
191
|
require 'catamaran'
|
|
186
192
|
require 'benchmark'
|
|
187
193
|
|
|
188
|
-
Catamaran::LogLevel.default_log_level = Catamaran::LogLevel::INFO
|
|
189
194
|
Catamaran::Manager.stderr = false
|
|
190
195
|
|
|
191
196
|
class CatamaranPerformanceTest
|
|
@@ -239,8 +244,9 @@ Ideas around what's next
|
|
|
239
244
|
* Consider capturing log messages beyond stderr, stdout, and local files
|
|
240
245
|
* Ongoing performance considerations
|
|
241
246
|
* Something like `filter_parameter_logging`
|
|
242
|
-
* Optional backtrace support for certain logs
|
|
243
247
|
* Color support
|
|
248
|
+
* Log rotation
|
|
249
|
+
* Heroku support
|
|
244
250
|
|
|
245
251
|
|
|
246
252
|
|
data/lib/catamaran/log_level.rb
CHANGED
|
@@ -7,10 +7,6 @@ module Catamaran
|
|
|
7
7
|
IO_LESS_CRITICAL_THAN_DEBUG = 2080
|
|
8
8
|
IO_LESS_CRITICAL_THAN_INFO = 3080
|
|
9
9
|
|
|
10
|
-
BACKTRACE_LESS_CRITICAL_THAN_TRACE = 1070
|
|
11
|
-
BACKTRACE_LESS_CRITICAL_THAN_DEBUG = 2070
|
|
12
|
-
BACKTRACE_LESS_CRITICAL_THAN_INFO = 3070
|
|
13
|
-
|
|
14
10
|
ALL = 100
|
|
15
11
|
|
|
16
12
|
TRACE = 2000
|
|
@@ -22,18 +18,10 @@ module Catamaran
|
|
|
22
18
|
FATAL = 8000
|
|
23
19
|
|
|
24
20
|
IO = IO_LESS_CRITICAL_THAN_INFO
|
|
25
|
-
BACKTRACE = BACKTRACE_LESS_CRITICAL_THAN_INFO
|
|
26
|
-
|
|
27
|
-
|
|
28
21
|
|
|
29
22
|
def self.reset
|
|
30
|
-
@@default_log_level = INFO
|
|
31
|
-
|
|
32
23
|
self.send( :remove_const, 'IO' ) if self.const_defined?( 'IO' )
|
|
33
|
-
self.const_set( 'IO', IO_LESS_CRITICAL_THAN_INFO )
|
|
34
|
-
|
|
35
|
-
self.send( :remove_const, 'BACKTRACE' ) if self.const_defined?( 'BACKTRACE' )
|
|
36
|
-
self.const_set( 'BACKTRACE', BACKTRACE_LESS_CRITICAL_THAN_INFO )
|
|
24
|
+
self.const_set( 'IO', IO_LESS_CRITICAL_THAN_INFO )
|
|
37
25
|
end
|
|
38
26
|
|
|
39
27
|
self.reset()
|
|
@@ -62,16 +50,7 @@ module Catamaran
|
|
|
62
50
|
end
|
|
63
51
|
|
|
64
52
|
retval
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def self.default_log_level
|
|
68
|
-
@@default_log_level
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def self.default_log_level=( value )
|
|
72
|
-
Catamaran.debugging( "Catamaran::LogLevel#default_log_level=() - Switching the default log level to #{value}" ) if Catamaran.debugging?
|
|
73
|
-
@@default_log_level = value
|
|
74
|
-
end
|
|
53
|
+
end
|
|
75
54
|
|
|
76
55
|
def self.log_level_io=( value )
|
|
77
56
|
self.send( :remove_const, 'IO' ) if self.const_defined?( 'IO' )
|
|
@@ -80,15 +59,6 @@ module Catamaran
|
|
|
80
59
|
|
|
81
60
|
def self.log_level_io
|
|
82
61
|
IO
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def self.log_level_backtrace=( value )
|
|
86
|
-
self.send( :remove_const, 'BACKTRACE' ) if self.const_defined?( 'BACKTRACE' )
|
|
87
|
-
self.const_set( 'BACKTRACE', value )
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def self.log_level_backtrace
|
|
91
|
-
BACKTRACE
|
|
92
62
|
end
|
|
93
63
|
end
|
|
94
64
|
end
|
data/lib/catamaran/logger.rb
CHANGED
|
@@ -15,7 +15,7 @@ module Catamaran
|
|
|
15
15
|
retval = @log_level
|
|
16
16
|
elsif self.parent.nil?
|
|
17
17
|
# No parent means this logger(self) is the root logger. So use the default log level
|
|
18
|
-
retval = Catamaran::LogLevel
|
|
18
|
+
retval = Catamaran::LogLevel::INFO
|
|
19
19
|
else
|
|
20
20
|
recursive = opts[:recursive]
|
|
21
21
|
if recursive == true
|
|
@@ -51,6 +51,87 @@ module Catamaran
|
|
|
51
51
|
@log_level = value
|
|
52
52
|
remove_instance_variable( :@memoized_log_level ) if instance_variable_defined?( :@memoized_log_level )
|
|
53
53
|
end
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def backtrace_log_level( opts = {} )
|
|
67
|
+
if instance_variable_defined?( :@backtrace_log_level ) && @backtrace_log_level
|
|
68
|
+
retval = @backtrace_log_level
|
|
69
|
+
elsif self.parent.nil?
|
|
70
|
+
# No parent means this logger(self) is the root logger. So use the default log level
|
|
71
|
+
retval = Catamaran::LogLevel::WARN
|
|
72
|
+
else
|
|
73
|
+
recursive = opts[:recursive]
|
|
74
|
+
if recursive == true
|
|
75
|
+
|
|
76
|
+
# Remember the log level we found so we don't have to recursively look for it ever time
|
|
77
|
+
if !instance_variable_defined?( :@memoized_backtrace_log_level ) || @memoized_backtrace_log_level.nil?
|
|
78
|
+
@memoized_backtrace_log_level = parent.backtrace_log_level( opts ) if parent
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
retval = @memoized_backtrace_log_level
|
|
82
|
+
else
|
|
83
|
+
Catamaran.debugging( "Catamaran::Logger#backtrace_log_level() - non-recrusive request for log level. And log level is nil. This shouldn't happen too often." ) if Catamaran.debugging?
|
|
84
|
+
retval = nil
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Implicit return
|
|
89
|
+
retval
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
##
|
|
93
|
+
# We usually want a logger to have a level. The smart_backtrace_log_level() reader determines a log level even if one isn't
|
|
94
|
+
# explicitly set on this logger instance by making use of recursion up to the root logger if needed
|
|
95
|
+
|
|
96
|
+
def smart_backtrace_log_level
|
|
97
|
+
self.backtrace_log_level( { :recursive => true } )
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
##
|
|
101
|
+
# Setter used to explicitly set the log level for this logger
|
|
102
|
+
|
|
103
|
+
def backtrace_log_level=( value )
|
|
104
|
+
@backtrace_log_level = value
|
|
105
|
+
remove_instance_variable( :@memoized_backtrace_log_level ) if instance_variable_defined?( :@memoized_backtrace_log_level )
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
54
135
|
|
|
55
136
|
##
|
|
56
137
|
# Is trace-level logging currently enabled?
|
|
@@ -65,7 +146,7 @@ module Catamaran
|
|
|
65
146
|
|
|
66
147
|
def trace( msg, opts = nil )
|
|
67
148
|
if trace?
|
|
68
|
-
|
|
149
|
+
log( LogLevel::TRACE, msg, opts )
|
|
69
150
|
end
|
|
70
151
|
end
|
|
71
152
|
|
|
@@ -82,7 +163,7 @@ module Catamaran
|
|
|
82
163
|
|
|
83
164
|
def debug( msg, opts = nil )
|
|
84
165
|
if debug?
|
|
85
|
-
|
|
166
|
+
log( LogLevel::DEBUG, msg, opts )
|
|
86
167
|
end
|
|
87
168
|
end
|
|
88
169
|
|
|
@@ -100,7 +181,7 @@ module Catamaran
|
|
|
100
181
|
|
|
101
182
|
def io( msg, opts = nil )
|
|
102
183
|
if io?
|
|
103
|
-
|
|
184
|
+
log( LogLevel::IO, msg, opts )
|
|
104
185
|
end
|
|
105
186
|
end
|
|
106
187
|
|
|
@@ -117,7 +198,7 @@ module Catamaran
|
|
|
117
198
|
|
|
118
199
|
def info( msg, opts = nil )
|
|
119
200
|
if info?
|
|
120
|
-
|
|
201
|
+
log( LogLevel::INFO, msg, opts )
|
|
121
202
|
end
|
|
122
203
|
end
|
|
123
204
|
|
|
@@ -134,7 +215,7 @@ module Catamaran
|
|
|
134
215
|
|
|
135
216
|
def warn( msg, opts = nil )
|
|
136
217
|
if warn?
|
|
137
|
-
|
|
218
|
+
log( LogLevel::WARN, msg, opts )
|
|
138
219
|
end
|
|
139
220
|
end
|
|
140
221
|
|
|
@@ -151,7 +232,7 @@ module Catamaran
|
|
|
151
232
|
|
|
152
233
|
def error( msg, opts = nil )
|
|
153
234
|
if error?
|
|
154
|
-
|
|
235
|
+
log( LogLevel::ERROR, msg, opts )
|
|
155
236
|
end
|
|
156
237
|
end
|
|
157
238
|
|
|
@@ -168,7 +249,7 @@ module Catamaran
|
|
|
168
249
|
|
|
169
250
|
def severe( msg, opts = nil )
|
|
170
251
|
if severe?
|
|
171
|
-
|
|
252
|
+
log( LogLevel::SEVERE, msg, opts )
|
|
172
253
|
end
|
|
173
254
|
end
|
|
174
255
|
|
|
@@ -185,20 +266,12 @@ module Catamaran
|
|
|
185
266
|
|
|
186
267
|
# def fatal( msg, opts = nil )
|
|
187
268
|
# if fatal?
|
|
188
|
-
#
|
|
269
|
+
# log( LogLevel::FATAL, msg, opts )
|
|
189
270
|
# end
|
|
190
271
|
# end
|
|
191
272
|
|
|
192
|
-
##
|
|
193
|
-
# Is backtrace-level logging currently enabled? (Special case)
|
|
194
273
|
|
|
195
|
-
|
|
196
|
-
if self.smart_log_level() <= LogLevel::BACKTRACE
|
|
197
|
-
true
|
|
198
|
-
else
|
|
199
|
-
false
|
|
200
|
-
end
|
|
201
|
-
end
|
|
274
|
+
|
|
202
275
|
|
|
203
276
|
##
|
|
204
277
|
# Usually get_logger is a reference to self, unless a path has been specified as a parameter
|
|
@@ -315,7 +388,8 @@ module Catamaran
|
|
|
315
388
|
|
|
316
389
|
def reset( opts = {} )
|
|
317
390
|
remove_instance_variable(:@memoized_log_level) if instance_variable_defined?( :@memoized_log_level )
|
|
318
|
-
remove_instance_variable(:@log_level) if instance_variable_defined?( :@log_level )
|
|
391
|
+
remove_instance_variable(:@log_level) if instance_variable_defined?( :@log_level )
|
|
392
|
+
remove_instance_variable(:@backtrace_log_level) if instance_variable_defined?( :@backtrace_log_level )
|
|
319
393
|
|
|
320
394
|
self.name = @initialized_name
|
|
321
395
|
self.path = @initialized_path_so_far ? @initialized_path_so_far.dup : []
|
|
@@ -374,7 +448,7 @@ module Catamaran
|
|
|
374
448
|
|
|
375
449
|
def to_s
|
|
376
450
|
# Implicit return
|
|
377
|
-
"#<#{self.class}:0x#{object_id.to_s(16)}>[name=#{self.name},path=#{path_to_s},depth=#{self.depth},log_level=#{@log_level}]"
|
|
451
|
+
"#<#{self.class}:0x#{object_id.to_s(16)}>[name=#{self.name},path=#{path_to_s},depth=#{self.depth},log_level=#{@log_level},backtrace_log_level=#{@backtrace_log_level}]"
|
|
378
452
|
end
|
|
379
453
|
|
|
380
454
|
protected
|
|
@@ -413,9 +487,10 @@ module Catamaran
|
|
|
413
487
|
|
|
414
488
|
|
|
415
489
|
##
|
|
416
|
-
# All log statements eventually call
|
|
490
|
+
# All log statements eventually call log
|
|
491
|
+
|
|
492
|
+
def log( log_level, msg, opts )
|
|
417
493
|
|
|
418
|
-
def _log( log_level, msg, opts )
|
|
419
494
|
if self.specified_file || self.specified_class
|
|
420
495
|
opts = {} unless opts
|
|
421
496
|
opts[:file] = self.specified_file if self.specified_file
|
|
@@ -423,15 +498,35 @@ module Catamaran
|
|
|
423
498
|
end
|
|
424
499
|
|
|
425
500
|
if opts && opts[:backtrace] == true
|
|
426
|
-
|
|
427
|
-
|
|
501
|
+
_smart_backtrace_log_level = self.smart_backtrace_log_level()
|
|
502
|
+
|
|
503
|
+
# If the specified log message has a level that's
|
|
504
|
+
# greater than or equal to the current backtrace_log_level
|
|
505
|
+
Catamaran.debugging( "Catamaran::Logger#initialize() - Considering a backtrace: log_level = #{log_level}, backtrace_log_level = #{_smart_backtrace_log_level}" ) if Catamaran.debugging?
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
if log_level >= _smart_backtrace_log_level
|
|
509
|
+
# no-op -- display the backtrace
|
|
510
|
+
else
|
|
511
|
+
# overwrite opts with a new value
|
|
512
|
+
|
|
513
|
+
# For performance it's probably acceptable to just remove the backtrace option from the options list...
|
|
514
|
+
# opts.delete(:backtrace)
|
|
515
|
+
|
|
516
|
+
# But for now it might be cleaner to duplicate the hash first, before modifying it
|
|
428
517
|
opts = opts.dup
|
|
429
|
-
opts.delete(:backtrace)
|
|
518
|
+
opts.delete( :backtrace )
|
|
430
519
|
end
|
|
431
520
|
end
|
|
432
521
|
|
|
433
|
-
|
|
434
|
-
Outputter.write(
|
|
522
|
+
# Implicit return
|
|
523
|
+
Outputter.write( _format_msg( log_level, msg, opts ) )
|
|
524
|
+
end
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
def _format_msg( log_level, msg, opts )
|
|
528
|
+
# Implicit return
|
|
529
|
+
Manager.formatter_class.construct_formatted_message( log_level, self.path_to_s(), msg, opts )
|
|
435
530
|
end
|
|
436
531
|
|
|
437
532
|
##
|
data/lib/catamaran/version.rb
CHANGED
data/spec/catamaran_spec.rb
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Catamaran do
|
|
4
|
+
before(:each) do
|
|
5
|
+
Catamaran::Manager.stderr = false
|
|
6
|
+
end
|
|
7
|
+
|
|
4
8
|
it "should define TRACE" do
|
|
5
9
|
Catamaran::LogLevel::TRACE.should > 0
|
|
6
10
|
end
|
|
@@ -20,11 +24,11 @@ describe Catamaran do
|
|
|
20
24
|
end
|
|
21
25
|
|
|
22
26
|
it "should reuse the same logger instance when contextually the same" do
|
|
23
|
-
Catamaran.logger.
|
|
27
|
+
Catamaran.logger.com.mycompany.myrailsproject.app.models.User.object_id.should == Catamaran.logger.com.mycompany.myrailsproject.app.models.User.object_id
|
|
24
28
|
end
|
|
25
29
|
|
|
26
30
|
it "should reuse the same logger instance when contextually the same regardless of if the logger was determined by a string or by sequential method calls" do
|
|
27
|
-
Catamaran.logger( "
|
|
31
|
+
Catamaran.logger( "com.mycompany.myrailsproject.app.models.User" ).object_id.should == Catamaran.logger.com.mycompany.myrailsproject.app.models.User.object_id
|
|
28
32
|
end
|
|
29
33
|
|
|
30
34
|
it "should provide access to the root logger through CatLogger" do
|
|
@@ -37,9 +41,9 @@ describe Catamaran do
|
|
|
37
41
|
end
|
|
38
42
|
|
|
39
43
|
it "should provide access to loggers after a reset" do
|
|
40
|
-
logger = Catamaran.logger.
|
|
44
|
+
logger = Catamaran.logger.com.mycompany.myrailsproject.app.models.User
|
|
41
45
|
Catamaran::Manager.reset
|
|
42
|
-
logger2 = Catamaran.logger.
|
|
46
|
+
logger2 = Catamaran.logger.com.mycompany.myrailsproject.app.models.User
|
|
43
47
|
logger2.should be_instance_of( Catamaran::Logger )
|
|
44
48
|
logger2.object_id.should == logger.object_id
|
|
45
49
|
end
|
|
@@ -47,15 +51,21 @@ describe Catamaran do
|
|
|
47
51
|
it "should create a new loggers for each point in the path" do
|
|
48
52
|
Catamaran.logger
|
|
49
53
|
Catamaran::Manager.num_loggers.should == 1
|
|
50
|
-
Catamaran.logger.
|
|
51
|
-
Catamaran::Manager.num_loggers.should ==
|
|
54
|
+
Catamaran.logger.com.mycompany.myrailsproject.app.models.User
|
|
55
|
+
Catamaran::Manager.num_loggers.should == 7
|
|
52
56
|
end
|
|
53
57
|
|
|
54
|
-
it "should be possible for the user to modify the
|
|
55
|
-
Catamaran
|
|
56
|
-
Catamaran.logger.
|
|
58
|
+
it "should be possible for the user to modify the log level of root logger" do
|
|
59
|
+
Catamaran.logger.log_level = Catamaran::LogLevel::TRACE
|
|
60
|
+
Catamaran.logger.log_level.should == Catamaran::LogLevel::TRACE
|
|
57
61
|
end
|
|
58
62
|
|
|
63
|
+
it "should be possible for the user to modify the log level of non-root loggers" do
|
|
64
|
+
Catamaran.logger.whatever.log_level.should be_nil
|
|
65
|
+
Catamaran.logger.whatever.log_level = Catamaran::LogLevel::TRACE
|
|
66
|
+
Catamaran.logger.whatever.log_level.should == Catamaran::LogLevel::TRACE
|
|
67
|
+
end
|
|
68
|
+
|
|
59
69
|
it "should not provide the same object ID for different paths" do
|
|
60
70
|
Catamaran.logger.A.C.object_id.should_not == Catamaran.logger.B.C
|
|
61
71
|
Catamaran.logger.A.C.object_id.should_not == Catamaran.logger.A.B
|
|
@@ -63,24 +73,50 @@ describe Catamaran do
|
|
|
63
73
|
|
|
64
74
|
context "by default" do
|
|
65
75
|
it "should log INFO messages" do
|
|
66
|
-
logger = Catamaran.logger.
|
|
76
|
+
logger = Catamaran.logger.com.mycompany.myrailsproject.app.models.User
|
|
67
77
|
end
|
|
68
78
|
|
|
69
79
|
it "should NOT log DEBUG messages" do
|
|
70
|
-
logger = Catamaran.logger.
|
|
80
|
+
logger = Catamaran.logger.com.mycompany.myrailsproject.app.models.User
|
|
71
81
|
end
|
|
72
82
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
83
|
+
describe "the Root Logger" do
|
|
84
|
+
it "should have a log level set to INFO" do
|
|
85
|
+
Catamaran.logger.log_level.should == Catamaran::LogLevel::INFO
|
|
86
|
+
end
|
|
76
87
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
88
|
+
it "should have a backtrace log level set to WARN" do
|
|
89
|
+
Catamaran.logger.backtrace_log_level.should == Catamaran::LogLevel::WARN
|
|
90
|
+
end
|
|
80
91
|
end
|
|
81
92
|
|
|
82
|
-
|
|
83
|
-
|
|
93
|
+
describe "a non-root Logger" do
|
|
94
|
+
before(:each) do
|
|
95
|
+
@non_root_logger = Catamaran.logger.whatever
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
it "should have a log level set to INFO" do
|
|
100
|
+
@non_root_logger.log_level.should be_nil
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "should have a backtrace log level set to WARN" do
|
|
104
|
+
@non_root_logger.backtrace_log_level.should be_nil
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "should have a smart log level set to INFO" do
|
|
108
|
+
@non_root_logger.smart_log_level.should == Catamaran::LogLevel::INFO
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it "should have a smart backtrace log level set to WARN" do
|
|
112
|
+
@non_root_logger.smart_backtrace_log_level.should == Catamaran::LogLevel::WARN
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
describe "Catamaran::Manager" do
|
|
117
|
+
it "should have one logger configured" do
|
|
118
|
+
Catamaran::Manager.num_loggers.should == 1
|
|
119
|
+
end
|
|
84
120
|
end
|
|
85
121
|
|
|
86
122
|
it "should have an IO log level that corresponds to IO_LESS_CRITICAL_THAN_INFO" do
|
|
@@ -88,28 +124,32 @@ describe Catamaran do
|
|
|
88
124
|
end
|
|
89
125
|
end
|
|
90
126
|
|
|
91
|
-
context "when the log level is set to INFO" do
|
|
92
|
-
Catamaran.logger.log_level = Catamaran::LogLevel::INFO
|
|
93
|
-
Catamaran.logger.Company.Product.App.Model.User
|
|
94
|
-
end
|
|
95
|
-
|
|
96
127
|
context "after a (soft) reset" do
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
128
|
+
describe "the Root Logger" do
|
|
129
|
+
it "should have a log level of INFO" do
|
|
130
|
+
logger = Catamaran.logger
|
|
131
|
+
logger.log_level = Catamaran::LogLevel::ERROR
|
|
132
|
+
logger.log_level.should == Catamaran::LogLevel::ERROR
|
|
133
|
+
Catamaran::Manager.reset
|
|
134
|
+
logger.log_level.should == Catamaran::LogLevel::INFO
|
|
135
|
+
end
|
|
136
|
+
|
|
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
|
|
141
|
+
Catamaran::Manager.reset
|
|
142
|
+
logger.backtrace_log_level.should == Catamaran::LogLevel::WARN
|
|
143
|
+
end
|
|
144
|
+
end
|
|
105
145
|
|
|
106
|
-
it "should
|
|
146
|
+
it "should have the same number of loggers" do
|
|
107
147
|
Catamaran.logger
|
|
108
148
|
Catamaran::Manager.num_loggers.should == 1
|
|
109
|
-
Catamaran.logger.
|
|
110
|
-
Catamaran::Manager.num_loggers.should ==
|
|
149
|
+
Catamaran.logger.com.mycompany.myrailsproject.app.models.User
|
|
150
|
+
Catamaran::Manager.num_loggers.should == 7
|
|
111
151
|
Catamaran::Manager.reset
|
|
112
|
-
Catamaran::Manager.num_loggers.should ==
|
|
152
|
+
Catamaran::Manager.num_loggers.should == 7
|
|
113
153
|
end
|
|
114
154
|
|
|
115
155
|
it "should have the same root logger object before and after the reset" do
|
|
@@ -119,9 +159,9 @@ describe Catamaran do
|
|
|
119
159
|
end
|
|
120
160
|
|
|
121
161
|
it "should reuse the same logger non-root logger instance" do
|
|
122
|
-
before_logger = Catamaran.logger.
|
|
162
|
+
before_logger = Catamaran.logger.com.mycompany.myrailsproject.app.models.User
|
|
123
163
|
Catamaran::Manager.reset
|
|
124
|
-
before_logger.object_id.should == Catamaran.logger.
|
|
164
|
+
before_logger.object_id.should == Catamaran.logger.com.mycompany.myrailsproject.app.models.User.object_id
|
|
125
165
|
end
|
|
126
166
|
end
|
|
127
167
|
|
|
@@ -138,8 +178,8 @@ describe Catamaran do
|
|
|
138
178
|
it "should reset the number of loggers to 1" do
|
|
139
179
|
Catamaran.logger
|
|
140
180
|
Catamaran::Manager.num_loggers.should == 1
|
|
141
|
-
Catamaran.logger.
|
|
142
|
-
Catamaran::Manager.num_loggers.should ==
|
|
181
|
+
Catamaran.logger.com.mycompany.myrailsproject.app.models.User
|
|
182
|
+
Catamaran::Manager.num_loggers.should == 7
|
|
143
183
|
Catamaran::Manager.hard_reset
|
|
144
184
|
Catamaran::Manager.num_loggers.should == 1
|
|
145
185
|
end
|
|
@@ -151,17 +191,44 @@ describe Catamaran do
|
|
|
151
191
|
end
|
|
152
192
|
|
|
153
193
|
it "should NOT reuse the same non-root logger instance" do
|
|
154
|
-
before_logger = Catamaran.logger.
|
|
194
|
+
before_logger = Catamaran.logger.com.mycompany.myrailsproject.app.models.User
|
|
155
195
|
Catamaran::Manager.hard_reset
|
|
156
|
-
before_logger.object_id.should_not == Catamaran.logger.
|
|
196
|
+
before_logger.object_id.should_not == Catamaran.logger.com.mycompany.myrailsproject.app.models.User.object_id
|
|
157
197
|
end
|
|
158
198
|
end
|
|
159
199
|
|
|
160
|
-
describe
|
|
161
|
-
it "should
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
200
|
+
describe "Backtrace Logging" do
|
|
201
|
+
it "should capture a backtrace when the requested log is DEBUG and the log_level and backtrace_log_level are TRACE" do
|
|
202
|
+
logger = Catamaran.logger
|
|
203
|
+
logger.should_receive( :_format_msg ).with( Catamaran::LogLevel::DEBUG, 'message', {:backtrace=>true} )
|
|
204
|
+
logger.log_level = Catamaran::LogLevel::TRACE
|
|
205
|
+
logger.backtrace_log_level = Catamaran::LogLevel::TRACE
|
|
206
|
+
Catamaran.logger.debug( "message", { :backtrace => true } ) if Catamaran.logger.debug?
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
it "should capture a backtrace when the requested log is DEBUG and the log_level and backtrace_log_level are DEBUG" do
|
|
210
|
+
logger = Catamaran.logger
|
|
211
|
+
logger.should_receive( :_format_msg ).with( Catamaran::LogLevel::DEBUG, 'message', {:backtrace=>true} )
|
|
212
|
+
logger.log_level = Catamaran::LogLevel::DEBUG
|
|
213
|
+
logger.backtrace_log_level = Catamaran::LogLevel::DEBUG
|
|
214
|
+
Catamaran.logger.debug( "message", { :backtrace => true } ) if Catamaran.logger.debug?
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
it "should capture a backtrace when the requested log is DEBUG and the log_level is TRACE and the backtrace_log_level is DEBUG" do
|
|
218
|
+
logger = Catamaran.logger
|
|
219
|
+
logger.should_receive( :_format_msg ).with( Catamaran::LogLevel::DEBUG, 'message', {:backtrace=>true} )
|
|
220
|
+
logger.log_level = Catamaran::LogLevel::TRACE
|
|
221
|
+
logger.backtrace_log_level = Catamaran::LogLevel::DEBUG
|
|
222
|
+
Catamaran.logger.debug( "message", { :backtrace => true } ) if Catamaran.logger.debug?
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
it "should NOT capture a backtrace when the backtrace_log_level is greater than the level of the log" do
|
|
226
|
+
logger = Catamaran.logger
|
|
227
|
+
logger.log_level = Catamaran::LogLevel::TRACE
|
|
228
|
+
logger.backtrace_log_level = Catamaran::LogLevel::WARN
|
|
229
|
+
logger.should_receive( :_format_msg ).with( Catamaran::LogLevel::DEBUG, 'message', {} )
|
|
230
|
+
Catamaran.logger.debug( "message", { :backtrace => true } ) if Catamaran.logger.debug?
|
|
231
|
+
end
|
|
165
232
|
end
|
|
166
233
|
|
|
167
234
|
describe Catamaran::Manager do
|
|
@@ -186,37 +253,42 @@ describe Catamaran do
|
|
|
186
253
|
end
|
|
187
254
|
|
|
188
255
|
describe Catamaran::Logger do
|
|
256
|
+
it "should inherit it's log level (via smart_log_level) from an ancestor" do
|
|
257
|
+
Catamaran.logger.com.mycompany.myproject.controllers.log_level = Catamaran::LogLevel::ERROR
|
|
258
|
+
Catamaran.logger.com.mycompany.myproject.controllers.MyController.smart_log_level.should == Catamaran::LogLevel::ERROR
|
|
259
|
+
end
|
|
260
|
+
|
|
189
261
|
it "should inherit the log level from the root logger as needed" do
|
|
190
262
|
Catamaran.logger.smart_log_level.should == Catamaran::LogLevel::INFO
|
|
191
|
-
Catamaran.logger.
|
|
192
|
-
Catamaran.logger.
|
|
263
|
+
Catamaran.logger.com.mycompany.myrailsproject.app.models.User.log_level.should be_nil
|
|
264
|
+
Catamaran.logger.com.mycompany.myrailsproject.app.models.User.smart_log_level.should == Catamaran::LogLevel::INFO
|
|
193
265
|
end
|
|
194
266
|
|
|
195
267
|
it "should have a nil log_level unless explicitly set" do
|
|
196
|
-
Catamaran.logger.
|
|
268
|
+
Catamaran.logger.com.mycompany.myrailsproject.app.models.User.log_level.should be_nil
|
|
197
269
|
end
|
|
198
270
|
|
|
199
271
|
it "should always have a smart_log_level set" do
|
|
200
|
-
Catamaran.logger.
|
|
201
|
-
Catamaran.logger.
|
|
272
|
+
Catamaran.logger.whatever.log_level.should be_nil
|
|
273
|
+
Catamaran.logger.whatever.smart_log_level.should_not be_nil
|
|
202
274
|
end
|
|
203
275
|
|
|
204
|
-
it "should write the log if the log
|
|
276
|
+
it "should write the log message if the requested log does not have sufficient weight" do
|
|
205
277
|
Catamaran.logger.smart_log_level.should == Catamaran::LogLevel::INFO
|
|
206
|
-
Catamaran.logger.should_receive( :
|
|
278
|
+
Catamaran.logger.should_receive( :log ).once
|
|
207
279
|
Catamaran.logger.info( "Testing an INFO log" )
|
|
208
280
|
end
|
|
209
281
|
|
|
210
|
-
it "should NOT write the log if the log does
|
|
282
|
+
it "should NOT write the log message if the requested log does not have sufficient weight" do
|
|
211
283
|
Catamaran.logger.smart_log_level.should == Catamaran::LogLevel::INFO
|
|
212
284
|
# DEBUG is disabled
|
|
213
|
-
Catamaran.logger.should_not_receive( :
|
|
285
|
+
Catamaran.logger.should_not_receive( :log )
|
|
214
286
|
Catamaran.logger.debug( "Testing a DEBUG log" )
|
|
215
287
|
end
|
|
216
288
|
|
|
217
289
|
describe "#determine_path_and_opts_arguments" do
|
|
218
290
|
it "should return the correct path when one string parameter is specified" do
|
|
219
|
-
Catamaran.logger.send( :determine_path_and_opts_arguments, "
|
|
291
|
+
Catamaran.logger.send( :determine_path_and_opts_arguments, "mycompany.myrailsproject.app.models.User" ).should == [ "mycompany.myrailsproject.app.models.User", nil ]
|
|
220
292
|
end
|
|
221
293
|
|
|
222
294
|
it "should return the correct opts when one hash parameter is specified" do
|
|
@@ -224,19 +296,17 @@ describe Catamaran do
|
|
|
224
296
|
end
|
|
225
297
|
|
|
226
298
|
it "should return the correct path and opts when two parameters are specified" do
|
|
227
|
-
Catamaran.logger.send( :determine_path_and_opts_arguments, "
|
|
299
|
+
Catamaran.logger.send( :determine_path_and_opts_arguments, "mycompany.myrailsproject.app.models.User", {} ).should == [ "mycompany.myrailsproject.app.models.User", {} ]
|
|
228
300
|
end
|
|
229
301
|
end
|
|
230
302
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
Catamaran.logger.Company.Product.App.smart_log_level.should == Catamaran::LogLevel::INFO
|
|
239
|
-
end
|
|
303
|
+
it "should inherit the log level (via smart_log_level) from it's ancestors" do
|
|
304
|
+
Catamaran.logger.log_level = Catamaran::LogLevel::INFO
|
|
305
|
+
Catamaran.logger.com.mycompany.myrailsproject.app.models.log_level = Catamaran::LogLevel::ERROR
|
|
306
|
+
Catamaran.logger.com.mycompany.myrailsproject.app.controllers.log_level = Catamaran::LogLevel::WARN
|
|
307
|
+
Catamaran.logger.com.mycompany.myrailsproject.app.models.User.smart_log_level.should == Catamaran::LogLevel::ERROR
|
|
308
|
+
Catamaran.logger.com.mycompany.myrailsproject.app.controllers.UsersController.smart_log_level.should == Catamaran::LogLevel::WARN
|
|
309
|
+
Catamaran.logger.Company.Product.App.smart_log_level.should == Catamaran::LogLevel::INFO
|
|
240
310
|
end
|
|
241
311
|
|
|
242
312
|
context "when the log level is specified, the default is no longer used" do
|
|
@@ -246,5 +316,5 @@ describe Catamaran do
|
|
|
246
316
|
Catamaran.logger.smart_log_level.should == Catamaran::LogLevel::ERROR
|
|
247
317
|
end
|
|
248
318
|
end
|
|
249
|
-
end
|
|
250
|
-
end
|
|
319
|
+
end # ends describe Catamaran::Logger do
|
|
320
|
+
end # ends describe Catamaran 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.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jeano
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2013-12-
|
|
11
|
+
date: 2013-12-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A logging utility
|
|
14
14
|
email:
|