catamaran 0.3.0 → 0.4.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.
data/README.md CHANGED
@@ -6,7 +6,7 @@ I think logging is a powerful and often undervalued tool in software development
6
6
  Gemfile
7
7
  -------
8
8
 
9
- gem 'catamaran', '~> 0.2.0'
9
+ gem 'catamaran', '~> 0.3.0'
10
10
 
11
11
  Rails-related setup:
12
12
 
@@ -15,52 +15,27 @@ Rails-related setup:
15
15
  Now modify `development.rb` as needed
16
16
 
17
17
  Ruby Quickstart
18
- -------------------------------
19
- Catamaran::Manager.stderr = true
20
- Catamaran::LogLevel.default_log_level = Catamaran::LogLevel::DEBUG
21
- Catamaran::Manager.formatter_class = Catamaran::Formatter::NoCallerFormatter
18
+ ---------------
19
+ require 'catamaran'
22
20
 
23
21
  class FirstRubyDemo
24
22
  LOGGER = Catamaran.logger( "FirstRubyDemo" )
25
23
 
26
24
  def run
27
- LOGGER.debug( "Note that DEBUG messages are getting logged" ) if LOGGER.debug?
25
+ LOGGER.warn( "Note that WARN messages are getting logged" ) if LOGGER.warn?
28
26
  LOGGER.trace( "Note that TRACE messages are NOT getting logged" ) if LOGGER.trace?
29
27
  end
30
28
  end
31
29
 
32
- class SecondRubyDemo
33
- LOGGER = Catamaran.logger( { :class => name(), :file => __FILE__ } )
34
-
35
- def run
36
- LOGGER.debug( "Sample DEBUG statement", { :line => __LINE__, :method => 'run'} ) if LOGGER.debug?
37
- end
38
- end
39
-
40
- class ThirdRubyDemo
41
- LOGGER = Catamaran.logger( "com.mycompany.ThirdRubyDemo", { :class => name(), :file => __FILE__ } )
42
-
43
- def run
44
- LOGGER.debug( "Sample DEBUG statement", { :line => __LINE__, :method => 'run'} ) if LOGGER.debug?
45
- end
46
- end
47
-
48
-
49
- puts "Catamaran VERSION = #{Catamaran::VERSION}"
50
30
  FirstRubyDemo.new.run
51
- SecondRubyDemo.new.run
52
- ThirdRubyDemo.new.run
53
31
 
54
32
  And the output
55
33
 
56
- Catamaran VERSION = 0.3.0
57
- DEBUG pid-2729 [2013-12-23 19:35:35:732] FirstRubyDemo - Note that DEBUG messages are getting logged
58
- DEBUG pid-2729 [2013-12-23 19:35:35:732] - Sample DEBUG statement (catmaran_ruby_demos.rb:21:in `SecondRubyDemo.run')
59
- DEBUG pid-2729 [2013-12-23 19:35:35:732] com.mycompany.ThirdRubyDemo - Sample DEBUG statement (catmaran_ruby_demos.rb:29:in `ThirdRubyDemo.run')
34
+ WARN pid-2729 [2013-12-23 19:35:35:732] FirstRubyDemo - Note that WARN messages are getting logged
60
35
 
61
36
 
62
37
  Rails Quickstart
63
- --------------------------------
38
+ ----------------
64
39
 
65
40
  class PagesController < ApplicationController
66
41
  LOGGER = Catamaran.logger.com.mycompany.myrailsapp.app.controllers.PagesController
@@ -85,6 +60,37 @@ Load the `index` page and check out your `development.log` file
85
60
  IO pid-86000 [2013-12-17 17:26:39:176] pany.myrailsapp.app.controllers.PagesController - Entering with params = {"controller"=>"pages", "action"=>"index"} (`/myrailsapp/app/controllers/pages_controller.rb:7`:in `index`)
86
61
 
87
62
 
63
+ Other Ruby Examples
64
+ -------------------
65
+ require 'catamaran'
66
+
67
+ Catamaran::LogLevel.default_log_level = Catamaran::LogLevel::DEBUG
68
+ Catamaran::Manager.formatter_class = Catamaran::Formatter::NoCallerFormatter
69
+
70
+ class SecondRubyDemo
71
+ LOGGER = Catamaran.logger( { :class => name(), :file => __FILE__ } )
72
+
73
+ def run
74
+ LOGGER.debug( "Sample DEBUG statement", { :line => __LINE__, :method => 'run'} ) if LOGGER.debug?
75
+ end
76
+ end
77
+
78
+ class ThirdRubyDemo
79
+ LOGGER = Catamaran.logger( "com.mycompany.ThirdRubyDemo", { :class => name(), :file => __FILE__ } )
80
+
81
+ def run
82
+ LOGGER.debug( "Sample DEBUG statement", { :line => __LINE__, :method => 'run'} ) if LOGGER.debug?
83
+ end
84
+ end
85
+
86
+ SecondRubyDemo.new.run
87
+ ThirdRubyDemo.new.run
88
+
89
+ And the output
90
+
91
+ DEBUG pid-2729 [2013-12-23 19:35:35:732] - Sample DEBUG statement (catamaran_ruby_demos.rb:21:in `SecondRubyDemo.run')
92
+ DEBUG pid-2729 [2013-12-23 19:35:35:732] com.mycompany.ThirdRubyDemo - Sample DEBUG statement (catamaran_ruby_demos.rb:29:in `ThirdRubyDemo.run')
93
+
88
94
 
89
95
  Inspiration
90
96
  -----------
@@ -98,6 +104,60 @@ I'm looking for a logging utility that:
98
104
  * is capable of capturing logs at different log level thresholds from different parts of the app simultaneously
99
105
  * readily works with Rails
100
106
 
107
+
108
+ Performance Considerations
109
+ --------------------------
110
+ require 'catamaran'
111
+ require 'benchmark'
112
+
113
+ Catamaran::LogLevel.default_log_level = Catamaran::LogLevel::INFO
114
+ Catamaran::Manager.formatter_class = Catamaran::Formatter::NoCallerFormatter
115
+
116
+ class CatamaranPerformanceTest
117
+ LOGGER = Catamaran.logger( "CatamaranPerformanceTest" )
118
+
119
+ # NOTE that the log level for this test is set to INFO,
120
+ # so 'warn' logs are enabled and 'debug' logs are disabled
121
+
122
+ n = 500000
123
+ Benchmark.bm(7) do |x|
124
+ x.report("warn WITHOUT if LOGGER.warn? ") {
125
+ n.times do |i|
126
+ LOGGER.warn "This is a WARN"
127
+ end
128
+ }
129
+ x.report("warn WITH if LOGGER.warn? ") {
130
+ n.times do |i|
131
+ LOGGER.warn "This is a WARN" if LOGGER.warn?
132
+ end
133
+ }
134
+ end
135
+
136
+ Benchmark.bm(7) do |x|
137
+ x.report("debug WITHOUT if LOGGER.debug?") {
138
+ n.times do |i|
139
+ LOGGER.debug "This is a DEBUG"
140
+ end
141
+ }
142
+ x.report("debug WITH if LOGGER.debug? ") {
143
+ n.times do |i|
144
+ LOGGER.debug "This is a DEBUG" if LOGGER.debug?
145
+ end
146
+ }
147
+ end
148
+
149
+ end
150
+
151
+
152
+ # user system total real
153
+ # warn WITHOUT if LOGGER.warn? 6.520000 0.020000 6.540000 ( 6.533741)
154
+ # warn WITH if LOGGER.warn? 7.110000 0.020000 7.130000 ( 7.129708)
155
+ # user system total real
156
+ # debug WITHOUT if LOGGER.debug? 0.610000 0.010000 0.620000 ( 0.623714)
157
+ # debug WITH if LOGGER.debug? 0.530000 0.010000 0.540000 ( 0.544295)
158
+
159
+
160
+
101
161
  Ideas around what's next
102
162
  ------------------------
103
163
 
@@ -1,13 +1,5 @@
1
1
  module Catamaran
2
2
  class LogLevel
3
- TRACE = 1000
4
- DEBUG = 2000
5
- INFO = 3000
6
- WARN = 4000
7
- ERROR = 5000
8
- SEVERE = 6000
9
- FATAL = 7000
10
-
11
3
  # By default, logger.io messages will be captured when the log level is DEBUG (IO_LESS_CRITICAL_THAN_INFO)
12
4
  # If that's too verbose, the level can be changed to IO_LESS_CRITICAL_THAN_DEBUG and logger.io messages won't be
13
5
  # visible unless the log level is set to TRACE.
@@ -15,8 +7,18 @@ module Catamaran
15
7
  IO_LESS_CRITICAL_THAN_DEBUG = 1080
16
8
  IO_LESS_CRITICAL_THAN_INFO = 2080
17
9
 
10
+
11
+ TRACE = 1000
12
+ DEBUG = 2000
13
+ INFO = 3000
14
+ WARN = 4000
15
+ ERROR = 5000
16
+ SEVERE = 6000
17
+ FATAL = 7000
18
18
  IO = IO_LESS_CRITICAL_THAN_INFO
19
19
 
20
+
21
+
20
22
  def self.reset
21
23
  @@default_log_level = INFO
22
24
 
@@ -1,4 +1,4 @@
1
1
  module Catamaran
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
4
4
 
data/lib/catamaran.rb CHANGED
@@ -46,7 +46,10 @@ end
46
46
  # add rails integration
47
47
  require('catamaran/integration/rails') if defined?(Rails)
48
48
 
49
- # Catamaran::Manager.stderr = true
49
+ # By default, Catamaran should write messages to STDERR (in addition to anywhere else configured)
50
+ Catamaran::Manager.stderr = true
51
+
52
+ # By default, Catamaran will not write message to STDOUT
50
53
  # Catamaran::Manager.stdout = false
51
54
 
52
55
  ##
@@ -13,3 +13,15 @@ Catamaran::LogLevel.default_log_level = Catamaran::LogLevel::DEBUG
13
13
 
14
14
  # The NoCallerFormatter is the default.
15
15
  Catamaran::Manager.formatter_class = Catamaran::Formatter::CallerFormatter
16
+
17
+ # Uncomment to enable Catamaran internal debugging
18
+ # Catamaran::debugging = true
19
+
20
+ ##
21
+ # Detailed log levels
22
+
23
+ # Uncomment to set the default log level for all models to be TRACE
24
+ # Catamaran.logger.com.mycompany.myrailsapp.app.models = Catamaran::LogLevel::TRACE
25
+
26
+ # Uncomment to set the default log level for all controllers to be WARN
27
+ # Catamaran.logger.com.mycompany.myrailsapp.app.controllers = Catamaran::LogLevel::WARN
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catamaran
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeano
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2013-12-23 00:00:00 -06:00
12
+ date: 2013-12-26 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15