koa-utils 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/koa-utils/logger.rb +77 -44
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: def7b9d5a92875c1d4aeec44696c474005e9651e
4
- data.tar.gz: 7f5186e6fbffe96a55fa0e85ccbb8f9d44e2c476
3
+ metadata.gz: 28698360221534e0bd5c1b86b6979352f3f8876c
4
+ data.tar.gz: 7e30b74a6c131b38f072f37fe7af282b850ef495
5
5
  SHA512:
6
- metadata.gz: 1d3f1645d5364269097bab9ab2c43e36092e7c2ce86756c78785826b8de19673e2cf5186d2eb92c27fd4007af6f2d1789c4535ddddf047700115965a51fe4ca4
7
- data.tar.gz: e23fdfaf0a66757744d1d880ac47f58affeca5ef789247ebc7250fdea506ff1893fbfaa25a4b56ce8c9313da2231fa6dbf63d32dc812e395a08d2b612d11c7db
6
+ metadata.gz: 044ba256ce989617459fb8e57e42f98b876513c55eb312f503f077e87fa5ce461d25fa177640e18ab756d4405de07f6496793b89efda685ee5a26e555df31eac
7
+ data.tar.gz: 11c03c3b2b21bcf57942c7867002f22e3638c7505d5d59c0af7fdd15075ef69a971cbc287168146b98e5d25e538302f9b9ac2c6f7272432ba55b95bb3eb375e2
@@ -1,52 +1,85 @@
1
1
  $stdout.sync = true
2
-
3
- module KOAUtils::Logger
4
-
5
- def self.appname
6
- @prefix ||= ENV['APP_NAME'].downcase if ENV['APP_NAME']
7
- if defined? ::Rails
8
- @prefix ||= Rails.application.class.parent_name.downcase+"."
2
+ module KOAUtils
3
+ class StringLogger
4
+ def initialize
5
+ @msgs = []
6
+ end
7
+
8
+ def puts(msg)
9
+ @msgs << msg
10
+ end
11
+
12
+ def flush
13
+ @msgs.length.times.map {@msgs.pop}
9
14
  end
10
- @prefix ||= ""
11
- end
12
-
13
- def self.prefix(name)
14
- appname+name
15
- end
16
-
17
- def self.librato_log(type, name, val, data)
18
- name = prefix(name)
19
- data["#{type}##{name}"] = val
20
- log(data)
21
- end
22
-
23
- def self.log(data)
24
- $stdout.puts(stringify(data))
25
- end
26
-
27
- def self.measure_block(name, data = {})
28
- start = Time.now
29
- result = yield
30
- elapsed = (Time.now.to_f - start.to_f) * 1000
31
- measure(name, elapsed.round.to_s+"ms")
32
- result
33
- end
34
-
35
- def self.count(name, val, data = {})
36
- librato_log("count", name, val, data)
37
- end
38
-
39
- def self.measure(name, val, data = {})
40
- librato_log("measure", name, val, data)
41
15
  end
42
16
 
43
- def self.sample(name, val, data = {})
44
- librato_log("sample", name, val, data)
17
+ module NullLogger
18
+ def self.puts(*args)
19
+
20
+ end
21
+
22
+ def self.flush(*args)
23
+
24
+ end
45
25
  end
46
26
 
47
- def self.stringify(data)
48
- data.reduce(out=String.new) do |s, tup|
49
- s << [tup.first, tup.last].join("=") << " "
27
+ module Logger
28
+ def self.appname
29
+ @prefix ||= ENV['APP_NAME'].downcase if ENV['APP_NAME']
30
+ if defined? ::Rails
31
+ @prefix ||= Rails.application.class.parent_name.downcase+"."
32
+ end
33
+ @prefix ||= ""
34
+ end
35
+
36
+ def self.prefix(name)
37
+ appname+name
38
+ end
39
+
40
+ def self.librato_log(type, name, val, data)
41
+ name = prefix(name)
42
+ data["#{type}##{name}"] = val
43
+ log(data)
44
+ end
45
+
46
+ def self.out=(o)
47
+ @out = o
48
+ end
49
+
50
+ def self.out
51
+ @out || $stdout
52
+ end
53
+
54
+ def self.log(data)
55
+ out.puts(stringify(data))
56
+ end
57
+
58
+ def self.measure_block(name, data = {})
59
+ start = Time.now
60
+ result = yield
61
+ elapsed = (Time.now.to_f - start.to_f) * 1000
62
+ measure(name, elapsed.round.to_s+"ms")
63
+ result
64
+ end
65
+
66
+ def self.count(name, val, data = {})
67
+ librato_log("count", name, val, data)
68
+ end
69
+
70
+ def self.measure(name, val, data = {})
71
+ librato_log("measure", name, val, data)
72
+ end
73
+
74
+ def self.sample(name, val, data = {})
75
+ librato_log("sample", name, val, data)
76
+ end
77
+
78
+ def self.stringify(data)
79
+ data.reduce(out=String.new) do |s, tup|
80
+ s << [tup.first, tup.last].join("=") << " "
81
+ end
50
82
  end
51
83
  end
52
- end
84
+
85
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koa-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Rykwalder