press 0.15 → 0.16
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/press.rb +10 -5
- data/lib/press/printer.rb +24 -10
- metadata +2 -2
data/lib/press.rb
CHANGED
@@ -6,24 +6,29 @@ module Press
|
|
6
6
|
Printer.ctx = data
|
7
7
|
end
|
8
8
|
|
9
|
+
def mtx(tag)
|
10
|
+
Printer.mtx = tag
|
11
|
+
end
|
12
|
+
|
9
13
|
def mctx(tag, data)
|
10
|
-
|
14
|
+
mtx tag
|
15
|
+
ctx data
|
11
16
|
end
|
12
17
|
|
13
18
|
def pd(*data, &blk)
|
14
19
|
Printer.pd *data, &blk
|
15
20
|
end
|
16
21
|
|
17
|
-
def mpd(*data)
|
18
|
-
Printer.mpd *data
|
22
|
+
def mpd(*data, &blk)
|
23
|
+
Printer.mpd *data, &blk
|
19
24
|
end
|
20
25
|
|
21
26
|
def pdfm(file, m, *data, &blk)
|
22
27
|
Printer.pdfm file, m, *data, &blk
|
23
28
|
end
|
24
29
|
|
25
|
-
def mpdfm(file, m, *data)
|
26
|
-
Printer.mpdfm file, m, *data
|
30
|
+
def mpdfm(file, m, *data, &blk)
|
31
|
+
Printer.mpdfm file, m, *data, &blk
|
27
32
|
end
|
28
33
|
|
29
34
|
def pde(e, *data)
|
data/lib/press/printer.rb
CHANGED
@@ -15,40 +15,40 @@ module Press
|
|
15
15
|
write $stdout, hashify(*data, {}), &blk
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.mpd(*data)
|
19
|
-
|
18
|
+
def self.mpd(*data, &blk)
|
19
|
+
mwrite $stdout, @mtx, hashify(*data, {}), &blk
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.pdfm(file, m, *data, &blk)
|
23
23
|
write $stdout, hashify(*data, :file => File.basename(file, ".rb"), :fn => m), &blk
|
24
24
|
end
|
25
25
|
|
26
|
-
def self.mpdfm(file, m, *data)
|
27
|
-
|
26
|
+
def self.mpdfm(file, m, *data, &blk)
|
27
|
+
mwrite $stdout, [@mtx, File.basename(file, ".rb"), m].compact.join("."), hashify(*data, :file => File.basename(file, ".rb"), :fn => m), &blk
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.pde(e, *data)
|
31
|
-
write $stderr, hashify(*data, :at => "error", :class => e.class, :message => e.message.lines.to_a.first, :trace => e.backtrace.map { |i| i.match(/(#{Gem.dir}|#{Dir.getwd})?\/(.*):in (.*)/) && $2 }[0..5].inspect)
|
31
|
+
write $stderr, hashify(*data, :at => "error", :class => e.class, :message => e.message.lines.to_a.first, :trace => e.backtrace.map { |i| i.match(/(#{Gem.dir}|#{Dir.getwd})?\/(.*):in (.*)/) && $2 }[0..5].compact.inspect)
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.mpde(e, *data)
|
35
|
-
|
35
|
+
mwrite $stderr, [@mtx, "error"].compact.join("."), hashify(*data, :at => "error", :class => e.class, :message => e.message.lines.to_a.first, :trace => e.backtrace.map { |i| i.match(/(#{Gem.dir}|#{Dir.getwd})?\/(.*):in (.*)/) && $2 }[0..5].compact.inspect)
|
36
36
|
end
|
37
37
|
|
38
38
|
def self.pdfme(file, m, e, *data)
|
39
|
-
write $stderr, hashify(*data, :at => "error", :class => e.class, :message => e.message.lines.to_a.first, :trace => e.backtrace.map { |i| i.match(/(#{Gem.dir}|#{Dir.getwd})?\/(.*):in (.*)/) && $2 }[0..5].inspect, :file => File.basename(file, ".rb"), :fn => m)
|
39
|
+
write $stderr, hashify(*data, :at => "error", :class => e.class, :message => e.message.lines.to_a.first, :trace => e.backtrace.map { |i| i.match(/(#{Gem.dir}|#{Dir.getwd})?\/(.*):in (.*)/) && $2 }[0..5].compact.inspect, :file => File.basename(file, ".rb"), :fn => m)
|
40
40
|
end
|
41
41
|
|
42
42
|
def self.mpdfme(file, m, e, *data)
|
43
|
-
|
43
|
+
mwrite $stderr, [@mtx, "error"].compact.join("."), hashify(*data, :at => "error", :class => e.class, :message => e.message.lines.to_a.first, :trace => e.backtrace.map { |i| i.match(/(#{Gem.dir}|#{Dir.getwd})?\/(.*):in (.*)/) && $2 }[0..5].compact.inspect, :file => File.basename(file, ".rb"), :fn => m)
|
44
44
|
end
|
45
45
|
|
46
46
|
def self.hashify(*data, initial)
|
47
47
|
data.compact.reduce(initial.merge(@ctx || {})) { |d, v| d.merge v }
|
48
48
|
end
|
49
49
|
|
50
|
-
def self.
|
51
|
-
|
50
|
+
def self.mtag(tag, data)
|
51
|
+
data.tap { |d| d[:measure] = [tag, d[:event]].compact.join(".") if tag }
|
52
52
|
end
|
53
53
|
|
54
54
|
def self.stringify(data)
|
@@ -81,5 +81,19 @@ module Press
|
|
81
81
|
yield.tap { write file, { :at => "finish", :elapsed => Time.now - start }.merge(data) }
|
82
82
|
end
|
83
83
|
end
|
84
|
+
|
85
|
+
def self.mwrite(file, tag, data, &blk)
|
86
|
+
unless blk
|
87
|
+
file.puts stringify(mtag(tag, data))
|
88
|
+
file.flush
|
89
|
+
else
|
90
|
+
start = Time.now
|
91
|
+
write file, { :at => "start" }.merge(data)
|
92
|
+
yield.tap do
|
93
|
+
elapsed = Time.now - start
|
94
|
+
mwrite file, tag, { :at => "finish", :elapsed => elapsed }.merge(data).tap { |d| d[:val] = elapsed if tag }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
84
98
|
end
|
85
99
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: press
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.16'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-17 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Data and exception printer.
|
15
15
|
email: mark.fine@gmail.com
|