catamaran 1.0.0 → 2.0.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: 1ceef3f519f51532217eaddf8223b1afb6ec5ec6
4
- data.tar.gz: 58c77f78b0f793460d6a5facce4de971ebcea7fd
3
+ metadata.gz: a7b2c5c9d0ea8b6039c9b7bc454f66f07b064541
4
+ data.tar.gz: 966f7e9d3572846d188aae5deed8b1d8e2625e7a
5
5
  SHA512:
6
- metadata.gz: bd1696544420f5a8ed29e30b28704687cff1d7fd1b4d8dfa6f636c68e37d1af809f76a6f261a5daace9bf9b0a657e74a16193d6f9dee6322d29be0cd061b6135
7
- data.tar.gz: 5dae71064d293c2b16c8f2d1962a60aaf4cbc8e25c101b6dc8133fea9f775f13dadbc879e995bbfa3d2800a4def917fc34d70843fbb8107cd10d0d1844e24c67
6
+ metadata.gz: 9626247cabacf4e5497f30c4ddf2569813e4f1cee7434a0c61d0e4b4f3187de8d4fb8cbe99bbb2613177efbcebc10b3509bbd86a3f50171c585685563a9832df
7
+ data.tar.gz: 6789d578205007d3fba391a95919ed1a86a84f281d6b3944c4a78a6b4e546332e5dde76658df4a4387d9eff428706f2e900419b43fc69dfa52eba83ef2a4e1ad
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', '~> 1.0.0'
9
+ gem 'catamaran', '~> 2.0.0'
10
10
 
11
11
  Rails-related setup:
12
12
 
@@ -17,14 +17,13 @@ Now modify `config/initializers/catamaran/development.rb` as needed
17
17
  Ruby Quickstart
18
18
  ---------------
19
19
  ```ruby
20
- require 'catamaran'
21
20
 
22
- class FirstRubyDemo
23
- LOGGER = Catamaran.logger( "com.mytld.FirstRubyDemo" )
21
+ class WorkingWithCatamaran
22
+ LOGGER = Catamaran.logger( "com.mytld.WorkingWithCatamaran" )
24
23
  # or equivalently:
25
- # LOGGER = Catamaran.logger.com.mytld.FirstRubyDemo
24
+ # LOGGER = Catamaran.logger.com.mytld.WorkingWithCatamaran
26
25
 
27
- def run
26
+ def demonstrating_log_levels
28
27
  # Disabled by default
29
28
  LOGGER.trace( "TRACE logs are NOT captured by default" ) if LOGGER.trace?
30
29
  LOGGER.debug( "DEBUG logs are NOT captured by default" ) if LOGGER.debug?
@@ -32,24 +31,67 @@ class FirstRubyDemo
32
31
 
33
32
  # Enabled by default
34
33
  LOGGER.notice( "NOTICE logs are captured by default" )
35
- LOGGER.warn( "WARN logs are captured by default" )
34
+ LOGGER.warn( "WARN logs are captured by default" )
36
35
  LOGGER.error( "ERROR logs are captured by default" )
37
36
  LOGGER.severe( "SEVERE logs are captured by default" )
38
37
  LOGGER.fatal( "FATAL logs are captured by default" )
39
38
  end
39
+
40
+ def using_the_caller
41
+ # Enable the caller (it's disabled by default)
42
+ Catamaran::Manager.formatter_caller_enabled = true
43
+
44
+ LOGGER.notice( "The caller will append log location info to this message" )
45
+ LOGGER.notice( "If the user specifies the :file, :line, AND :method, the caller will NOT get invoked", { :file => __FILE__, :line => __LINE__, :method => 'run' } )
46
+ LOGGER.notice( "To prove the caller is not used, we can put dummy data in and see that it's being used instead", { :file => 'just_kidding.rb', :line => 123456789, :method => 'whatever' } )
47
+
48
+ # Turn it back off
49
+ Catamaran::Manager.formatter_caller_enabled = false
50
+ end
51
+
52
+ def changing_the_log_level
53
+ # Note that the log level can be changed
54
+ Catamaran.logger.log_level = Catamaran::LogLevel::DEBUG
55
+ Catamaran::Manager.forget_cached_log_levels()
56
+
57
+ LOGGER.trace( "TRACE logs are STILL NOT captured" ) if LOGGER.trace?
58
+ LOGGER.debug( "Now DEBUG messages should show up" ) if LOGGER.debug?
59
+ end
60
+
61
+ def displaying_backtrace_information
62
+ Catamaran.logger.log_level = Catamaran::LogLevel::NOTICE
63
+ Catamaran.logger.backtrace_log_level = Catamaran::LogLevel::ERROR
64
+ Catamaran::Manager.forget_cached_log_levels()
65
+
66
+ LOGGER.debug( "Sample DEBUG statement with backtrace requested", { :backtrace => true } )
67
+ LOGGER.warn( "Sample WARN statement with backtrace requested", { :backtrace => true } )
68
+ LOGGER.error( "Sample ERROR statement with backtrace requested", { :backtrace => true } )
69
+ end
40
70
  end
41
71
 
42
- FirstRubyDemo.new.run
72
+ working_with_catamaran = WorkingWithCatamaran.new
73
+ working_with_catamaran.demonstrating_log_levels
74
+ working_with_catamaran.using_the_caller
75
+ working_with_catamaran.changing_the_log_level
76
+ working_with_catamaran.displaying_backtrace_information
43
77
  ```
44
78
 
45
79
  And the output
46
80
 
47
81
  ```
48
- NOTICE pid-23773 [2014-01-01 13:09:47:551] com.mytld.FirstRubyDemo - NOTICE logs are captured by default
49
- WARN pid-23773 [2014-01-01 13:09:47:551] com.mytld.FirstRubyDemo - WARN logs are captured by default
50
- ERROR pid-23773 [2014-01-01 13:09:47:551] com.mytld.FirstRubyDemo - ERROR logs are captured by default
51
- SEVERE pid-23773 [2014-01-01 13:09:47:551] com.mytld.FirstRubyDemo - SEVERE logs are captured by default
52
- FATAL pid-23773 [2014-01-01 13:09:47:551] com.mytld.FirstRubyDemo - FATAL logs are captured by default
82
+ NOTICE pid-28828 [2014-01-04 15:42:18:664] com.mytld.WorkingWithCatamaran - NOTICE logs are captured by default
83
+ WARN pid-28828 [2014-01-04 15:42:18:664] com.mytld.WorkingWithCatamaran - WARN logs are captured by default
84
+ ERROR pid-28828 [2014-01-04 15:42:18:664] com.mytld.WorkingWithCatamaran - ERROR logs are captured by default
85
+ SEVERE pid-28828 [2014-01-04 15:42:18:664] com.mytld.WorkingWithCatamaran - SEVERE logs are captured by default
86
+ FATAL pid-28828 [2014-01-04 15:42:18:664] com.mytld.WorkingWithCatamaran - FATAL logs are captured by default
87
+ NOTICE pid-28828 [2014-01-04 15:42:18:664] com.mytld.WorkingWithCatamaran - The caller will append log location info to this message (working_with_catamaran.rb:27:in `using_the_caller')
88
+ NOTICE pid-28828 [2014-01-04 15:42:18:664] com.mytld.WorkingWithCatamaran - If the user specifies the :file, :line, AND :method, the caller will NOT get invoked (working_with_catamaran.rb:28:in `run')
89
+ NOTICE pid-28828 [2014-01-04 15:42:18:664] com.mytld.WorkingWithCatamaran - To prove the caller is not used, we can put dummy data in and see that it's being used instead (just_kidding.rb:123456789:in `whatever')
90
+ DEBUG pid-28828 [2014-01-04 15:42:18:664] com.mytld.WorkingWithCatamaran - Now DEBUG messages should show up
91
+ WARN pid-28828 [2014-01-04 15:42:18:664] com.mytld.WorkingWithCatamaran - Sample WARN statement with backtrace requested
92
+ ERROR pid-28828 [2014-01-04 15:42:18:664] com.mytld.WorkingWithCatamaran - Sample ERROR statement with backtrace requested from:
93
+ working_with_catamaran.rb:51:in `displaying_backtrace_information'
94
+ working_with_catamaran.rb:59:in `<main>'
53
95
  ```
54
96
 
55
97
 
@@ -79,49 +121,6 @@ Available log levels: `TRACE` (verbose and trivial log messages), `DEBUG`, `INF
79
121
  The `NOTICE` log level severity is the default. Any logs with `NOTICE` or higher severity will be captured.
80
122
 
81
123
 
82
- Other Ruby Examples
83
- -------------------
84
- ```ruby
85
- require 'catamaran'
86
-
87
- Catamaran.logger.log_level = Catamaran::LogLevel::INFO
88
- Catamaran.logger.backtrace_log_level = Catamaran::LogLevel::ERROR
89
- Catamaran::Manager.formatter_class = Catamaran::Formatter::NoCallerFormatter
90
-
91
- class SecondRubyDemo
92
- LOGGER = Catamaran.logger( { :class => name(), :file => __FILE__ } )
93
-
94
- def run
95
- LOGGER.info( "Sample INFO statement", { :line => __LINE__, :method => 'run'} ) if LOGGER.info?
96
- end
97
- end
98
-
99
- class ThirdRubyDemo
100
- LOGGER = Catamaran.logger( "com.mytld.ThirdRubyDemo", { :class => name(), :file => __FILE__ } )
101
-
102
- def run
103
- LOGGER.warn( "Sample WARN statement", { :line => __LINE__, :method => 'run' } )
104
- LOGGER.warn( "Sample WARN statement with backtrace option", { :line => __LINE__, :method => 'run', :backtrace => true } )
105
- LOGGER.error( "Sample ERROR statement with backtrace option", { :line => __LINE__, :method => 'run', :backtrace => true } )
106
- end
107
- end
108
-
109
- SecondRubyDemo.new.run
110
- ThirdRubyDemo.new.run
111
- ```
112
-
113
- And the output
114
-
115
- INFO pid-5973 [2013-12-27 17:18:09:115] - Sample INFO statement (catamaran_ruby_demos.rb:12:in `SecondRubyDemo.run')
116
- WARN pid-5973 [2013-12-27 17:18:09:115] com.mytld.ThirdRubyDemo - Sample WARN statement (catamaran_ruby_demos.rb:20:in `ThirdRubyDemo.run')
117
- WARN pid-5973 [2013-12-27 17:18:09:115] com.mytld.ThirdRubyDemo - Sample WARN statement with backtrace option (catamaran_ruby_demos.rb:21:in `ThirdRubyDemo.run')
118
- ERROR pid-5973 [2013-12-27 17:18:09:115] com.mytld.ThirdRubyDemo - Sample ERROR statement with backtrace option (catamaran_ruby_demos.rb:22:in `ThirdRubyDemo.run') from:
119
- catamaran_ruby_demos.rb:22:in `run'
120
- catamaran_ruby_demos.rb:27:in `<main>'
121
-
122
-
123
-
124
-
125
124
  Inspiration
126
125
  -----------
127
126
  I'm looking for a logging utility that:
@@ -148,11 +147,10 @@ require 'catamaran'
148
147
  require 'benchmark'
149
148
 
150
149
  Catamaran::LogLevel.default_log_level = Catamaran::LogLevel::INFO
151
- Catamaran::Manager.formatter_class = Catamaran::Formatter::NoCallerFormatter
152
150
  Catamaran::Manager.stderr = false
153
151
 
154
- class CatamaranPerformanceTest
155
- LOGGER = Catamaran.logger( "CatamaranPerformanceTest" )
152
+ class CatamaranConditionalLogStatementBenchmark
153
+ LOGGER = Catamaran.logger( "CatamaranConditionalLogStatementBenchmark" )
156
154
 
157
155
  # NOTE that the log level for this test is set to INFO,
158
156
  # so 'warn' logs are enabled and 'debug' logs are disabled
@@ -218,7 +216,7 @@ LOGGER.severe "This is a SEVERE log"
218
216
  LOGGER.severe "This is a FATAL log"
219
217
  ```
220
218
 
221
- ### NoCallerFormatter vs CallerFormatter
219
+ ### Performance implications of using `caller`
222
220
 
223
221
  ```ruby
224
222
  require 'catamaran'
@@ -226,22 +224,22 @@ require 'benchmark'
226
224
 
227
225
  Catamaran::Manager.stderr = false
228
226
 
229
- class CatamaranPerformanceTest
230
- LOGGER = Catamaran.logger( "CatamaranPerformanceTest" )
227
+ class CatamaranCallerBenchmark
228
+ LOGGER = Catamaran.logger( "CatamaranCallerBenchmark" )
231
229
 
232
230
  n = 500000
233
231
  Benchmark.bm(7) do |x|
234
- Catamaran::Manager.formatter_class = Catamaran::Formatter::NoCallerFormatter
232
+ Catamaran::Manager.formatter_caller_enabled = false
235
233
 
236
- x.report("Using NoCallerFormatter") {
234
+ x.report("Catamaran::Manager.formatter_caller_enabled = false") {
237
235
  n.times do |i|
238
236
  LOGGER.error "This is a ERROR log"
239
237
  end
240
238
  }
241
239
 
242
- Catamaran::Manager.formatter_class = Catamaran::Formatter::CallerFormatter
240
+ Catamaran::Manager.formatter_caller_enabled = true
243
241
 
244
- x.report("Using CallerFormatter") {
242
+ x.report("Catamaran::Manager.formatter_caller_enabled = true ") {
245
243
  n.times do |i|
246
244
  LOGGER.error "This is a ERROR log"
247
245
  end
@@ -250,24 +248,24 @@ class CatamaranPerformanceTest
250
248
  end
251
249
 
252
250
 
253
- # user system total real
254
- # Using NoCallerFormatter 6.850000 0.010000 6.860000 ( 6.864649)
255
- # Using CallerFormatter 14.700000 0.150000 14.850000 ( 14.867592)
251
+ # user system total real
252
+ # Catamaran::Manager.formatter_caller_enabled = false 6.710000 0.060000 6.770000 ( 6.780703)
253
+ # Catamaran::Manager.formatter_caller_enabled = true 13.940000 0.400000 14.340000 ( 14.345921)
256
254
  ```
257
255
 
258
256
  #### Summary
259
257
 
260
- `CallerFormatter` is slower but contains more details in the log statements as compared to `NoCallerFormatter`
258
+ Using the `caller()` is slower but generate more details in the log statements
261
259
 
262
- ##### Sample log from NoCallerFormatter
260
+ ##### Sample log from when formatter_caller_enabled is set to `false`
263
261
 
264
262
  WARN pid-4407 [2013-12-26 14:18:19:697] FirstRubyDemo - Note that WARN messages are getting logged
265
263
 
266
- ##### Sample log from CallerFormatter
264
+ ##### Sample log from when formatter_caller_enabled is set to `true`
267
265
 
268
266
  WARN pid-4410 [2013-12-26 14:18:38:276] FirstRubyDemo - Note that WARN messages are getting logged (catamaran_ruby_demos.rb:12:in `run')
269
267
 
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.
268
+ Because of this performance difference, the `caller()` is disabled by default. Though enabling it tends to be especially useful in the development and test environments when debugging problems during the course of functional testing.
271
269
 
272
270
  ### Ruby Profiler
273
271
  ```ruby
@@ -275,10 +273,10 @@ require 'catamaran'
275
273
  require 'ruby-prof'
276
274
 
277
275
 
278
- class FirstRubyDemo
279
- LOGGER = Catamaran.logger( "com.mycompany.FirstRubyDemo" )
276
+ class CatamaranProfilerTest
277
+ LOGGER = Catamaran.logger( "com.mycompany.CatamaranProfilerTest" )
280
278
  # or equivalently:
281
- # LOGGER = Catamaran.logger.com.mycompany.FirstRubyDemo
279
+ # LOGGER = Catamaran.logger.com.mycompany.CatamaranProfilerTest
282
280
 
283
281
  def run
284
282
  # Disabled by default
@@ -314,197 +312,191 @@ printer.print(STDOUT)
314
312
 
315
313
  ```
316
314
  Thread ID: 2156341060
317
- Fiber ID: 2164637460
318
- Total Time: 0.8493040000000001
315
+ Fiber ID: 2156558900
316
+ Total Time: 0.792647
319
317
  Sort by: total_time
320
318
 
321
319
  %total %self total self wait child calls Name
322
320
  --------------------------------------------------------------------------------
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
321
+ 100.00% 0.01% 0.793 0.000 0.000 0.793 1 Global#[No method]
322
+ 0.793 0.003 0.000 0.790 1/1 Integer#times
323
+ 0.000 0.000 0.000 0.000 1/2 Class#new
324
+ --------------------------------------------------------------------------------
325
+ 0.793 0.003 0.000 0.790 1/1 Global#[No method]
326
+ 99.99% 0.36% 0.793 0.003 0.000 0.790 1 Integer#times
327
+ 0.790 0.021 0.000 0.768 1000/1000 ProfilerTest#run
328
+ --------------------------------------------------------------------------------
329
+ 0.790 0.021 0.000 0.768 1000/1000 Integer#times
330
+ 99.64% 2.70% 0.790 0.021 0.000 0.768 1000 ProfilerTest#run
331
+ 0.147 0.012 0.000 0.135 1000/1000 Catamaran::Logger#severe
332
+ 0.146 0.007 0.000 0.138 1000/1000 Catamaran::Logger#fatal
333
+ 0.144 0.007 0.000 0.137 1000/1000 Catamaran::Logger#error
334
+ 0.140 0.007 0.000 0.133 1000/1000 Catamaran::Logger#warn
335
+ 0.128 0.007 0.000 0.122 1000/1000 Catamaran::Logger#notice
336
+ 0.021 0.006 0.000 0.015 1000/1000 Catamaran::Logger#debug?
337
+ 0.021 0.006 0.000 0.015 1000/1000 Catamaran::Logger#trace?
338
+ 0.021 0.006 0.000 0.015 1000/1000 Catamaran::Logger#info?
339
+ --------------------------------------------------------------------------------
340
+ 0.107 0.006 0.000 0.100 1000/5000 Catamaran::Logger#notice
341
+ 0.119 0.007 0.000 0.113 1000/5000 Catamaran::Logger#warn
342
+ 0.120 0.007 0.000 0.113 1000/5000 Catamaran::Logger#severe
343
+ 0.121 0.007 0.000 0.115 1000/5000 Catamaran::Logger#error
344
+ 0.123 0.007 0.000 0.117 1000/5000 Catamaran::Logger#fatal
345
+ 74.54% 4.23% 0.591 0.034 0.000 0.557 5000 Catamaran::Logger#log
346
+ 0.381 0.028 0.000 0.353 5000/5000 Catamaran::Logger#_format_msg
347
+ 0.176 0.047 0.000 0.129 5000/5000 <Class::Catamaran::Outputter>#write
348
+ --------------------------------------------------------------------------------
349
+ 0.381 0.028 0.000 0.353 5000/5000 Catamaran::Logger#log
350
+ 48.08% 3.49% 0.381 0.028 0.000 0.353 5000 Catamaran::Logger#_format_msg
351
+ 0.288 0.107 0.000 0.181 5000/5000 Catamaran::Formatter#construct_formatted_message
352
+ 0.051 0.033 0.000 0.018 5000/5000 Catamaran::Logger#path_to_s
353
+ 0.014 0.014 0.000 0.000 5000/5000 <Class::Catamaran::Formatter>#instance
354
+ --------------------------------------------------------------------------------
355
+ 0.288 0.107 0.000 0.181 5000/5000 Catamaran::Logger#_format_msg
356
+ 36.32% 13.50% 0.288 0.107 0.000 0.181 5000 Catamaran::Formatter#construct_formatted_message
357
+ 0.086 0.064 0.000 0.022 5000/5000 Time#strftime
358
+ 0.038 0.018 0.000 0.020 5000/5000 <Class::Time>#now
359
+ 0.025 0.025 0.000 0.000 5000/5000 Kernel#sprintf
368
360
  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
361
+ 0.011 0.011 0.000 0.000 5000/5000 Fixnum#to_s
362
+ 0.006 0.006 0.000 0.000 5000/5000 <Module::Process>#pid
371
363
  --------------------------------------------------------------------------------
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
364
+ 0.176 0.047 0.000 0.129 5000/5000 Catamaran::Logger#log
365
+ 22.23% 5.96% 0.176 0.047 0.000 0.129 5000 <Class::Catamaran::Outputter>#write
366
+ 0.095 0.020 0.000 0.075 5000/5000 IO#puts
375
367
  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?
368
+ 0.016 0.016 0.000 0.000 5000/5000 <Class::Catamaran::Manager>#stderr?
377
369
  --------------------------------------------------------------------------------
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
370
+ 0.147 0.012 0.000 0.135 1000/1000 ProfilerTest#run
371
+ 18.53% 1.54% 0.147 0.012 0.000 0.135 1000 Catamaran::Logger#severe
372
+ 0.120 0.007 0.000 0.113 1000/5000 Catamaran::Logger#log
373
+ 0.015 0.012 0.000 0.002 1000/8003 Catamaran::Logger#log_level
382
374
  --------------------------------------------------------------------------------
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
375
+ 0.146 0.007 0.000 0.138 1000/1000 ProfilerTest#run
376
+ 18.39% 0.94% 0.146 0.007 0.000 0.138 1000 Catamaran::Logger#fatal
377
+ 0.123 0.007 0.000 0.117 1000/5000 Catamaran::Logger#log
386
378
  0.015 0.013 0.000 0.002 1000/8003 Catamaran::Logger#log_level
387
379
  --------------------------------------------------------------------------------
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
380
+ 0.144 0.007 0.000 0.137 1000/1000 ProfilerTest#run
381
+ 18.20% 0.94% 0.144 0.007 0.000 0.137 1000 Catamaran::Logger#error
382
+ 0.121 0.007 0.000 0.115 1000/5000 Catamaran::Logger#log
383
+ 0.015 0.013 0.000 0.002 1000/8003 Catamaran::Logger#log_level
397
384
  --------------------------------------------------------------------------------
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
385
+ 0.140 0.007 0.000 0.133 1000/1000 ProfilerTest#run
386
+ 17.64% 0.85% 0.140 0.007 0.000 0.133 1000 Catamaran::Logger#warn
387
+ 0.119 0.007 0.000 0.113 1000/5000 Catamaran::Logger#log
401
388
  0.014 0.012 0.000 0.002 1000/8003 Catamaran::Logger#log_level
389
+ --------------------------------------------------------------------------------
390
+ 0.128 0.007 0.000 0.122 1000/1000 ProfilerTest#run
391
+ 16.19% 0.84% 0.128 0.007 0.000 0.122 1000 Catamaran::Logger#notice
392
+ 0.107 0.006 0.000 0.100 1000/5000 Catamaran::Logger#log
393
+ 0.015 0.013 0.000 0.002 1000/8003 Catamaran::Logger#log_level
402
394
  --------------------------------------------------------------------------------
403
395
  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
396
+ 0.014 0.012 0.000 0.002 1000/8003 Catamaran::Logger#warn
397
+ 0.015 0.012 0.000 0.002 1000/8003 Catamaran::Logger#severe
398
+ 0.015 0.013 0.000 0.002 1000/8003 Catamaran::Logger#notice
399
+ 0.015 0.013 0.000 0.002 1000/8003 Catamaran::Logger#fatal
405
400
  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
401
+ 0.015 0.013 0.000 0.002 1000/8003 Catamaran::Logger#trace?
402
+ 0.015 0.013 0.000 0.002 1000/8003 Catamaran::Logger#debug?
403
+ 0.015 0.013 0.000 0.002 1000/8003 Catamaran::Logger#error
404
+ 15.07% 12.83% 0.119 0.102 0.000 0.018 8003 *Catamaran::Logger#log_level
413
405
  0.018 0.018 0.000 0.000 16001/16001 Kernel#nil?
414
406
  0.000 0.000 0.000 0.000 4/4 NilClass#nil?
415
407
  0.000 0.000 0.000 0.000 3/8003 Catamaran::Logger#log_level
416
408
  --------------------------------------------------------------------------------
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
409
+ 0.095 0.020 0.000 0.075 5000/5000 <Class::Catamaran::Outputter>#write
410
+ 11.98% 2.49% 0.095 0.020 0.000 0.075 5000 IO#puts
411
+ 0.075 0.075 0.000 0.000 10000/10000 IO#write
420
412
  --------------------------------------------------------------------------------
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
413
+ 0.086 0.064 0.000 0.022 5000/5000 Catamaran::Formatter#construct_formatted_message
414
+ 10.89% 8.09% 0.086 0.064 0.000 0.022 5000 Time#strftime
415
+ 0.016 0.016 0.000 0.000 10000/10000 Fixnum#divmod
424
416
  0.006 0.006 0.000 0.000 5000/5000 Fixnum#%
425
417
  --------------------------------------------------------------------------------
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
418
+ 0.075 0.075 0.000 0.000 10000/10000 IO#puts
419
+ 9.49% 9.49% 0.075 0.075 0.000 0.000 10000 IO#write
428
420
  --------------------------------------------------------------------------------
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
421
+ 0.051 0.033 0.000 0.018 5000/5000 Catamaran::Logger#_format_msg
422
+ 6.49% 4.20% 0.051 0.033 0.000 0.018 5000 Catamaran::Logger#path_to_s
423
+ 0.018 0.018 0.000 0.000 5000/5000 Array#join
432
424
  0.000 0.000 0.000 0.000 1/1 <Class::Catamaran::Manager>#delimiter
433
425
  --------------------------------------------------------------------------------
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
426
+ 0.038 0.018 0.000 0.020 5000/5000 Catamaran::Formatter#construct_formatted_message
427
+ 4.78% 2.22% 0.038 0.018 0.000 0.020 5000 <Class::Time>#now
436
428
  0.020 0.014 0.000 0.006 5000/5000 Time#initialize
437
429
  --------------------------------------------------------------------------------
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
430
+ 0.025 0.025 0.000 0.000 5000/5000 Catamaran::Formatter#construct_formatted_message
431
+ 3.15% 3.15% 0.025 0.025 0.000 0.000 5000 Kernel#sprintf
440
432
  --------------------------------------------------------------------------------
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
433
+ 0.021 0.006 0.000 0.015 1000/1000 ProfilerTest#run
434
+ 2.70% 0.75% 0.021 0.006 0.000 0.015 1000 Catamaran::Logger#debug?
435
+ 0.015 0.013 0.000 0.002 1000/8003 Catamaran::Logger#log_level
451
436
  --------------------------------------------------------------------------------
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
437
+ 0.021 0.006 0.000 0.015 1000/1000 ProfilerTest#run
438
+ 2.69% 0.77% 0.021 0.006 0.000 0.015 1000 Catamaran::Logger#trace?
439
+ 0.015 0.013 0.000 0.002 1000/8003 Catamaran::Logger#log_level
454
440
  --------------------------------------------------------------------------------
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?
441
+ 0.021 0.006 0.000 0.015 1000/1000 ProfilerTest#run
442
+ 2.60% 0.70% 0.021 0.006 0.000 0.015 1000 Catamaran::Logger#info?
457
443
  0.015 0.013 0.000 0.002 1000/8003 Catamaran::Logger#log_level
458
444
  --------------------------------------------------------------------------------
459
445
  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
446
+ 2.56% 1.80% 0.020 0.014 0.000 0.006 5000 Time#initialize
461
447
  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
448
  --------------------------------------------------------------------------------
466
449
  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?
450
+ 2.31% 2.31% 0.018 0.018 0.000 0.000 5000 <Class::Catamaran::Manager>#stdout?
468
451
  --------------------------------------------------------------------------------
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
452
+ 0.018 0.018 0.000 0.000 5000/5000 Catamaran::Logger#path_to_s
453
+ 2.28% 2.28% 0.018 0.018 0.000 0.000 5000 Array#join
471
454
  --------------------------------------------------------------------------------
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
455
+ 0.018 0.018 0.000 0.000 16001/16001 Catamaran::Logger#log_level
456
+ 2.24% 2.24% 0.018 0.018 0.000 0.000 16001 Kernel#nil?
474
457
  --------------------------------------------------------------------------------
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
458
+ 0.016 0.016 0.000 0.000 10000/10000 Time#strftime
459
+ 1.99% 1.99% 0.016 0.016 0.000 0.000 10000 Fixnum#divmod
477
460
  --------------------------------------------------------------------------------
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?
461
+ 0.016 0.016 0.000 0.000 5000/5000 <Class::Catamaran::Outputter>#write
462
+ 1.97% 1.97% 0.016 0.016 0.000 0.000 5000 <Class::Catamaran::Manager>#stderr?
480
463
  --------------------------------------------------------------------------------
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
464
+ 0.014 0.014 0.000 0.000 5000/5000 Catamaran::Formatter#construct_formatted_message
465
+ 1.79% 1.79% 0.014 0.014 0.000 0.000 5000 <Class::Catamaran::LogLevel>#severity_to_s
483
466
  --------------------------------------------------------------------------------
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
467
+ 0.014 0.014 0.000 0.000 5000/5000 Catamaran::Logger#_format_msg
468
+ 1.78% 1.78% 0.014 0.014 0.000 0.000 5000 <Class::Catamaran::Formatter>#instance
469
+ 0.000 0.000 0.000 0.000 1/2 Class#new
486
470
  --------------------------------------------------------------------------------
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
471
+ 0.011 0.011 0.000 0.000 5000/5000 Catamaran::Formatter#construct_formatted_message
472
+ 1.44% 1.44% 0.011 0.011 0.000 0.000 5000 Fixnum#to_s
489
473
  --------------------------------------------------------------------------------
490
474
  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#%
475
+ 0.81% 0.81% 0.006 0.006 0.000 0.000 5000 Fixnum#%
476
+ --------------------------------------------------------------------------------
477
+ 0.006 0.006 0.000 0.000 5000/5000 Catamaran::Formatter#construct_formatted_message
478
+ 0.77% 0.77% 0.006 0.006 0.000 0.000 5000 <Module::Process>#pid
492
479
  --------------------------------------------------------------------------------
493
480
  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#+
481
+ 0.76% 0.76% 0.006 0.006 0.000 0.000 5000 Fixnum#+
495
482
  --------------------------------------------------------------------------------
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
483
+ 0.000 0.000 0.000 0.000 1/2 Global#[No method]
484
+ 0.000 0.000 0.000 0.000 1/2 <Class::Catamaran::Formatter>#instance
485
+ 0.00% 0.00% 0.000 0.000 0.000 0.000 2 Class#new
486
+ 0.000 0.000 0.000 0.000 1/1 Catamaran::Formatter#initialize
498
487
  0.000 0.000 0.000 0.000 1/1 BasicObject#initialize
488
+ --------------------------------------------------------------------------------
489
+ 0.000 0.000 0.000 0.000 1/1 Catamaran::Logger#path_to_s
490
+ 0.00% 0.00% 0.000 0.000 0.000 0.000 1 <Class::Catamaran::Manager>#delimiter
499
491
  --------------------------------------------------------------------------------
500
492
  0.000 0.000 0.000 0.000 4/4 Catamaran::Logger#log_level
501
493
  0.00% 0.00% 0.000 0.000 0.000 0.000 4 NilClass#nil?
502
494
  --------------------------------------------------------------------------------
503
495
  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
496
+ 0.00% 0.00% 0.000 0.000 0.000 0.000 1 Catamaran::Formatter#initialize
505
497
  --------------------------------------------------------------------------------
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
498
+ 0.000 0.000 0.000 0.000 1/1 Class#new
499
+ 0.00% 0.00% 0.000 0.000 0.000 0.000 1 BasicObject#initialize
508
500
 
509
501
  * indicates recursively called methods
510
502
  ```
@@ -523,7 +515,6 @@ Ideas around what's next
523
515
  * Log rotation
524
516
  * Heroku support (https://blog.heroku.com/archives/2013/7/15/logging-on-heroku)
525
517
  * Buffered file I/O considerations
526
- * Revisit how the formatters work
527
518
 
528
519
 
529
520
 
@@ -0,0 +1,99 @@
1
+ module Catamaran
2
+ class Formatter
3
+ include Singleton
4
+
5
+ def self.instance
6
+ @@instance ||= new
7
+ end
8
+
9
+ def caller_enabled=( boolean_value )
10
+ @caller_enabled = boolean_value
11
+ end
12
+
13
+ def caller_enabled
14
+ @caller_enabled
15
+ end
16
+
17
+ ##
18
+ # Construct a properly formatted log message based
19
+
20
+
21
+ def construct_formatted_message( severity, path, msg, opts )
22
+ msg = sprintf( "%6s pid-#{Process.pid} [#{Time.now.strftime( "%G-%m-%d %H:%M:%S:%L" )}] %47s - #{msg}",
23
+ LogLevel.severity_to_s( severity ),
24
+ ( path.length > 47 ) ? path.dup[-47,47] : path )
25
+
26
+
27
+
28
+ ##
29
+ # Should the caller component be added to the msg
30
+
31
+ if ( ( opts && opts[:file] && opts[:line] && opts[:method] ) || !@caller_enabled )
32
+ # if file and line number are specified or the caller_enabled is disabled
33
+ # then construct a formatted message that does NOT make use of the caller (caller is slow)
34
+ append_caller_information = false
35
+ elsif @caller_enabled
36
+ # else if the caller is enabled, make use of it
37
+ append_caller_information = true
38
+ else
39
+ # Otherwise, do NOT use the caller (as it is slow)
40
+ append_caller_information = false
41
+ end
42
+
43
+
44
+ ##
45
+ # If the user has requested making use of the caller, then use it
46
+ # Otherwise append what optional information we can determine
47
+
48
+ if append_caller_information
49
+ msg << " (#{caller(4)[0]})"
50
+ else
51
+ ##
52
+ # Append some suffix info if it has been specified
53
+ #
54
+ if opts
55
+ if opts[:file]
56
+ msg << " (#{opts[:file]}"
57
+
58
+ if opts[:line]
59
+ msg << ":#{opts[:line]}"
60
+ end
61
+
62
+ if opts[:class] || opts[:method]
63
+ msg << ":in `"
64
+
65
+ if opts[:class]
66
+ msg << "#{opts[:class]}."
67
+ end
68
+
69
+ msg << "#{opts[:method]}" if opts[:method]
70
+ msg << "'"
71
+ end
72
+
73
+ msg << ')'
74
+ end
75
+ end
76
+ end
77
+
78
+
79
+ ##
80
+ # Append the backtrace information if it has been requested by the user
81
+ if opts && opts[:backtrace] == true
82
+ # Implicit return
83
+ msg << " from:\n#{caller(4).take(10).join("\n")}"
84
+ end
85
+
86
+ # Implicit return
87
+ msg
88
+ end
89
+
90
+ private
91
+
92
+ def initialize
93
+ # Using caller() in the log messages is DISABLED by default
94
+ @caller_enabled = false
95
+ end
96
+
97
+ end
98
+ end
99
+
@@ -394,6 +394,7 @@ module Catamaran
394
394
  def forget_memoizations
395
395
  @memoized_log_level = nil
396
396
  @memoized_backtrace_log_level = nil
397
+ @memoized_delimiter = nil
397
398
 
398
399
  @sub_loggers.values.each do |logger|
399
400
  logger.forget_memoizations()
@@ -565,7 +566,7 @@ module Catamaran
565
566
 
566
567
  def _format_msg( severity, msg, opts )
567
568
  # Implicit return
568
- Manager.formatter_class.construct_formatted_message( severity, self.path_to_s(), msg, opts )
569
+ Formatter.instance.construct_formatted_message( severity, self.path_to_s(), msg, opts )
569
570
  end
570
571
 
571
572
  ##
@@ -6,19 +6,6 @@ module Catamaran
6
6
  attr_accessor :_stderr_flag;
7
7
  attr_accessor :_output_files;
8
8
 
9
-
10
- ##
11
- # Class that's going to be performing the message formatting
12
-
13
- def formatter_class
14
- # The NoCallerFormatter class is the default formatter.
15
- @formatter_class || Catamaran::Formatter::NoCallerFormatter
16
- end
17
-
18
- def formatter_class=( value )
19
- @formatter_class = value
20
- end
21
-
22
9
  ##
23
10
  # The default delimiter
24
11
  #
@@ -32,6 +19,15 @@ module Catamaran
32
19
  end
33
20
 
34
21
 
22
+ def self.formatter_caller_enabled=( boolean_value )
23
+ Catamaran::Formatter.instance.caller_enabled = boolean_value
24
+ end
25
+
26
+ def self.formatter_caller_enabled
27
+ # Implicit return
28
+ Catamaran::Formatter.instance.caller_enabled
29
+ end
30
+
35
31
 
36
32
 
37
33
  ##
@@ -116,6 +112,10 @@ module Catamaran
116
112
  self.root_logger().forget_memoizations()
117
113
  end
118
114
 
115
+ def self.forget_cached_log_levels
116
+ self.forget_memoizations
117
+ end
118
+
119
119
  ##
120
120
  # How many loggers is Catamaran currently aware of
121
121
 
@@ -1,4 +1,4 @@
1
1
  module Catamaran
2
- VERSION = '1.0.0'
2
+ VERSION = '2.0.0'
3
3
  end
4
4
 
data/lib/catamaran.rb CHANGED
@@ -1,11 +1,9 @@
1
+ require 'singleton'
1
2
  require 'catamaran/logger'
2
3
  require 'catamaran/manager'
3
- require 'catamaran/formatter/base_formatter'
4
- require 'catamaran/formatter/caller_formatter'
5
- require 'catamaran/formatter/no_caller_formatter'
4
+ require 'catamaran/formatter'
6
5
  require 'catamaran/outputter'
7
6
  require 'catamaran/output_file'
8
-
9
7
  require 'catamaran/log_level'
10
8
  require 'catamaran/version'
11
9
 
@@ -37,6 +35,7 @@ module Catamaran
37
35
  LOG_LEVEL_TRACE = LogLevel::TRACE
38
36
  LOG_LEVEL_DEBUG = LogLevel::DEBUG
39
37
  LOG_LEVEL_INFO = LogLevel::INFO
38
+ LOG_LEVEL_NOTICE = LogLevel::NOTICE
40
39
  LOG_LEVEL_WARN = LogLevel::WARN
41
40
  LOG_LEVEL_ERROR = LogLevel::ERROR
42
41
  LOG_LEVEL_SEVERE = LogLevel::SEVERE
@@ -8,8 +8,8 @@ Catamaran.logger.log_level = Catamaran::LogLevel::DEBUG
8
8
  # If that's too verbose, uncomment this
9
9
  # Catamaran::LogLevel.log_level_io = Catamaran::LogLevel::IO_LESS_CRITICAL_THAN_DEBUG
10
10
 
11
- # The NoCallerFormatter is the default.
12
- Catamaran::Manager.formatter_class = Catamaran::Formatter::CallerFormatter
11
+ # There is a performance hit for using the caller, but it generates more detailed logs
12
+ Catamaran::Manager.formatter_caller_enabled = true
13
13
 
14
14
  # Uncomment to enable Catamaran internal debugging
15
15
  # Catamaran::debugging = true
@@ -242,16 +242,32 @@ describe Catamaran do
242
242
  end
243
243
  end
244
244
 
245
- describe "#forget_memoizations" do
245
+ describe ".forget_memoizations" do
246
246
  it "should forget all the memoized log levels" do
247
247
  Catamaran.logger.log_level = Catamaran::LogLevel::ERROR
248
248
  Catamaran.logger.Test.smart_log_level.should == Catamaran::LogLevel::ERROR
249
249
  Catamaran.logger.log_level = Catamaran::LogLevel::INFO
250
250
  Catamaran.logger.Test.smart_log_level.should == Catamaran::LogLevel::ERROR
251
- Catamaran.logger.forget_memoizations
251
+ Catamaran::Manager.forget_memoizations
252
252
  Catamaran.logger.Test.smart_log_level.should == Catamaran::LogLevel::INFO
253
253
  end
254
- end
254
+
255
+ it "should call forget_memoizations on the root logger" do
256
+ Catamaran.logger.log_level = Catamaran::LogLevel::ERROR
257
+ Catamaran.logger.Test.smart_log_level.should == Catamaran::LogLevel::ERROR
258
+ Catamaran.logger.log_level = Catamaran::LogLevel::INFO
259
+ Catamaran.logger.Test.smart_log_level.should == Catamaran::LogLevel::ERROR
260
+ Catamaran.logger.should_receive( :forget_memoizations ).once
261
+ Catamaran::Manager.forget_memoizations
262
+ end
263
+ end
264
+
265
+ describe ".forget_cached_log_levels" do
266
+ it "should call forget_memoizations" do
267
+ Catamaran::Manager.should_receive( :forget_memoizations )
268
+ Catamaran::Manager.forget_cached_log_levels
269
+ end
270
+ end
255
271
  end
256
272
 
257
273
  describe Catamaran::Logger do
@@ -309,6 +325,17 @@ describe Catamaran do
309
325
  Catamaran.logger.debug( "And INFO log should NOT be received" )
310
326
  end
311
327
 
328
+ describe "#forget_memoizations" do
329
+ it "should forget all the memoized log levels" do
330
+ Catamaran.logger.log_level = Catamaran::LogLevel::ERROR
331
+ Catamaran.logger.Test.smart_log_level.should == Catamaran::LogLevel::ERROR
332
+ Catamaran.logger.log_level = Catamaran::LogLevel::INFO
333
+ Catamaran.logger.Test.smart_log_level.should == Catamaran::LogLevel::ERROR
334
+ Catamaran.logger.forget_memoizations
335
+ Catamaran.logger.Test.smart_log_level.should == Catamaran::LogLevel::INFO
336
+ end
337
+ end
338
+
312
339
  describe "#determine_path_and_opts_arguments" do
313
340
  it "should return the correct path when one string parameter is specified" do
314
341
  Catamaran.logger.send( :determine_path_and_opts_arguments, "mycompany.myrailsproject.app.models.User" ).should == [ "mycompany.myrailsproject.app.models.User", nil ]
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: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeano
@@ -22,9 +22,7 @@ files:
22
22
  - catamaran.gemspec
23
23
  - init.rb
24
24
  - lib/catamaran.rb
25
- - lib/catamaran/formatter/base_formatter.rb
26
- - lib/catamaran/formatter/caller_formatter.rb
27
- - lib/catamaran/formatter/no_caller_formatter.rb
25
+ - lib/catamaran/formatter.rb
28
26
  - lib/catamaran/integration/rails.rb
29
27
  - lib/catamaran/log_level.rb
30
28
  - lib/catamaran/logger.rb
@@ -1,78 +0,0 @@
1
- module Catamaran
2
- module Formatter
3
- ##
4
- # Construct a properly formatted log message based
5
-
6
- class BaseFormatter
7
- def self.base_construct_formatted_message( severity, path, msg, opts )
8
- # Truncate on the left
9
- if path.length > 47
10
- updated_path = path.dup[-47,47]
11
- else
12
- updated_path = path
13
- end
14
-
15
- # TODO: Abstract out the logger so that it's easy to use different formats
16
- # Implicit return
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
- end
19
-
20
- def self.construct_backtrace_info( opts )
21
- if opts && opts[:backtrace] == true
22
- # Implicit return
23
- " from:\n#{caller(5).take(10).join("\n")}"
24
- else
25
- # Implicit return
26
- ''
27
- end
28
- end
29
-
30
-
31
- def self.contruct_suffix_info( opts )
32
- msg = ''
33
-
34
- if opts
35
- if opts[:file]
36
- msg << " (#{opts[:file]}"
37
-
38
- if opts[:line]
39
- msg << ":#{opts[:line]}"
40
- end
41
-
42
- if opts[:class] || opts[:method]
43
- msg << ":in `"
44
-
45
- msg << construct_class_method_info( opts )
46
-
47
- msg << "'"
48
- end
49
-
50
- msg << ')'
51
- end
52
- end
53
-
54
- # Implicit return
55
- msg
56
- end
57
-
58
-
59
- def self.construct_class_method_info( opts )
60
- msg = ''
61
- if opts
62
- if opts[:class] || opts[:method]
63
- if opts[:class]
64
- msg << "#{opts[:class]}."
65
- end
66
-
67
- msg << "#{opts[:method]}" if opts[:method]
68
- end
69
- end
70
-
71
- # Implicit Return
72
- msg
73
- end
74
-
75
- end
76
- end
77
- end
78
-
@@ -1,13 +0,0 @@
1
- module Catamaran
2
- module Formatter
3
- ##
4
- # Construct a properly formatted log message based
5
-
6
- class CallerFormatter < BaseFormatter
7
- def self.construct_formatted_message( log_level, path, msg, opts )
8
- "#{base_construct_formatted_message( log_level, path, msg, opts )} (#{caller(4)[0]})" + construct_backtrace_info( opts )
9
- end
10
- end
11
- end
12
- end
13
-
@@ -1,13 +0,0 @@
1
- module Catamaran
2
- module Formatter
3
- ##
4
- # Construct a properly formatted log message based
5
-
6
- class NoCallerFormatter < BaseFormatter
7
- def self.construct_formatted_message( log_level, path, msg, opts )
8
- base_construct_formatted_message( log_level, path, msg, opts ) + contruct_suffix_info( opts ) + construct_backtrace_info( opts )
9
- end
10
- end
11
- end
12
- end
13
-