datalogger 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +50 -2
- data/lib/datalogger.rb +2 -6
- data/lib/datalogger/version.rb +1 -1
- metadata +1 -1
data/Readme.md
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
# DataLogger (alpha)
|
2
|
-
A simple structured data logger. Pass it a hash, and it takes care of
|
1
|
+
# DataLogger (alpha - API should be considered unstable)
|
2
|
+
A simple structured data logger. Pass it a hash, and it takes care of emitting to stdout.
|
3
|
+
|
4
|
+
Inspiration largely comes from ["The Twelve-Factor App"](http://www.12factor.net/logs) by Adam Wiggins, Mark McGranaghan's ["Logs as Data"](https://github.com/relevance/clojure-conj/blob/master/2011-slides/mark-mcgranaghan-logs-as-data.pdf) talk, and various experiments at [Heroku](http://heroku.com).
|
3
5
|
|
4
6
|
## Usage
|
7
|
+
### The most obvious way:
|
5
8
|
```ruby
|
6
9
|
require 'datalogger'
|
7
10
|
|
@@ -32,3 +35,48 @@ This will generate a message that looks something like so:
|
|
32
35
|
myapp action=create_user at=start
|
33
36
|
myapp action=create_user at=finish elapsed=0.003116
|
34
37
|
```
|
38
|
+
|
39
|
+
###As a singleton:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'datalogger'
|
43
|
+
|
44
|
+
DataLogger::Logger.component = 'myapp'
|
45
|
+
DataLogger::Logger.log a: 1, b: 2, c: 3
|
46
|
+
```
|
47
|
+
|
48
|
+
### Mixing in instance methods
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
require 'datalogger'
|
52
|
+
|
53
|
+
DataLogger::Logger.component = 'myapp'
|
54
|
+
|
55
|
+
class MyThing
|
56
|
+
include DataLogger
|
57
|
+
|
58
|
+
def do_something
|
59
|
+
log(action: 'do_something') do
|
60
|
+
# code goes here
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
### Mixing in class methods
|
67
|
+
```ruby
|
68
|
+
require 'datalogger'
|
69
|
+
|
70
|
+
DataLogger::Logger.component = 'myapp'
|
71
|
+
|
72
|
+
class MyThing
|
73
|
+
extend DataLogger
|
74
|
+
|
75
|
+
def self.do_something
|
76
|
+
log(action: 'do_something') do
|
77
|
+
# code goes here
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
```
|
82
|
+
|
data/lib/datalogger.rb
CHANGED
data/lib/datalogger/version.rb
CHANGED