catamaran 0.5.0 → 0.6.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: ce160eae2640b8c7d690d9677b5440892b48dae1
4
- data.tar.gz: 70e6fe894ef0216d45e5e0f837b94deb9a912b20
3
+ metadata.gz: 5e6d25e6550c1bcba63f44167d3e53de5950a528
4
+ data.tar.gz: 76e8decccaa647af4a1ebf5622ecf0594d0b5a49
5
5
  SHA512:
6
- metadata.gz: a4ce49087602bed11ca7f627291829af5561ec6b21b0c46a1f7effac2b2f59ec8c1e34ad18ecc5e83e973c76e08b47efca2077fd55f2fe6685b9c84ea8a3c8b7
7
- data.tar.gz: 3e4a99d0e26290c1be952b84d3acdc7a4847885acc3192184133dd8cff07b269f036a82d137c29f5172fd49b3f94b24dbd1ae3656fd5a07a294af8ac1b41f127
6
+ metadata.gz: cf04c77d2d57455b5899a232dc364e939da2280301e02891096ec19c5ca254702269e3d80b6c2530ba515c7f423eaa1f4d3f7386b4f2cf796ed07336b7840cec
7
+ data.tar.gz: d36ab4e2705db71915e064ca6986bc09d3292f929ad557438c28f176513f5469485344fcf28bf4ffeb709dcc41b819166b5ef1bde3551ac38b3a3578205fe8da
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.4.0'
9
+ gem 'catamaran', '~> 0.6.0'
10
10
 
11
11
  Rails-related setup:
12
12
 
@@ -64,14 +64,14 @@ Other Ruby Examples
64
64
  -------------------
65
65
  require 'catamaran'
66
66
 
67
- Catamaran::LogLevel.default_log_level = Catamaran::LogLevel::DEBUG
67
+ Catamaran::LogLevel.default_log_level = Catamaran::LogLevel::TRACE
68
68
  Catamaran::Manager.formatter_class = Catamaran::Formatter::NoCallerFormatter
69
69
 
70
70
  class SecondRubyDemo
71
71
  LOGGER = Catamaran.logger( { :class => name(), :file => __FILE__ } )
72
72
 
73
73
  def run
74
- LOGGER.debug( "Sample DEBUG statement", { :line => __LINE__, :method => 'run'} ) if LOGGER.debug?
74
+ LOGGER.trace( "Sample TRACE statement", { :line => __LINE__, :method => 'run'} ) if LOGGER.trace?
75
75
  end
76
76
  end
77
77
 
@@ -79,7 +79,8 @@ Other Ruby Examples
79
79
  LOGGER = Catamaran.logger( "com.mycompany.ThirdRubyDemo", { :class => name(), :file => __FILE__ } )
80
80
 
81
81
  def run
82
- LOGGER.debug( "Sample DEBUG statement", { :line => __LINE__, :method => 'run'} ) if LOGGER.debug?
82
+ LOGGER.debug( "Sample DEBUG statement", { :line => __LINE__, :method => 'run' } ) if LOGGER.debug?
83
+ LOGGER.debug( "Sample DEBUG statement with backtrace option", { :line => __LINE__, :method => 'run', :backtrace => true } ) if LOGGER.debug?
83
84
  end
84
85
  end
85
86
 
@@ -88,8 +89,12 @@ Other Ruby Examples
88
89
 
89
90
  And the output
90
91
 
91
- DEBUG pid-2729 [2013-12-23 19:35:35:732] - Sample DEBUG statement (catamaran_ruby_demos.rb:21:in `SecondRubyDemo.run')
92
- DEBUG pid-2729 [2013-12-23 19:35:35:732] com.mycompany.ThirdRubyDemo - Sample DEBUG statement (catamaran_ruby_demos.rb:29:in `ThirdRubyDemo.run')
92
+ TRACE pid-4714 [2013-12-26 15:33:05:311] - Sample TRACE statement (catamaran_ruby_demos.rb:11:in `SecondRubyDemo.run')
93
+ DEBUG pid-4714 [2013-12-26 15:33:05:311] com.mycompany.ThirdRubyDemo - Sample DEBUG statement (catamaran_ruby_demos.rb:19:in `ThirdRubyDemo.run')
94
+ DEBUG pid-4714 [2013-12-26 15:33:05:311] com.mycompany.ThirdRubyDemo - Sample DEBUG statement with backtrace option (catamaran_ruby_demos.rb:20:in `ThirdRubyDemo.run') from:
95
+ catamaran_ruby_demos.rb:20:in `run'
96
+ catamaran_ruby_demos.rb:25:in `<main>'
97
+
93
98
 
94
99
 
95
100
  Inspiration
@@ -17,13 +17,24 @@ module Catamaran
17
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 )
18
18
  end
19
19
 
20
+ def self.construct_backtrace_info( opts )
21
+ if opts && opts[:backtrace] == true
22
+ msg = " from:\n#{caller(4).take(10).join("\n")}"
23
+ else
24
+ msg = ''
25
+ end
26
+
27
+ # Implicit return
28
+ msg
29
+ end
30
+
20
31
 
21
32
  def self.contruct_suffix_info( opts )
22
33
  msg = ''
23
34
 
24
35
  if opts
25
36
  if opts[:file]
26
- msg << "(#{opts[:file]}"
37
+ msg << " (#{opts[:file]}"
27
38
 
28
39
  if opts[:line]
29
40
  msg << ":#{opts[:line]}"
@@ -5,7 +5,7 @@ module Catamaran
5
5
 
6
6
  class CallerFormatter < BaseFormatter
7
7
  def self.construct_formatted_message( log_level, path, msg, opts )
8
- "#{base_construct_formatted_message( log_level, path, msg, opts )} (#{caller(3)[0]})"
8
+ "#{base_construct_formatted_message( log_level, path, msg, opts )} (#{caller(3)[0]})" + construct_backtrace_info( opts )
9
9
  end
10
10
  end
11
11
  end
@@ -5,12 +5,7 @@ module Catamaran
5
5
 
6
6
  class NoCallerFormatter < BaseFormatter
7
7
  def self.construct_formatted_message( log_level, path, msg, opts )
8
- suffix_info = contruct_suffix_info( opts )
9
- if suffix_info && suffix_info.length > 0
10
- base_construct_formatted_message( log_level, path, msg, opts ) + ' ' + suffix_info
11
- else
12
- base_construct_formatted_message( log_level, path, msg, opts )
13
- end
8
+ base_construct_formatted_message( log_level, path, msg, opts ) + contruct_suffix_info( opts ) + construct_backtrace_info( opts )
14
9
  end
15
10
  end
16
11
  end
@@ -4,26 +4,36 @@ 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 = 1080
8
- IO_LESS_CRITICAL_THAN_INFO = 2080
7
+ IO_LESS_CRITICAL_THAN_DEBUG = 2080
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
+ ALL = 100
15
+
16
+ TRACE = 2000
17
+ DEBUG = 3000
18
+ INFO = 4000
19
+ WARN = 5000
20
+ ERROR = 6000
21
+ SEVERE = 7000
22
+ FATAL = 8000
10
23
 
11
- TRACE = 1000
12
- DEBUG = 2000
13
- INFO = 3000
14
- WARN = 4000
15
- ERROR = 5000
16
- SEVERE = 6000
17
- FATAL = 7000
18
24
  IO = IO_LESS_CRITICAL_THAN_INFO
25
+ BACKTRACE = BACKTRACE_LESS_CRITICAL_THAN_INFO
26
+
19
27
 
20
-
21
28
 
22
29
  def self.reset
23
30
  @@default_log_level = INFO
24
31
 
25
32
  self.send( :remove_const, 'IO' ) if self.const_defined?( 'IO' )
26
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 )
27
37
  end
28
38
 
29
39
  self.reset()
@@ -70,6 +80,15 @@ module Catamaran
70
80
 
71
81
  def self.log_level_io
72
82
  IO
73
- end
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
+ end
74
93
  end
75
94
  end
@@ -65,7 +65,7 @@ module Catamaran
65
65
 
66
66
  def trace( msg, opts = nil )
67
67
  if trace?
68
- _write_to_log( LogLevel::TRACE, msg, opts )
68
+ _log( LogLevel::TRACE, msg, opts )
69
69
  end
70
70
  end
71
71
 
@@ -82,7 +82,7 @@ module Catamaran
82
82
 
83
83
  def debug( msg, opts = nil )
84
84
  if debug?
85
- _write_to_log( LogLevel::DEBUG, msg, opts )
85
+ _log( LogLevel::DEBUG, msg, opts )
86
86
  end
87
87
  end
88
88
 
@@ -100,7 +100,7 @@ module Catamaran
100
100
 
101
101
  def io( msg, opts = nil )
102
102
  if io?
103
- _write_to_log( LogLevel::IO, msg, opts )
103
+ _log( LogLevel::IO, msg, opts )
104
104
  end
105
105
  end
106
106
 
@@ -117,7 +117,7 @@ module Catamaran
117
117
 
118
118
  def info( msg, opts = nil )
119
119
  if info?
120
- _write_to_log( LogLevel::INFO, msg, opts )
120
+ _log( LogLevel::INFO, msg, opts )
121
121
  end
122
122
  end
123
123
 
@@ -134,7 +134,7 @@ module Catamaran
134
134
 
135
135
  def warn( msg, opts = nil )
136
136
  if warn?
137
- _write_to_log( LogLevel::WARN, msg, opts )
137
+ _log( LogLevel::WARN, msg, opts )
138
138
  end
139
139
  end
140
140
 
@@ -151,7 +151,7 @@ module Catamaran
151
151
 
152
152
  def error( msg, opts = nil )
153
153
  if error?
154
- _write_to_log( LogLevel::ERROR, msg, opts )
154
+ _log( LogLevel::ERROR, msg, opts )
155
155
  end
156
156
  end
157
157
 
@@ -168,7 +168,7 @@ module Catamaran
168
168
 
169
169
  def severe( msg, opts = nil )
170
170
  if severe?
171
- _write_to_log( LogLevel::SEVERE, msg, opts )
171
+ _log( LogLevel::SEVERE, msg, opts )
172
172
  end
173
173
  end
174
174
 
@@ -185,10 +185,21 @@ module Catamaran
185
185
 
186
186
  # def fatal( msg, opts = nil )
187
187
  # if fatal?
188
- # _write_to_log( LogLevel::FATAL, msg, opts )
188
+ # _log( LogLevel::FATAL, msg, opts )
189
189
  # end
190
190
  # end
191
191
 
192
+ ##
193
+ # Is backtrace-level logging currently enabled? (Special case)
194
+
195
+ def backtrace?
196
+ if self.smart_log_level() <= LogLevel::BACKTRACE
197
+ true
198
+ else
199
+ false
200
+ end
201
+ end
202
+
192
203
  ##
193
204
  # Usually get_logger is a reference to self, unless a path has been specified as a parameter
194
205
 
@@ -402,15 +413,23 @@ module Catamaran
402
413
 
403
414
 
404
415
  ##
405
- # All log statements eventually call _write_to_log
416
+ # All log statements eventually call _log
406
417
 
407
- def _write_to_log( log_level, msg, opts )
418
+ def _log( log_level, msg, opts )
408
419
  if self.specified_file || self.specified_class
409
420
  opts = {} unless opts
410
421
  opts[:file] = self.specified_file if self.specified_file
411
422
  opts[:class] = self.specified_class if self.specified_class
412
423
  end
413
424
 
425
+ if opts && opts[:backtrace] == true
426
+ # If backtrace is NOT enabled, then delete it from the options before it gets passed to the formatter
427
+ if !backtrace?
428
+ opts = opts.dup
429
+ opts.delete(:backtrace)
430
+ end
431
+ end
432
+
414
433
  formatted_msg = Manager.formatter_class.construct_formatted_message( log_level, self.path_to_s(), msg, opts )
415
434
  Outputter.write( formatted_msg )
416
435
  end
@@ -1,4 +1,4 @@
1
1
  module Catamaran
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
4
4
 
@@ -83,7 +83,7 @@ describe Catamaran do
83
83
  Catamaran::Manager.num_loggers.should == 1
84
84
  end
85
85
 
86
- it "should be that the IO log level is the same as IO_LESS_CRITICAL_THAN_INFO" do
86
+ it "should have an IO log level that corresponds to IO_LESS_CRITICAL_THAN_INFO" do
87
87
  Catamaran::LogLevel::IO.should == Catamaran::LogLevel::IO_LESS_CRITICAL_THAN_INFO
88
88
  end
89
89
  end
@@ -203,14 +203,14 @@ describe Catamaran do
203
203
 
204
204
  it "should write the log if the log has sufficient weight" do
205
205
  Catamaran.logger.smart_log_level.should == Catamaran::LogLevel::INFO
206
- Catamaran.logger.should_receive( :_write_to_log ).once
206
+ Catamaran.logger.should_receive( :_log ).once
207
207
  Catamaran.logger.info( "Testing an INFO log" )
208
208
  end
209
209
 
210
210
  it "should NOT write the log if the log does NOT have sufficient" do
211
211
  Catamaran.logger.smart_log_level.should == Catamaran::LogLevel::INFO
212
212
  # DEBUG is disabled
213
- Catamaran.logger.should_not_receive( :_write_to_log )
213
+ Catamaran.logger.should_not_receive( :_log )
214
214
  Catamaran.logger.debug( "Testing a DEBUG log" )
215
215
  end
216
216
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catamaran
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeano