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 +4 -4
- data/README.md +203 -212
- data/lib/catamaran/formatter.rb +99 -0
- data/lib/catamaran/logger.rb +2 -1
- data/lib/catamaran/manager.rb +13 -13
- data/lib/catamaran/version.rb +1 -1
- data/lib/catamaran.rb +3 -4
- data/lib/generators/catamaran/templates/catamaran/development.rb +2 -2
- data/spec/catamaran_spec.rb +30 -3
- metadata +2 -4
- data/lib/catamaran/formatter/base_formatter.rb +0 -78
- data/lib/catamaran/formatter/caller_formatter.rb +0 -13
- data/lib/catamaran/formatter/no_caller_formatter.rb +0 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a7b2c5c9d0ea8b6039c9b7bc454f66f07b064541
|
|
4
|
+
data.tar.gz: 966f7e9d3572846d188aae5deed8b1d8e2625e7a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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', '~>
|
|
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
|
|
23
|
-
LOGGER = Catamaran.logger( "com.mytld.
|
|
21
|
+
class WorkingWithCatamaran
|
|
22
|
+
LOGGER = Catamaran.logger( "com.mytld.WorkingWithCatamaran" )
|
|
24
23
|
# or equivalently:
|
|
25
|
-
# LOGGER = Catamaran.logger.com.mytld.
|
|
24
|
+
# LOGGER = Catamaran.logger.com.mytld.WorkingWithCatamaran
|
|
26
25
|
|
|
27
|
-
def
|
|
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
|
-
|
|
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-
|
|
49
|
-
WARN pid-
|
|
50
|
-
ERROR pid-
|
|
51
|
-
SEVERE pid-
|
|
52
|
-
FATAL pid-
|
|
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
|
|
155
|
-
LOGGER = Catamaran.logger( "
|
|
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
|
-
###
|
|
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
|
|
230
|
-
LOGGER = Catamaran.logger( "
|
|
227
|
+
class CatamaranCallerBenchmark
|
|
228
|
+
LOGGER = Catamaran.logger( "CatamaranCallerBenchmark" )
|
|
231
229
|
|
|
232
230
|
n = 500000
|
|
233
231
|
Benchmark.bm(7) do |x|
|
|
234
|
-
Catamaran::Manager.
|
|
232
|
+
Catamaran::Manager.formatter_caller_enabled = false
|
|
235
233
|
|
|
236
|
-
x.report("
|
|
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.
|
|
240
|
+
Catamaran::Manager.formatter_caller_enabled = true
|
|
243
241
|
|
|
244
|
-
x.report("
|
|
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
|
-
#
|
|
254
|
-
#
|
|
255
|
-
#
|
|
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
|
-
`
|
|
258
|
+
Using the `caller()` is slower but generate more details in the log statements
|
|
261
259
|
|
|
262
|
-
##### Sample log from
|
|
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
|
|
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, `
|
|
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
|
|
279
|
-
LOGGER = Catamaran.logger( "com.mycompany.
|
|
276
|
+
class CatamaranProfilerTest
|
|
277
|
+
LOGGER = Catamaran.logger( "com.mycompany.CatamaranProfilerTest" )
|
|
280
278
|
# or equivalently:
|
|
281
|
-
# LOGGER = Catamaran.logger.com.mycompany.
|
|
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:
|
|
318
|
-
Total Time: 0.
|
|
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.
|
|
324
|
-
0.
|
|
325
|
-
0.000 0.000 0.000 0.000 1/
|
|
326
|
-
--------------------------------------------------------------------------------
|
|
327
|
-
0.
|
|
328
|
-
99.99% 0.
|
|
329
|
-
0.
|
|
330
|
-
--------------------------------------------------------------------------------
|
|
331
|
-
0.
|
|
332
|
-
99.
|
|
333
|
-
0.
|
|
334
|
-
0.
|
|
335
|
-
0.
|
|
336
|
-
0.
|
|
337
|
-
0.
|
|
338
|
-
0.
|
|
339
|
-
0.021 0.006 0.000 0.
|
|
340
|
-
0.
|
|
341
|
-
--------------------------------------------------------------------------------
|
|
342
|
-
0.
|
|
343
|
-
0.
|
|
344
|
-
0.
|
|
345
|
-
0.
|
|
346
|
-
0.
|
|
347
|
-
|
|
348
|
-
0.
|
|
349
|
-
0.
|
|
350
|
-
--------------------------------------------------------------------------------
|
|
351
|
-
0.
|
|
352
|
-
|
|
353
|
-
0.
|
|
354
|
-
0.
|
|
355
|
-
0.
|
|
356
|
-
--------------------------------------------------------------------------------
|
|
357
|
-
0.
|
|
358
|
-
|
|
359
|
-
0.
|
|
360
|
-
0.
|
|
361
|
-
0.
|
|
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.
|
|
370
|
-
0.
|
|
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.
|
|
373
|
-
|
|
374
|
-
0.
|
|
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.
|
|
368
|
+
0.016 0.016 0.000 0.000 5000/5000 <Class::Catamaran::Manager>#stderr?
|
|
377
369
|
--------------------------------------------------------------------------------
|
|
378
|
-
0.
|
|
379
|
-
|
|
380
|
-
0.
|
|
381
|
-
0.
|
|
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.
|
|
384
|
-
18.
|
|
385
|
-
0.
|
|
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.
|
|
389
|
-
|
|
390
|
-
0.
|
|
391
|
-
0.
|
|
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.
|
|
399
|
-
|
|
400
|
-
0.
|
|
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#
|
|
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#
|
|
407
|
-
0.
|
|
408
|
-
0.
|
|
409
|
-
|
|
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.
|
|
418
|
-
|
|
419
|
-
0.
|
|
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.
|
|
422
|
-
|
|
423
|
-
0.
|
|
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.
|
|
427
|
-
|
|
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.
|
|
430
|
-
6.
|
|
431
|
-
0.
|
|
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.
|
|
435
|
-
4.
|
|
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.
|
|
439
|
-
3.
|
|
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.
|
|
442
|
-
2.
|
|
443
|
-
0.
|
|
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.
|
|
453
|
-
2.
|
|
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.
|
|
456
|
-
2.
|
|
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.
|
|
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.
|
|
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
|
|
470
|
-
2.
|
|
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.
|
|
473
|
-
|
|
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.
|
|
476
|
-
1.
|
|
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.
|
|
479
|
-
1.
|
|
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
|
|
482
|
-
1.
|
|
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.
|
|
485
|
-
1.
|
|
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.
|
|
488
|
-
|
|
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.
|
|
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.
|
|
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/
|
|
497
|
-
|
|
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
|
|
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
|
|
507
|
-
0.00% 0.00% 0.000 0.000 0.000 0.000 1
|
|
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
|
+
|
data/lib/catamaran/logger.rb
CHANGED
|
@@ -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
|
-
|
|
569
|
+
Formatter.instance.construct_formatted_message( severity, self.path_to_s(), msg, opts )
|
|
569
570
|
end
|
|
570
571
|
|
|
571
572
|
##
|
data/lib/catamaran/manager.rb
CHANGED
|
@@ -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
|
|
data/lib/catamaran/version.rb
CHANGED
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
|
|
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
|
-
#
|
|
12
|
-
Catamaran::Manager.
|
|
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
|
data/spec/catamaran_spec.rb
CHANGED
|
@@ -242,16 +242,32 @@ describe Catamaran do
|
|
|
242
242
|
end
|
|
243
243
|
end
|
|
244
244
|
|
|
245
|
-
|
|
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.
|
|
251
|
+
Catamaran::Manager.forget_memoizations
|
|
252
252
|
Catamaran.logger.Test.smart_log_level.should == Catamaran::LogLevel::INFO
|
|
253
253
|
end
|
|
254
|
-
|
|
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:
|
|
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
|
|
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
|
-
|