catamaran 0.7.0 → 0.8.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: 0e807d462b178ce06016ad76babba6ba142928f9
4
- data.tar.gz: 240ed2615b1b49361f3c49ba5be63bf2a5edafa8
3
+ metadata.gz: dad20818493f3c8f96f0d942495f6a4cb40712e0
4
+ data.tar.gz: 79168eb79497446d8247b0c1a6b0d017365ea687
5
5
  SHA512:
6
- metadata.gz: 1214f644cbecf098a31703930f6dfe4aed9715faa88ffa7acfcc8dbc8759e69f14104ff6ce72baa8317f35376ae71a7dd41bce1aad194c53b130c4c76f2132eb
7
- data.tar.gz: 784259e5224043161d3b23bea3088e4f8328cd23b36feeabdebaf3f5edbde2b28d41588577aff6d41864f4935aaed8eeb24eeee225856dda61312842a988586d
6
+ metadata.gz: 30c7a5da926687402aecfbee909a3d1d6aef5f02c49ea4793e1b46891ecf1adda76845ab44a2f52060881c975908b71d14274cc3b9a71d07f237cdfca00812dd
7
+ data.tar.gz: 86295eff51d438edd6df7e28755c8447e6cd54180739ff4a76682888e69c9d7a97af4fc638492dfb2eba9712e0e9578a5bee9022a1667d8ad1fcad9f71fa6a1e
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.7.0'
9
+ gem 'catamaran', '~> 0.8.0'
10
10
 
11
11
  Rails-related setup:
12
12
 
@@ -16,78 +16,84 @@ Now modify `config/initializers/catamaran/development.rb` as needed
16
16
 
17
17
  Ruby Quickstart
18
18
  ---------------
19
- require 'catamaran'
19
+ ```ruby
20
+ require 'catamaran'
20
21
 
21
- class FirstRubyDemo
22
- LOGGER = Catamaran.logger( "FirstRubyDemo" )
22
+ class FirstRubyDemo
23
+ LOGGER = Catamaran.logger( "FirstRubyDemo" )
24
+ # or equivalently:
25
+ # LOGGER = Catamaran.logger.FirstRubyDemo
23
26
 
24
- def run
25
- LOGGER.warn( "Note that WARN messages are getting logged" ) if LOGGER.warn?
26
- LOGGER.trace( "Note that TRACE messages are NOT getting logged" ) if LOGGER.trace?
27
- end
28
- end
27
+ def run
28
+ LOGGER.notice( "Note that NOTICE messages are captured by default" ) if LOGGER.notice?
29
+ LOGGER.info( "Note that INFO messages are NOT captured by default" ) if LOGGER.info?
30
+ LOGGER.debug( "Note that DEBUG messages are NOT captured by default" ) if LOGGER.debug?
31
+ end
32
+ end
29
33
 
30
- FirstRubyDemo.new.run
34
+ FirstRubyDemo.new.run
35
+ ```
31
36
 
32
37
  And the output
33
38
 
34
- WARN pid-2729 [2013-12-23 19:35:35:732] FirstRubyDemo - Note that WARN messages are getting logged
39
+ NOTICE pid-2729 [2013-12-23 19:35:35:732] FirstRubyDemo - Note that NOTICE messages are getting captured by default
35
40
 
36
41
 
37
42
  Rails Quickstart
38
43
  ----------------
39
44
 
40
- class PagesController < ApplicationController
41
- LOGGER = Catamaran.logger.com.mycompany.myrailsapp.app.controllers.PagesController
42
-
43
- def index
44
- # LOGGER.io methods are reserved for logs related to entering and returning from methods
45
- LOGGER.io "Entering with params = #{params}" if LOGGER.io?
46
-
47
- LOGGER.trace "This is my TRACE log" if LOGGER.trace?
48
- LOGGER.debug "This is my DEBUG log" if LOGGER.debug?
49
- LOGGER.info "This is my INFO log" if LOGGER.info?
50
- LOGGER.warn "This is my WARN log" if LOGGER.warn?
51
- LOGGER.error "This is my ERROR log" if LOGGER.error?
45
+ ```ruby
46
+ class PagesController < ApplicationController
47
+ LOGGER = Catamaran.logger.com.mycompany.myrailsapp.app.controllers.PagesController
52
48
 
53
- LOGGER.io "Returning" if LOGGER.io?
54
- end
55
- end
49
+ def index
50
+ LOGGER.debug "Entering with params = #{params}" if LOGGER.debug?
51
+ end
52
+ end
53
+ ```
56
54
 
57
55
  Load the `index` page and check out your `development.log` file
58
56
 
59
57
  ### Sample log entry (in your development.log file)
60
- IO pid-86000 [2013-12-17 17:26:39:176] pany.myrailsapp.app.controllers.PagesController - Entering with params = {"controller"=>"pages", "action"=>"index"} (`/myrailsapp/app/controllers/pages_controller.rb:7`:in `index`)
58
+ DEBUG pid-86000 [2013-12-17 17:26:39:176] pany.myrailsapp.app.controllers.PagesController - Entering with params = {"controller"=>"pages", "action"=>"index"} (`/myrailsapp/app/controllers/pages_controller.rb:7`:in `index`)
59
+
60
+ Log Levels
61
+ ----------
62
+ Available log levels: `TRACE` (verbose and trivial log messages), `DEBUG`, `INFO`, `NOTICE`, `WARN`, `ERROR`, `SEVERE` (logs related to very serious error conditions)
63
+
64
+ The `NOTICE` log level severity is the default. Any logs with `NOTICE` or higher severity will be captured.
61
65
 
62
66
 
63
67
  Other Ruby Examples
64
68
  -------------------
65
- require 'catamaran'
69
+ ```ruby
70
+ require 'catamaran'
66
71
 
67
- Catamaran.logger.log_level = Catamaran::LogLevel::INFO
68
- Catamaran.logger.backtrace_log_level = Catamaran::LogLevel::ERROR
69
- Catamaran::Manager.formatter_class = Catamaran::Formatter::NoCallerFormatter
72
+ Catamaran.logger.log_level = Catamaran::LogLevel::INFO
73
+ Catamaran.logger.backtrace_log_level = Catamaran::LogLevel::ERROR
74
+ Catamaran::Manager.formatter_class = Catamaran::Formatter::NoCallerFormatter
70
75
 
71
- class SecondRubyDemo
72
- LOGGER = Catamaran.logger( { :class => name(), :file => __FILE__ } )
76
+ class SecondRubyDemo
77
+ LOGGER = Catamaran.logger( { :class => name(), :file => __FILE__ } )
73
78
 
74
- def run
75
- LOGGER.info( "Sample INFO statement", { :line => __LINE__, :method => 'run'} ) if LOGGER.info?
76
- end
77
- end
79
+ def run
80
+ LOGGER.info( "Sample INFO statement", { :line => __LINE__, :method => 'run'} ) if LOGGER.info?
81
+ end
82
+ end
78
83
 
79
- class ThirdRubyDemo
80
- LOGGER = Catamaran.logger( "com.mycompany.ThirdRubyDemo", { :class => name(), :file => __FILE__ } )
84
+ class ThirdRubyDemo
85
+ LOGGER = Catamaran.logger( "com.mycompany.ThirdRubyDemo", { :class => name(), :file => __FILE__ } )
81
86
 
82
- def run
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?
86
- end
87
- end
87
+ def run
88
+ LOGGER.warn( "Sample WARN statement", { :line => __LINE__, :method => 'run' } )
89
+ LOGGER.warn( "Sample WARN statement with backtrace option", { :line => __LINE__, :method => 'run', :backtrace => true } )
90
+ LOGGER.error( "Sample ERROR statement with backtrace option", { :line => __LINE__, :method => 'run', :backtrace => true } )
91
+ end
92
+ end
88
93
 
89
- SecondRubyDemo.new.run
90
- ThirdRubyDemo.new.run
94
+ SecondRubyDemo.new.run
95
+ ThirdRubyDemo.new.run
96
+ ```
91
97
 
92
98
  And the output
93
99
 
@@ -115,111 +121,122 @@ I'm looking for a logging utility that:
115
121
  * http://stackoverflow.com/questions/462651/rails-logger-format-string-configuration
116
122
  * http://stackoverflow.com/questions/3654827/logging-in-rails-app
117
123
  * http://stackoverflow.com/questions/11991967/rails-log-too-verbose
124
+ * http://www.ietf.org/rfc/rfc3164.txt
118
125
 
119
126
  Performance Considerations
120
127
  --------------------------
121
128
 
122
129
  ### With or without `if LOGGER.debug?`
123
- require 'catamaran'
124
- require 'benchmark'
130
+ ```ruby
131
+ require 'catamaran'
132
+ require 'benchmark'
125
133
 
126
- Catamaran::LogLevel.default_log_level = Catamaran::LogLevel::INFO
127
- Catamaran::Manager.formatter_class = Catamaran::Formatter::NoCallerFormatter
128
- Catamaran::Manager.stderr = false
129
-
130
- class CatamaranPerformanceTest
131
- LOGGER = Catamaran.logger( "CatamaranPerformanceTest" )
132
-
133
- # NOTE that the log level for this test is set to INFO,
134
- # so 'warn' logs are enabled and 'debug' logs are disabled
135
-
136
- n = 500000
137
- Benchmark.bm(7) do |x|
138
- x.report("warn WITHOUT if LOGGER.warn? ") {
139
- n.times do |i|
140
- LOGGER.warn "Based on the current log level, this log is being captured"
141
- end
142
- }
143
- x.report("warn WITH if LOGGER.warn? ") {
144
- n.times do |i|
145
- LOGGER.warn "Based on the current log level, this log is being captured" if LOGGER.warn?
146
- end
147
- }
134
+ Catamaran::LogLevel.default_log_level = Catamaran::LogLevel::INFO
135
+ Catamaran::Manager.formatter_class = Catamaran::Formatter::NoCallerFormatter
136
+ Catamaran::Manager.stderr = false
137
+
138
+ class CatamaranPerformanceTest
139
+ LOGGER = Catamaran.logger( "CatamaranPerformanceTest" )
140
+
141
+ # NOTE that the log level for this test is set to INFO,
142
+ # so 'warn' logs are enabled and 'debug' logs are disabled
143
+
144
+ n = 500000
145
+ Benchmark.bm(7) do |x|
146
+ x.report("warn WITHOUT if LOGGER.warn? ") {
147
+ n.times do |i|
148
+ LOGGER.warn "Based on the current log level, this log is being captured"
149
+ end
150
+ }
151
+ x.report("warn WITH if LOGGER.warn? ") {
152
+ n.times do |i|
153
+ LOGGER.warn "Based on the current log level, this log is being captured" if LOGGER.warn?
154
+ end
155
+ }
156
+ end
157
+
158
+ Benchmark.bm(7) do |x|
159
+ x.report("debug WITHOUT if LOGGER.debug?") {
160
+ n.times do |i|
161
+ LOGGER.debug "Based on the current log level, this log is NOT being captured"
162
+ end
163
+ }
164
+ x.report("debug WITH if LOGGER.debug? ") {
165
+ n.times do |i|
166
+ LOGGER.debug "Based on the current log level, this log is NOT being captured" if LOGGER.debug?
148
167
  end
168
+ }
169
+ end
170
+
171
+ end
149
172
 
150
- Benchmark.bm(7) do |x|
151
- x.report("debug WITHOUT if LOGGER.debug?") {
152
- n.times do |i|
153
- LOGGER.debug "Based on the current log level, this log is NOT being captured"
154
- end
155
- }
156
- x.report("debug WITH if LOGGER.debug? ") {
157
- n.times do |i|
158
- LOGGER.debug "Based on the current log level, this log is NOT being captured" if LOGGER.debug?
159
- end
160
- }
161
- end
162
-
163
- end
164
-
165
- # user system total real
166
- # warn WITHOUT if LOGGER.warn? 6.940000 0.010000 6.950000 ( 6.950691)
167
- # warn WITH if LOGGER.warn? 7.650000 0.000000 7.650000 ( 7.658004)
168
- # user system total real
169
- # debug WITHOUT if LOGGER.debug? 0.660000 0.010000 0.670000 ( 0.665775)
170
- # debug WITH if LOGGER.debug? 0.560000 0.010000 0.570000 ( 0.574397)
173
+ # user system total real
174
+ # warn WITHOUT if LOGGER.warn? 6.940000 0.010000 6.950000 ( 6.950691)
175
+ # warn WITH if LOGGER.warn? 7.650000 0.000000 7.650000 ( 7.658004)
176
+ # user system total real
177
+ # debug WITHOUT if LOGGER.debug? 0.660000 0.010000 0.670000 ( 0.665775)
178
+ # debug WITH if LOGGER.debug? 0.560000 0.010000 0.570000 ( 0.574397)
179
+ ```
171
180
 
172
181
  #### Summary
173
182
 
174
- * For log messages that are usually *disabled* in the production environment ( TRACE, DEBUG ), it's generally better to invoke the log only after confirming that the log level is enabled
183
+ * For log messages that are usually *disabled* in the production environment ( TRACE, DEBUG, INFO ), it's generally better to invoke the log only after confirming that the log level is enabled
175
184
 
176
185
  ex:
177
186
 
178
- LOGGER.trace "This is a TRACE log" if LOGGER.trace?
179
- LOGGER.debug "This is a DEBUG log" if LOGGER.debug?
187
+ ```ruby
188
+ LOGGER.trace "This is a TRACE log" if LOGGER.trace?
189
+ LOGGER.debug "This is a DEBUG log" if LOGGER.debug?
190
+ LOGGER.info "This is a INFO log" if LOGGER.info?
191
+ ```
180
192
 
181
- * For log messages that are usually *enabled* in the production environment ( INFO, WARN, ERROR, SEVERE ), it's generally better to invoke the log WITHOUT first testing the log level
193
+ * 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
182
194
 
183
195
  ex:
184
196
 
185
- LOGGER.info "This is a INFO log"
186
- LOGGER.warn "This is a WARN log"
187
- LOGGER.error "This is a ERROR log"
197
+ ```ruby
198
+ LOGGER.notice "This is a NOTICE log"
199
+ LOGGER.warn "This is a WARN log"
200
+ LOGGER.error "This is a ERROR log"
201
+ LOGGER.severe "This is a SEVERE log"
202
+ ```
188
203
 
189
204
  ### NoCallerFormatter vs CallerFormatter
190
205
 
191
- require 'catamaran'
192
- require 'benchmark'
193
-
194
- Catamaran::Manager.stderr = false
195
-
196
- class CatamaranPerformanceTest
197
- LOGGER = Catamaran.logger( "CatamaranPerformanceTest" )
198
-
199
- n = 500000
200
- Benchmark.bm(7) do |x|
201
- Catamaran::Manager.formatter_class = Catamaran::Formatter::NoCallerFormatter
202
-
203
- x.report("Using NoCallerFormatter") {
204
- n.times do |i|
205
- LOGGER.error "This is a ERROR log"
206
- end
207
- }
208
-
209
- Catamaran::Manager.formatter_class = Catamaran::Formatter::CallerFormatter
210
-
211
- x.report("Using CallerFormatter") {
212
- n.times do |i|
213
- LOGGER.error "This is a ERROR log"
214
- end
215
- }
206
+ ```ruby
207
+ require 'catamaran'
208
+ require 'benchmark'
209
+
210
+ Catamaran::Manager.stderr = false
211
+
212
+ class CatamaranPerformanceTest
213
+ LOGGER = Catamaran.logger( "CatamaranPerformanceTest" )
214
+
215
+ n = 500000
216
+ Benchmark.bm(7) do |x|
217
+ Catamaran::Manager.formatter_class = Catamaran::Formatter::NoCallerFormatter
218
+
219
+ x.report("Using NoCallerFormatter") {
220
+ n.times do |i|
221
+ LOGGER.error "This is a ERROR log"
222
+ end
223
+ }
224
+
225
+ Catamaran::Manager.formatter_class = Catamaran::Formatter::CallerFormatter
226
+
227
+ x.report("Using CallerFormatter") {
228
+ n.times do |i|
229
+ LOGGER.error "This is a ERROR log"
216
230
  end
217
- end
218
-
231
+ }
232
+ end
233
+ end
234
+
219
235
 
220
- # user system total real
221
- # Using NoCallerFormatter 6.850000 0.010000 6.860000 ( 6.864649)
222
- # Using CallerFormatter 14.700000 0.150000 14.850000 ( 14.867592)
236
+ # user system total real
237
+ # Using NoCallerFormatter 6.850000 0.010000 6.860000 ( 6.864649)
238
+ # Using CallerFormatter 14.700000 0.150000 14.850000 ( 14.867592)
239
+ ```
223
240
 
224
241
  #### Summary
225
242
 
@@ -246,7 +263,8 @@ Ideas around what's next
246
263
  * Something like `filter_parameter_logging`
247
264
  * Color support
248
265
  * Log rotation
249
- * Heroku support
266
+ * Heroku support (https://blog.heroku.com/archives/2013/7/15/logging-on-heroku)
267
+ * Buffered file I/O considerations
250
268
 
251
269
 
252
270
 
@@ -4,7 +4,7 @@ module Catamaran
4
4
  # Construct a properly formatted log message based
5
5
 
6
6
  class BaseFormatter
7
- def self.base_construct_formatted_message( log_level, path, msg, opts )
7
+ def self.base_construct_formatted_message( severity, path, msg, opts )
8
8
  # Truncate on the left
9
9
  if path.length > 47
10
10
  updated_path = path.dup[-47,47]
@@ -14,7 +14,7 @@ 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.to_s(log_level), updated_path )
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 )
18
18
  end
19
19
 
20
20
  def self.construct_backtrace_info( opts )
@@ -4,18 +4,24 @@ module Catamaran
4
4
  # If that's too verbose, the level can be changed to IO_LESS_CRITICAL_THAN_DEBUG and logger.io messages won't be
5
5
  # visible unless the log level is set to TRACE.
6
6
  # See development.rb for an example of this
7
- IO_LESS_CRITICAL_THAN_DEBUG = 2080
8
- IO_LESS_CRITICAL_THAN_INFO = 3080
7
+ IO_LESS_CRITICAL_THAN_DEBUG = 2780
8
+ IO_LESS_CRITICAL_THAN_INFO = 3780
9
+ IO_LESS_CRITICAL_THAN_NOTICE = 4780
9
10
 
10
11
  ALL = 100
11
12
 
12
13
  TRACE = 2000
13
14
  DEBUG = 3000
14
15
  INFO = 4000
15
- WARN = 5000
16
- ERROR = 6000
17
- SEVERE = 7000
18
- FATAL = 8000
16
+ # Adding notice per http://www.faqs.org/rfcs/rfc3164.html
17
+ NOTICE = 5000
18
+ WARN = 6000
19
+ ERROR = 7000
20
+ SEVERE = 8000 # versus critical
21
+
22
+ # FATAL is currently unused. In logger.rb you can see the fatal-related methods are commented out
23
+ FATAL = 9000 # versus alert
24
+ # versus emergency
19
25
 
20
26
  IO = IO_LESS_CRITICAL_THAN_INFO
21
27
 
@@ -27,29 +33,31 @@ module Catamaran
27
33
  self.reset()
28
34
 
29
35
 
30
- def self.to_s( log_level )
31
- case log_level
36
+ def self.severity_to_s( severity )
37
+ case severity
32
38
  when TRACE
33
- retval = 'TRACE'
39
+ 'TRACE'
34
40
  when DEBUG
35
- retval = 'DEBUG'
41
+ 'DEBUG'
36
42
  when INFO
37
- retval = 'INFO'
43
+ 'INFO'
44
+ when NOTICE
45
+ 'NOTICE'
38
46
  when WARN
39
- retval = 'WARN'
47
+ 'WARN'
40
48
  when ERROR
41
- retval = 'ERROR'
49
+ 'ERROR'
42
50
  when SEVERE
43
- retval = 'SEVERE'
51
+ 'SEVERE'
44
52
  when FATAL
45
- retval = 'FATAL'
53
+ 'FATAL'
46
54
  when IO_LESS_CRITICAL_THAN_INFO
47
- retval = 'IO'
55
+ 'IO'
48
56
  when IO_LESS_CRITICAL_THAN_DEBUG
49
- retval = 'IO'
57
+ 'IO'
58
+ else
59
+ 'UNKNOWN'
50
60
  end
51
-
52
- retval
53
61
  end
54
62
 
55
63
  def self.log_level_io=( value )
@@ -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::INFO
18
+ retval = Catamaran::LogLevel::NOTICE
19
19
  else
20
20
  recursive = opts[:recursive]
21
21
  if recursive == true
@@ -202,6 +202,23 @@ module Catamaran
202
202
  end
203
203
  end
204
204
 
205
+ ##
206
+ # Is notice-level logging currently enabled?
207
+
208
+ def notice?
209
+ if self.smart_log_level() <= LogLevel::NOTICE
210
+ true
211
+ else
212
+ false
213
+ end
214
+ end
215
+
216
+ def notice( msg, opts = nil )
217
+ if notice?
218
+ log( LogLevel::NOTICE, msg, opts )
219
+ end
220
+ end
221
+
205
222
  ##
206
223
  # Is warn-level logging currently enabled?
207
224
 
@@ -489,7 +506,7 @@ module Catamaran
489
506
  ##
490
507
  # All log statements eventually call log
491
508
 
492
- def log( log_level, msg, opts )
509
+ def log( severity, msg, opts )
493
510
 
494
511
  if self.specified_file || self.specified_class
495
512
  opts = {} unless opts
@@ -502,10 +519,10 @@ module Catamaran
502
519
 
503
520
  # If the specified log message has a level that's
504
521
  # 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?
522
+ Catamaran.debugging( "Catamaran::Logger#initialize() - Considering a backtrace: severity = #{severity}, backtrace_log_level = #{_smart_backtrace_log_level}" ) if Catamaran.debugging?
506
523
 
507
524
 
508
- if log_level >= _smart_backtrace_log_level
525
+ if severity >= _smart_backtrace_log_level
509
526
  # no-op -- display the backtrace
510
527
  else
511
528
  # overwrite opts with a new value
@@ -520,13 +537,13 @@ module Catamaran
520
537
  end
521
538
 
522
539
  # Implicit return
523
- Outputter.write( _format_msg( log_level, msg, opts ) )
540
+ Outputter.write( _format_msg( severity, msg, opts ) )
524
541
  end
525
542
 
526
543
 
527
- def _format_msg( log_level, msg, opts )
544
+ def _format_msg( severity, msg, opts )
528
545
  # Implicit return
529
- Manager.formatter_class.construct_formatted_message( log_level, self.path_to_s(), msg, opts )
546
+ Manager.formatter_class.construct_formatted_message( severity, self.path_to_s(), msg, opts )
530
547
  end
531
548
 
532
549
  ##
@@ -1,4 +1,4 @@
1
1
  module Catamaran
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.0'
3
3
  end
4
4
 
@@ -81,8 +81,8 @@ describe Catamaran do
81
81
  end
82
82
 
83
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
84
+ it "should have a log level set to NOTICE" do
85
+ Catamaran.logger.log_level.should == Catamaran::LogLevel::NOTICE
86
86
  end
87
87
 
88
88
  it "should have a backtrace log level set to WARN" do
@@ -96,7 +96,7 @@ describe Catamaran do
96
96
  end
97
97
 
98
98
 
99
- it "should have a log level set to INFO" do
99
+ it "should have an empty log level" do
100
100
  @non_root_logger.log_level.should be_nil
101
101
  end
102
102
 
@@ -104,8 +104,8 @@ describe Catamaran do
104
104
  @non_root_logger.backtrace_log_level.should be_nil
105
105
  end
106
106
 
107
- it "should have a smart log level set to INFO" do
108
- @non_root_logger.smart_log_level.should == Catamaran::LogLevel::INFO
107
+ it "should have a smart log level set to NOTICE" do
108
+ @non_root_logger.smart_log_level.should == Catamaran::LogLevel::NOTICE
109
109
  end
110
110
 
111
111
  it "should have a smart backtrace log level set to WARN" do
@@ -126,12 +126,12 @@ describe Catamaran do
126
126
 
127
127
  context "after a (soft) reset" do
128
128
  describe "the Root Logger" do
129
- it "should have a log level of INFO" do
129
+ it "should have a log level of NOTICE" do
130
130
  logger = Catamaran.logger
131
131
  logger.log_level = Catamaran::LogLevel::ERROR
132
132
  logger.log_level.should == Catamaran::LogLevel::ERROR
133
133
  Catamaran::Manager.reset
134
- logger.log_level.should == Catamaran::LogLevel::INFO
134
+ logger.log_level.should == Catamaran::LogLevel::NOTICE
135
135
  end
136
136
 
137
137
  it "should have a backtrace log level of WARN" do
@@ -166,13 +166,13 @@ describe Catamaran do
166
166
  end
167
167
 
168
168
  context "after a hard reset" do
169
- it "should have a default log level of INFO" do
169
+ it "should have a default log level of NOTICE" do
170
170
  logger = Catamaran.logger
171
- logger.log_level.should == Catamaran::LogLevel::INFO
171
+ logger.log_level.should == Catamaran::LogLevel::NOTICE
172
172
  logger.log_level = Catamaran::LogLevel::ERROR
173
173
  logger.log_level.should == Catamaran::LogLevel::ERROR
174
174
  Catamaran::Manager.hard_reset
175
- logger.log_level.should == Catamaran::LogLevel::INFO
175
+ logger.log_level.should == Catamaran::LogLevel::NOTICE
176
176
  end
177
177
 
178
178
  it "should reset the number of loggers to 1" do
@@ -222,7 +222,7 @@ describe Catamaran do
222
222
  Catamaran.logger.debug( "message", { :backtrace => true } ) if Catamaran.logger.debug?
223
223
  end
224
224
 
225
- it "should NOT capture a backtrace when the backtrace_log_level is greater than the level of the log" do
225
+ it "should NOT capture a backtrace when the backtrace_log_level is greater than the severity of the log" do
226
226
  logger = Catamaran.logger
227
227
  logger.log_level = Catamaran::LogLevel::TRACE
228
228
  logger.backtrace_log_level = Catamaran::LogLevel::WARN
@@ -259,9 +259,9 @@ describe Catamaran do
259
259
  end
260
260
 
261
261
  it "should inherit the log level from the root logger as needed" do
262
- Catamaran.logger.smart_log_level.should == Catamaran::LogLevel::INFO
262
+ root_log_level = Catamaran.logger.smart_log_level
263
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
264
+ Catamaran.logger.com.mycompany.myrailsproject.app.models.User.smart_log_level.should == root_log_level
265
265
  end
266
266
 
267
267
  it "should have a nil log_level unless explicitly set" do
@@ -273,17 +273,16 @@ describe Catamaran do
273
273
  Catamaran.logger.whatever.smart_log_level.should_not be_nil
274
274
  end
275
275
 
276
- it "should write the log message if the requested log does not have sufficient weight" do
277
- Catamaran.logger.smart_log_level.should == Catamaran::LogLevel::INFO
276
+ it "should write the log message if the requested log does have sufficient severity" do
277
+ Catamaran.logger.smart_log_level.should <= Catamaran::LogLevel::NOTICE
278
278
  Catamaran.logger.should_receive( :log ).once
279
- Catamaran.logger.info( "Testing an INFO log" )
279
+ Catamaran.logger.notice( "A NOTICE log should be received" )
280
280
  end
281
281
 
282
- it "should NOT write the log message if the requested log does not have sufficient weight" do
283
- Catamaran.logger.smart_log_level.should == Catamaran::LogLevel::INFO
284
- # DEBUG is disabled
282
+ it "should NOT write the log message if the requested log does not have sufficient severity" do
283
+ Catamaran.logger.smart_log_level.should > Catamaran::LogLevel::DEBUG
285
284
  Catamaran.logger.should_not_receive( :log )
286
- Catamaran.logger.debug( "Testing a DEBUG log" )
285
+ Catamaran.logger.debug( "And INFO log should NOT be received" )
287
286
  end
288
287
 
289
288
  describe "#determine_path_and_opts_arguments" do
@@ -310,11 +309,25 @@ describe Catamaran do
310
309
  end
311
310
 
312
311
  context "when the log level is specified, the default is no longer used" do
313
- it "should be " do
314
- Catamaran.logger.smart_log_level.should == Catamaran::LogLevel::INFO
312
+ it "should makeuse of the specified log level rather than the inherited one" do
313
+ initial_log_level = Catamaran.logger.smart_log_level
315
314
  Catamaran.logger.log_level = Catamaran::LogLevel::ERROR
315
+ initial_log_level.should_not == Catamaran.logger.smart_log_level
316
316
  Catamaran.logger.smart_log_level.should == Catamaran::LogLevel::ERROR
317
317
  end
318
318
  end
319
319
  end # ends describe Catamaran::Logger do
320
+
321
+ describe Catamaran::LogLevel do
322
+ describe ".severity_to_s" do
323
+ it "should be able to convert a numeric log level into a string" do
324
+ Catamaran::LogLevel.severity_to_s( Catamaran::LogLevel::NOTICE ).should == 'NOTICE'
325
+ end
326
+
327
+ it "should be able to handle IO log levels" do
328
+ Catamaran::LogLevel.severity_to_s( Catamaran::LogLevel::IO_LESS_CRITICAL_THAN_INFO ).should == 'IO'
329
+ Catamaran::LogLevel.severity_to_s( Catamaran::LogLevel::IO_LESS_CRITICAL_THAN_DEBUG ).should == 'IO'
330
+ end
331
+ end
332
+ end
320
333
  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.7.0
4
+ version: 0.8.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-27 00:00:00.000000000 Z
11
+ date: 2014-01-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A logging utility
14
14
  email: