logg 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +1 -1
- data/README.md +76 -8
- data/lib/logg/version.rb +1 -1
- metadata +157 -4
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -22,9 +22,34 @@ Foo.new.log.debug "test…" # => Fri Dec 31 16:00:09 +0100 2010 | [debug] test
|
|
22
22
|
Foo.new.log.error "failed" # => Fri Dec 31 16:00:09 +0100 2010 | [error] failed
|
23
23
|
```
|
24
24
|
|
25
|
-
|
25
|
+
You may also just instantiate a Logg dispatcher. This is less intrusive, no
|
26
|
+
mixin involved, allow for changing the dispatcher's name and have several
|
27
|
+
loggers lurking around:
|
26
28
|
|
27
|
-
|
29
|
+
``` ruby
|
30
|
+
report = Logg::Dispatcher.new
|
31
|
+
report.failure 'danger' # => "2011-07-02 20:27:01 +0200 | [failure] danger"
|
32
|
+
```
|
33
|
+
|
34
|
+
``` ruby
|
35
|
+
class Foo
|
36
|
+
attr_reader :report
|
37
|
+
|
38
|
+
def initialize
|
39
|
+
@report = Logg::Dispatcher.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def bar
|
43
|
+
report.something 'important'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
Foo.new.bar # => "2011-07-02 20:27:01 +0200 | [something] important"
|
47
|
+
```
|
48
|
+
|
49
|
+
This illustrates the basic use cases. The default logging format is a string
|
50
|
+
sent to `$stdout`, formatted as `time | [namespace] message` where "namespace" is the method called on the logger.
|
51
|
+
|
52
|
+
But this is only the default implementation of the message dispatcher. Many other examples are available under the `examples/` directory (based on the Cucumber `features/`). The next part of this README explains some of those use-cases.
|
28
53
|
|
29
54
|
## Custom loggers
|
30
55
|
|
@@ -53,7 +78,12 @@ Note: if you would like to define a custom logger under the name `#as`, the help
|
|
53
78
|
|
54
79
|
## Message formatting, templates
|
55
80
|
|
56
|
-
Logging is all about building meaningful messages. You may also want to log to
|
81
|
+
Logging is all about building meaningful messages. You may also want to log to
|
82
|
+
the tty, a file and send an email on top of that, and each one of those output
|
83
|
+
channels would benefit from using a different data representation. One should
|
84
|
+
thus be provided with efficient tools to define how a message is rendered in
|
85
|
+
particular context. Logg makes use of [Tilt](https://github.com/rtomayko/tilt)
|
86
|
+
to help you format your data. [Tilt](https://github.com/rtomayko/tilt) is a wrapper around several template engines (you may know about ERB or haml, but there are many others). Just tell Logg which format you want to use and go ahead! The dispatching logic is of your responsability.
|
57
87
|
|
58
88
|
For more details, see `examples/` and read/run the Cucumber `features/` (command: `cucumber features`).
|
59
89
|
|
@@ -79,20 +109,58 @@ class Foo
|
|
79
109
|
|
80
110
|
# now we want to render an external HAML template, providing its path with
|
81
111
|
# or withouth the .haml extension (if not provided, the :as option is mandatory)
|
82
|
-
|
83
|
-
|
112
|
+
# note we expect two parameters for this logger
|
113
|
+
log.as(:http_response) do |response, params|
|
114
|
+
output = render('tpl/foo.haml', :data => response, :locals => { :params => params})
|
84
115
|
# do something with output, for instance, send a mail notification when not a 200
|
85
116
|
end
|
86
|
-
log.http_response(resp) # performs the block, really
|
117
|
+
log.http_response(resp, request.params) # performs the block, really
|
87
118
|
end
|
88
119
|
```
|
89
120
|
|
90
121
|
If you want to render to several logging endpoints, and send a mail on top of that, just do it within the block!
|
91
122
|
|
123
|
+
Both `#render_inline` and `#render` follow [Tilt](https://github.com/rtomayko/tilt)'s implementation. The `:data`
|
124
|
+
object is any Ruby object which be promoted as `self` when rendering the
|
125
|
+
template. In the last example, if `foo.haml` where to contain calls to
|
126
|
+
methods such as `status` or `body`, this would mean running `response.status`
|
127
|
+
and `response.body` within the template. The `:locals` are additional
|
128
|
+
variables one may need to interpolate the template. In the last example, we
|
129
|
+
are passing the request parameters along the response object. You basically
|
130
|
+
define your loggers the way you want (see `Advice` section below for some
|
131
|
+
insight).
|
132
|
+
|
92
133
|
## Dispatching helpers
|
93
134
|
|
94
135
|
TODO: provide helpers for message dispatching/logging, levels managment and the like.
|
95
136
|
|
96
|
-
## About the
|
137
|
+
## About the implementation
|
138
|
+
|
139
|
+
* When a class mixins the `Logg::Machine` module, a `Logg::Dispatcher` instance is created and associated (if possible, see below) to the receiving class,
|
140
|
+
through method injection.
|
141
|
+
* The custom loggers blocks are runned in the context of a `Logg::Dispatcher::Render` class, so be aware you must inject in the closure any data you would require. This is by design so as to keep the logger's logic separated from the application burden, enforcing explicit control over the data payloads.
|
142
|
+
* If this is just too much a burden for you, you may avoid mixin `Logg::Machine` and just make use of the `Render` core implementation, by instantiating a new `Logg::Dispatcher` as illustrated in the Synopsis section above.
|
143
|
+
|
144
|
+
## Advice
|
145
|
+
|
146
|
+
When using MRI 1.9.2 or equivalent implementations, you can now define closure with dynamic params:
|
147
|
+
|
148
|
+
``` ruby
|
149
|
+
log.as(:report) do |name = 'toto', *args|
|
150
|
+
puts name
|
151
|
+
puts args
|
152
|
+
end
|
153
|
+
|
154
|
+
log.report # => toto
|
155
|
+
# []
|
156
|
+
log.report('joe') # => joe
|
157
|
+
# []
|
158
|
+
log.report('joe', {:foo => :bar}, 1) # => joe
|
159
|
+
# [{:foo => :bar}, 1]
|
160
|
+
```
|
161
|
+
|
162
|
+
It also support blocks as closure parameters ([more details](http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/)). All of this allows for building super-dynamic custom loggers.
|
163
|
+
|
164
|
+
## License
|
97
165
|
|
98
|
-
|
166
|
+
[MIT License](http://en.wikipedia.org/wiki/MIT_License). See the LICENSE file.
|
data/lib/logg/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: logg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jean-Denis Vauguet <jd@vauguet.fr>
|
@@ -10,10 +10,163 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-11 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
|
-
dependencies:
|
16
|
-
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: tilt
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: better
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: yard
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: test-unit
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: rspec
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: cucumber
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id006
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: aruba
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0"
|
91
|
+
type: :development
|
92
|
+
version_requirements: *id007
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: metric_fu
|
95
|
+
prerelease: false
|
96
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: "0"
|
102
|
+
type: :development
|
103
|
+
version_requirements: *id008
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: rcov
|
106
|
+
prerelease: false
|
107
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: "0"
|
113
|
+
type: :development
|
114
|
+
version_requirements: *id009
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: guard
|
117
|
+
prerelease: false
|
118
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: "0"
|
124
|
+
type: :development
|
125
|
+
version_requirements: *id010
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: guard-cucumber
|
128
|
+
prerelease: false
|
129
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: "0"
|
135
|
+
type: :development
|
136
|
+
version_requirements: *id011
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: guard-rspec
|
139
|
+
prerelease: false
|
140
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: "0"
|
146
|
+
type: :development
|
147
|
+
version_requirements: *id012
|
148
|
+
- !ruby/object:Gem::Dependency
|
149
|
+
name: rb-inotify
|
150
|
+
prerelease: false
|
151
|
+
requirement: &id013 !ruby/object:Gem::Requirement
|
152
|
+
none: false
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: "0"
|
157
|
+
type: :development
|
158
|
+
version_requirements: *id013
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: libnotify
|
161
|
+
prerelease: false
|
162
|
+
requirement: &id014 !ruby/object:Gem::Requirement
|
163
|
+
none: false
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: "0"
|
168
|
+
type: :development
|
169
|
+
version_requirements: *id014
|
17
170
|
description: A simple message dispatcher (aka. logger) for your ruby applications.
|
18
171
|
email: jd@vauguet.fr
|
19
172
|
executables: []
|