tagged_logger 0.4.6 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +71 -7
- data/TODO.markdown +3 -23
- data/lib/tagged_logger/railtie.rb +19 -3
- data/lib/tagged_logger/tagged_logger.rb +2 -2
- metadata +5 -5
data/README.markdown
CHANGED
@@ -107,16 +107,80 @@ You may also use regular expressions in your rules:
|
|
107
107
|
end
|
108
108
|
|
109
109
|
|
110
|
-
|
111
|
-
*TaggedLogger* is released under the MIT license.
|
112
|
-
|
113
|
-
## Shortcomings
|
114
|
-
The *#info(), #debug(), #warn(), #error(), #fatal()* rules when having form like *:to => logger*, the
|
115
|
-
*logger* **has** to be an object of standard library *Logger* class. If you need to use different sort of logger
|
116
|
-
the more general rules form is:
|
110
|
+
There is more general form for rules, it accepts block with three params:
|
117
111
|
|
118
112
|
TaggedLogger.rules do
|
119
113
|
info /Whatever/ do |level, tag, message|
|
120
114
|
#do your special logging here
|
121
115
|
end
|
122
116
|
end
|
117
|
+
|
118
|
+
As previously explained the *tag* is a class name the *#logger* is being called from (except when you override Rails instrumentation, see below)
|
119
|
+
|
120
|
+
## Integration with Rails (only Rails 3.0 supported at the moment, not completely tested):
|
121
|
+
|
122
|
+
Installation:
|
123
|
+
|
124
|
+
$ gem install tagged_logger
|
125
|
+
|
126
|
+
Rails has two facility for logging - *#logger* method injected in base classes such in ActiveRecord::Base and instrumentation. Instrumentation is somewhat which allows to issue an event upon execution of
|
127
|
+
block, for example:
|
128
|
+
|
129
|
+
def sendfile(path, options={})
|
130
|
+
ActiveSupport::Notifications.instrument("sendfile.action_controller") do
|
131
|
+
#do actual file send
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
The event *"sendfile.action_controller"* will be issued and one could subscribe to that event:
|
136
|
+
|
137
|
+
ActiveSupport::Notifications.subscribe("sendfile.action_controller") do
|
138
|
+
#do something, for example log an event
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
Actually Rails subscribers - they are responsible for majority of logging in Rails.
|
143
|
+
*TaggedLogger* allows you to override how those subscribers do actual logging, for example if you want to override it for *ActionController*:
|
144
|
+
|
145
|
+
# "#{Rails.root}/config/initializers/tagged_logger.rb"
|
146
|
+
TaggedLogger.rules(:override=>true) do
|
147
|
+
debug "action_controller.instrumentation" do |level, tag, msg|
|
148
|
+
puts "#{tag} {msg}" #msg formed by ActionController::LogSubscriber goes here, tag is 'action_controller.instrumentation'
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
If you like to have a special logging not only for *ActionController*, but rather for everything logged by Rails via instrumentation mechanism, you could use a
|
153
|
+
rule with regular expression:
|
154
|
+
|
155
|
+
debug /.*\.instrumentation$/ do |level, tag, msg|
|
156
|
+
#you special logging
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
Since *#logger* is defined by Rails for classes you inherits from (*ActionController::Base*, *ActiveRecord::Base*), you have to initialize *TaggedLogger* with
|
161
|
+
|
162
|
+
:override => true
|
163
|
+
|
164
|
+
option since by default *TaggedLogger* is trying to be safe and does not override existing *#logger* method:
|
165
|
+
|
166
|
+
class ApplicationController < ActionController::Base
|
167
|
+
def welcome
|
168
|
+
logger.info "welcome..."
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
# "#{Rails.root}/config/initializers/tagged_logger.rb"
|
173
|
+
TaggedLogger.rules(:override=>true) do
|
174
|
+
debug /.*Controller$/ do |level, tag, msg|
|
175
|
+
puts "Here I dump whatever happens in controllers, including ApplicationController"
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
## License
|
182
|
+
*TaggedLogger* is released under the MIT license.
|
183
|
+
|
184
|
+
## Shortcomings
|
185
|
+
The *#info(), #debug(), #warn(), #error(), #fatal()* rules when having form like *:to => logger*, the
|
186
|
+
*logger* **has** to be an object of standard library *Logger* class.
|
data/TODO.markdown
CHANGED
@@ -1,26 +1,6 @@
|
|
1
|
-
###
|
2
|
-
|
3
|
-
|
4
|
-
end
|
5
|
-
|
6
|
-
We specify *debug* rule, so what the need to pass it as a param? May be:
|
7
|
-
|
8
|
-
any_level /something/ do |level, tag, msg|
|
9
|
-
end
|
10
|
-
|
11
|
-
and
|
12
|
-
|
13
|
-
debug /something/ do |tag, msg|
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
### Integration with Rails instrumenation, may be somewhat like:
|
19
|
-
|
20
|
-
debug 'sql.active_record' do |msg| do
|
21
|
-
# custom handling for Rails 'sql.active_record' instrumentation
|
22
|
-
end
|
23
|
-
|
1
|
+
### ActiveResource::LogSubscriber instrumentation
|
2
|
+
### Tests for Rails instrumentation
|
3
|
+
### Refactor TagMatcher#match? with ===
|
24
4
|
### Documentation
|
25
5
|
|
26
6
|
### Ability to accept blocks as arguments for #debug, #info, and alike, i.e.:
|
@@ -1,9 +1,25 @@
|
|
1
1
|
if defined?(Rails::Railtie)
|
2
2
|
module TaggedLogger
|
3
3
|
class Railtie < Rails::Railtie
|
4
|
-
ActiveSupport.on_load(:action_controller)
|
5
|
-
|
6
|
-
|
4
|
+
ActiveSupport.on_load(:action_controller) do
|
5
|
+
TaggedLogger.send(:inject_logger_method_in_call_chain, ActionController::Base)
|
6
|
+
TaggedLogger.send(:inject_logger_method_in_call_chain, ActionController::LogSubscriber)
|
7
|
+
TaggedLogger.rename [ActionController::LogSubscriber] => "action_controller.instrumentation"
|
8
|
+
end
|
9
|
+
ActiveSupport.on_load(:active_record) do
|
10
|
+
TaggedLogger.send(:inject_logger_method_in_call_chain, ActiveRecord::Base)
|
11
|
+
TaggedLogger.send(:inject_logger_method_in_call_chain, ActiveRecord::LogSubscriber)
|
12
|
+
TaggedLogger.rename [ActiveRecord::LogSubscriber] => "active_record.instrumentation"
|
13
|
+
end
|
14
|
+
ActiveSupport.on_load(:action_mailer) do
|
15
|
+
TaggedLogger.send(:inject_logger_method_in_call_chain, ActionMailer::Base)
|
16
|
+
TaggedLogger.send(:inject_logger_method_in_call_chain, ActionMailer::LogSubscriber)
|
17
|
+
TaggedLogger.rename [ActionMailer::LogSubscriber] => "action_mailer.instrumentation"
|
18
|
+
end
|
19
|
+
ActiveSupport.on_load(:action_view) do
|
20
|
+
TaggedLogger.send(:inject_logger_method_in_call_chain, ActionView::LogSubscriber)
|
21
|
+
TaggedLogger.rename [ActionView::LogSubscriber] => "action_view.instrumentation"
|
22
|
+
end
|
7
23
|
end
|
8
24
|
end
|
9
25
|
end
|
@@ -132,10 +132,10 @@ module TaggedLogger
|
|
132
132
|
TagMatcher.new(tag, level)
|
133
133
|
end
|
134
134
|
|
135
|
-
def tag_aliases(tag
|
135
|
+
def tag_aliases(tag)
|
136
136
|
current_name = tag
|
137
137
|
@rename_rules.each { |from, to| current_name = to if from.match?(tag) }
|
138
|
-
|
138
|
+
yield current_name
|
139
139
|
end
|
140
140
|
|
141
141
|
def tag_blocks(level, tag, &block)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tagged_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Aleksandr Furmanov
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-29 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|