async 1.13.1 → 1.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/async/logger.rb +29 -18
- data/lib/async/version.rb +1 -1
- data/spec/async/logger_spec.rb +8 -0
- metadata +2 -3
- data/lib/async/measure.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e95eca0cff51fba91c446924485001f6bd9d63978d92a15b583bbb8916b7c53b
|
4
|
+
data.tar.gz: 463002c552022842360fb031aee28c6286ed7af44761e3e8e55b60c40f1094bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d2848633ef85c07e88321c1cc5f4eb890fc53eb66c973dcf182ab5b535fa211b3493d1a265500c83a359bcd673912ea9b77a076e0c818add4ad82b7d5b35a11
|
7
|
+
data.tar.gz: 9814c99bbdb06a4993aefd573cf77795d813ee0f129d93cd7df1cc29522cd4f2b11b212a4d9c91d45bdd9f78114ee21ca55dac0fa51438a877124e08e69dd382
|
data/lib/async/logger.rb
CHANGED
@@ -89,32 +89,39 @@ module Async
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def format(subject = nil, *arguments, &block)
|
92
|
+
buffer = StringIO.new
|
92
93
|
prefix = time_offset_prefix
|
93
94
|
indent = " " * prefix.size
|
94
95
|
|
95
|
-
if block_given?
|
96
|
-
arguments << yield
|
97
|
-
end
|
98
|
-
|
99
96
|
if subject
|
100
|
-
format_subject(prefix, subject)
|
97
|
+
format_subject(prefix, subject, output: buffer)
|
101
98
|
end
|
102
99
|
|
103
100
|
arguments.each do |argument|
|
104
|
-
format_argument(indent, argument)
|
101
|
+
format_argument(indent, argument, output: buffer)
|
102
|
+
end
|
103
|
+
|
104
|
+
if block_given?
|
105
|
+
if block.arity.zero?
|
106
|
+
format_argument(indent, yield, output: buffer)
|
107
|
+
else
|
108
|
+
yield(buffer, @terminal)
|
109
|
+
end
|
105
110
|
end
|
111
|
+
|
112
|
+
@output.write buffer.string
|
106
113
|
end
|
107
114
|
|
108
|
-
def format_argument(prefix, argument)
|
115
|
+
def format_argument(prefix, argument, output: @output)
|
109
116
|
if argument.is_a? Exception
|
110
|
-
format_exception(prefix, argument)
|
117
|
+
format_exception(prefix, argument, output: output)
|
111
118
|
else
|
112
|
-
format_value(prefix, argument)
|
119
|
+
format_value(prefix, argument, output: output)
|
113
120
|
end
|
114
121
|
end
|
115
122
|
|
116
|
-
def format_exception(indent, exception, prefix = nil, pwd: Dir.pwd)
|
117
|
-
|
123
|
+
def format_exception(indent, exception, prefix = nil, pwd: Dir.pwd, output: @output)
|
124
|
+
output.puts "#{indent}| #{prefix}#{@exception_title_style}#{exception.class}#{@reset_style}: #{exception}"
|
118
125
|
|
119
126
|
exception.backtrace.each_with_index do |line, index|
|
120
127
|
path, offset, message = line.split(":")
|
@@ -122,22 +129,26 @@ module Async
|
|
122
129
|
# Make the path a bit more readable
|
123
130
|
path.gsub!(/^#{pwd}\//, "./")
|
124
131
|
|
125
|
-
|
132
|
+
output.puts "#{indent}| #{index == 0 ? "→" : " "} #{@exception_line_style}#{path}:#{offset}#{@reset_style} #{message}"
|
126
133
|
end
|
127
134
|
|
128
135
|
if exception.cause
|
129
|
-
|
136
|
+
output.puts "#{indent}|"
|
130
137
|
|
131
|
-
format_exception(indent, exception.cause, "Caused by ", pwd: pwd)
|
138
|
+
format_exception(indent, exception.cause, "Caused by ", pwd: pwd, output: output)
|
132
139
|
end
|
133
140
|
end
|
134
141
|
|
135
|
-
def format_subject(prefix, subject)
|
136
|
-
|
142
|
+
def format_subject(prefix, subject, output: @output)
|
143
|
+
output.puts "#{@prefix_style}#{prefix}: #{@subject_style}#{subject}#{@reset_style}"
|
137
144
|
end
|
138
145
|
|
139
|
-
def format_value(indent, value)
|
140
|
-
|
146
|
+
def format_value(indent, value, output: @output)
|
147
|
+
string = value.to_s
|
148
|
+
|
149
|
+
string.each_line do |line|
|
150
|
+
output.puts "#{indent}: #{line}"
|
151
|
+
end
|
141
152
|
end
|
142
153
|
|
143
154
|
def time_offset_prefix
|
data/lib/async/version.rb
CHANGED
data/spec/async/logger_spec.rb
CHANGED
@@ -36,6 +36,14 @@ RSpec.describe Async::Logger do
|
|
36
36
|
|
37
37
|
expect(output.string).to_not include message
|
38
38
|
end
|
39
|
+
|
40
|
+
it "can log to buffer" do
|
41
|
+
subject.info do |buffer|
|
42
|
+
buffer << message
|
43
|
+
end
|
44
|
+
|
45
|
+
expect(output.string).to include message
|
46
|
+
end
|
39
47
|
end
|
40
48
|
|
41
49
|
described_class::LEVELS.each do |name, level|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nio4r
|
@@ -124,7 +124,6 @@ files:
|
|
124
124
|
- lib/async/debug/monitor.rb
|
125
125
|
- lib/async/debug/selector.rb
|
126
126
|
- lib/async/logger.rb
|
127
|
-
- lib/async/measure.rb
|
128
127
|
- lib/async/node.rb
|
129
128
|
- lib/async/notification.rb
|
130
129
|
- lib/async/queue.rb
|
data/lib/async/measure.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require 'benchmark'
|
22
|
-
|
23
|
-
module Async
|
24
|
-
def self.measure(*args, threshold: 1.0, &block)
|
25
|
-
result = nil
|
26
|
-
|
27
|
-
duration = Benchmark.realtime do
|
28
|
-
result = yield
|
29
|
-
end
|
30
|
-
|
31
|
-
return result
|
32
|
-
ensure
|
33
|
-
if duration && duration > threshold
|
34
|
-
warn "#{args.join(' ')} took #{duration}s"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|