childprocess 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +10 -0
- data/lib/childprocess.rb +13 -1
- data/lib/childprocess/abstract_process.rb +1 -1
- data/lib/childprocess/jruby/pump.rb +2 -1
- data/lib/childprocess/version.rb +1 -1
- data/spec/childprocess_spec.rb +76 -0
- data/spec/spec_helper.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 489236aacb3714c55ea91562be7530b61d3bd573
|
4
|
+
data.tar.gz: 5c1c4576e85e5887b35a9ce472cec901f01d7e90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af337f4fbb1e151c787810d63cbbb2d0f16d3631dea31579f2b2d11b4a04228e2b1f423272d19f7f1d33fffc580138363f9f8b4e033ea2e37852c659dc7b4013
|
7
|
+
data.tar.gz: c7b80f7b7e1879da50e54a81250f03aa6358f488539cf1ee7d8fe18d6f9e70911dcead16a2bed0e149a92f7b8aac26c86e4f49dbb0afc66a2d736e2783be7300
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -154,6 +154,16 @@ ChildProcess.build("cmd.exe", "/c", "bundle")
|
|
154
154
|
ChildProcess.build("ruby", "-S", "bundle")
|
155
155
|
```
|
156
156
|
|
157
|
+
#### Log to file
|
158
|
+
|
159
|
+
Errors and debugging information are logged to `$stderr` by default but a custom logger can be used instead.
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
logger = Logger.new('logfile.log')
|
163
|
+
logger.level = Logger::DEBUG
|
164
|
+
ChildProcess.logger = logger
|
165
|
+
```
|
166
|
+
|
157
167
|
## Caveats
|
158
168
|
|
159
169
|
* With JRuby on Unix, modifying `ENV["PATH"]` before using childprocess could lead to 'Command not found' errors, since JRuby is unable to modify the environemnt used for PATH searches in `java.lang.ProcessBuilder`. This can be avoided by setting `ChildProcess.posix_spawn = true`.
|
data/lib/childprocess.rb
CHANGED
@@ -3,12 +3,15 @@ require 'childprocess/errors'
|
|
3
3
|
require 'childprocess/abstract_process'
|
4
4
|
require 'childprocess/abstract_io'
|
5
5
|
require "fcntl"
|
6
|
+
require 'logger'
|
6
7
|
|
7
8
|
module ChildProcess
|
8
9
|
|
9
10
|
@posix_spawn = false
|
10
11
|
|
11
12
|
class << self
|
13
|
+
attr_writer :logger
|
14
|
+
|
12
15
|
def new(*args)
|
13
16
|
case os
|
14
17
|
when :macosx, :linux, :solaris, :bsd, :cygwin, :aix
|
@@ -27,6 +30,15 @@ module ChildProcess
|
|
27
30
|
end
|
28
31
|
alias_method :build, :new
|
29
32
|
|
33
|
+
def logger
|
34
|
+
return @logger if @logger
|
35
|
+
|
36
|
+
@logger = Logger.new($stderr)
|
37
|
+
@logger.level = $DEBUG ? Logger::DEBUG : Logger::INFO
|
38
|
+
|
39
|
+
@logger
|
40
|
+
end
|
41
|
+
|
30
42
|
def platform
|
31
43
|
if RUBY_PLATFORM == "java"
|
32
44
|
:jruby
|
@@ -164,7 +176,7 @@ module ChildProcess
|
|
164
176
|
|
165
177
|
unless @warnings[msg]
|
166
178
|
@warnings[msg] = true
|
167
|
-
|
179
|
+
logger.warn msg
|
168
180
|
end
|
169
181
|
end
|
170
182
|
|
data/lib/childprocess/version.rb
CHANGED
data/spec/childprocess_spec.rb
CHANGED
@@ -288,4 +288,80 @@ describe ChildProcess do
|
|
288
288
|
|
289
289
|
expect(proc).to be_exited
|
290
290
|
end
|
291
|
+
|
292
|
+
|
293
|
+
it 'has a logger' do
|
294
|
+
expect(ChildProcess).to respond_to(:logger)
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'can change its logger' do
|
298
|
+
expect(ChildProcess).to respond_to(:logger=)
|
299
|
+
|
300
|
+
original_logger = ChildProcess.logger
|
301
|
+
begin
|
302
|
+
ChildProcess.logger = :some_other_logger
|
303
|
+
expect(ChildProcess.logger).to eq(:some_other_logger)
|
304
|
+
ensure
|
305
|
+
ChildProcess.logger = original_logger
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
|
310
|
+
describe 'logger' do
|
311
|
+
|
312
|
+
before(:each) do
|
313
|
+
ChildProcess.logger = logger
|
314
|
+
end
|
315
|
+
|
316
|
+
after(:all) do
|
317
|
+
ChildProcess.logger = nil
|
318
|
+
end
|
319
|
+
|
320
|
+
|
321
|
+
context 'with the default logger' do
|
322
|
+
|
323
|
+
let(:logger) { nil }
|
324
|
+
|
325
|
+
|
326
|
+
it 'logs at INFO level by default' do
|
327
|
+
expect(ChildProcess.logger.level).to eq(Logger::INFO)
|
328
|
+
end
|
329
|
+
|
330
|
+
it 'logs at DEBUG level by default if $DEBUG is on' do
|
331
|
+
original_debug = $DEBUG
|
332
|
+
|
333
|
+
begin
|
334
|
+
$DEBUG = true
|
335
|
+
|
336
|
+
expect(ChildProcess.logger.level).to eq(Logger::DEBUG)
|
337
|
+
ensure
|
338
|
+
$DEBUG = original_debug
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
it "logs to stderr by default" do
|
343
|
+
cap = capture_std { generate_log_messages }
|
344
|
+
|
345
|
+
expect(cap.stdout).to be_empty
|
346
|
+
expect(cap.stderr).to_not be_empty
|
347
|
+
end
|
348
|
+
|
349
|
+
end
|
350
|
+
|
351
|
+
context 'with a custom logger' do
|
352
|
+
|
353
|
+
let(:logger) { Logger.new($stdout) }
|
354
|
+
|
355
|
+
|
356
|
+
it "logs to configured logger" do
|
357
|
+
cap = capture_std { generate_log_messages }
|
358
|
+
|
359
|
+
expect(cap.stdout).to_not be_empty
|
360
|
+
expect(cap.stderr).to be_empty
|
361
|
+
end
|
362
|
+
|
363
|
+
end
|
364
|
+
|
365
|
+
end
|
366
|
+
|
291
367
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -233,6 +233,14 @@ module ChildProcessSpecHelper
|
|
233
233
|
STDERR.reopen orig_err
|
234
234
|
end
|
235
235
|
|
236
|
+
def generate_log_messages
|
237
|
+
ChildProcess.logger.level = Logger::DEBUG
|
238
|
+
|
239
|
+
process = exit_with(0).start
|
240
|
+
process.wait
|
241
|
+
process.poll_for_exit(0.1)
|
242
|
+
end
|
243
|
+
|
236
244
|
end # ChildProcessSpecHelper
|
237
245
|
|
238
246
|
Thread.abort_on_exception = true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: childprocess
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jari Bakken
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-05-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|