koa 0.0.1 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/koa/logger.rb +19 -19
- data/lib/koa/measurement.rb +10 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 478a408cb43b0149e505d7f09f5569195346cff3
|
4
|
+
data.tar.gz: 5db49dfe9a1eb30be09afa5cf847de300ad5033d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d89d6d9d73663b8ff5a5bd3af82db76b9d40d52fd811b4030df8598e306389ef34b884dc70f89764ee57f92bcfe8c24b8543b41252d362be765f542af7b28a60
|
7
|
+
data.tar.gz: 9ed081fa9a7e812fdaacb65f0b8e0b328a08579e006eaccc45addef791e336b16badc73e69642d1668ff39332c45eab56b61776f93a1c03814434eee7172f8f9
|
data/lib/koa/logger.rb
CHANGED
@@ -4,26 +4,26 @@ module Koa
|
|
4
4
|
def initialize
|
5
5
|
@msgs = []
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
def puts(msg)
|
9
9
|
@msgs << msg
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def flush
|
13
13
|
@msgs.length.times.map {@msgs.pop}
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
module NullLogger
|
18
18
|
def self.puts(*args)
|
19
|
-
|
19
|
+
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def self.flush(*args)
|
23
|
-
|
23
|
+
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
module Logger
|
28
28
|
def self.appname
|
29
29
|
@prefix ||= ENV['APP_NAME'].downcase if ENV['APP_NAME']
|
@@ -32,54 +32,54 @@ module Koa
|
|
32
32
|
end
|
33
33
|
@prefix ||= ""
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def self.prefix(name)
|
37
37
|
appname+name
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def self.librato_log(type, name, val, data)
|
41
41
|
name = prefix(name)
|
42
42
|
data["#{type}##{name}"] = val
|
43
43
|
log(data)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def self.out=(o)
|
47
47
|
@out = o
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def self.out
|
51
51
|
@out || $stdout
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def self.log(data)
|
55
55
|
out.puts(stringify(data))
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def self.measure_block(name, data = {})
|
59
59
|
start = Time.now
|
60
60
|
result = yield
|
61
61
|
elapsed = (Time.now.to_f - start.to_f) * 1000
|
62
|
-
measure(name, elapsed.round.to_s+"ms")
|
62
|
+
measure(name, elapsed.round.to_s+"ms", data)
|
63
63
|
result
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
def self.count(name, val, data = {})
|
67
67
|
librato_log("count", name, val, data)
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def self.measure(name, val, data = {})
|
71
71
|
librato_log("measure", name, val, data)
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
def self.sample(name, val, data = {})
|
75
75
|
librato_log("sample", name, val, data)
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
def self.stringify(data)
|
79
79
|
data.reduce(out=String.new) do |s, tup|
|
80
80
|
s << [tup.first, tup.last].join("=") << " "
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
end
|
data/lib/koa/measurement.rb
CHANGED
@@ -5,6 +5,14 @@ module Koa
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module ClassMethods
|
8
|
+
def measurement_name(method)
|
9
|
+
self.name.gsub(/::/, '/').
|
10
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
11
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
12
|
+
tr("-", "_").
|
13
|
+
downcase + "." + method.to_s.gsub(/_/,"-")
|
14
|
+
end
|
15
|
+
|
8
16
|
def measure_methods(*args)
|
9
17
|
@methods_to_measure ||= []
|
10
18
|
@methods_to_measure += args
|
@@ -18,7 +26,7 @@ module Koa
|
|
18
26
|
unmeasured_name = "unmeasured_#{name}"
|
19
27
|
alias_method unmeasured_name, name
|
20
28
|
define_method name do |*args, &block|
|
21
|
-
Koa::Logger.measure_block(
|
29
|
+
Koa::Logger.measure_block(self.class.measurement_name(name)) do
|
22
30
|
send unmeasured_name, *args, &block
|
23
31
|
end
|
24
32
|
end
|
@@ -33,7 +41,7 @@ module Koa
|
|
33
41
|
unmeasured_name = "unmeasured_#{name}"
|
34
42
|
self.singleton_class.send(:alias_method, unmeasured_name, name)
|
35
43
|
define_singleton_method name do |*args, &block|
|
36
|
-
Koa::Logger.measure_block(name
|
44
|
+
Koa::Logger.measure_block(measurement_name(name)) do
|
37
45
|
send unmeasured_name, *args, &block
|
38
46
|
end
|
39
47
|
end
|