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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8fff702a88edcf12e690bc426dc20f31f17ed0d
4
- data.tar.gz: 12b43475977dd21b946f034a81d78bf0511b758f
3
+ metadata.gz: 489236aacb3714c55ea91562be7530b61d3bd573
4
+ data.tar.gz: 5c1c4576e85e5887b35a9ce472cec901f01d7e90
5
5
  SHA512:
6
- metadata.gz: a91ee53c379d04b8f2e5df225494442bfc89670e3e0a8d0e6cb36aec5afb0929a50bdabcb6663b35ae23ca060765aa45b50a7be714253003961eb9dc7412daba
7
- data.tar.gz: d110af9984b5e2e6f062ff1f6c9f77d08c0976a2a4a7acdcddef9de862b6227e042a87cf3563c60bfc9df5c508c2120ba3fe1f90543a8ab32152a155dc9b0703
6
+ metadata.gz: af337f4fbb1e151c787810d63cbbb2d0f16d3631dea31579f2b2d11b4a04228e2b1f423272d19f7f1d33fffc580138363f9f8b4e033ea2e37852c659dc7b4013
7
+ data.tar.gz: c7b80f7b7e1879da50e54a81250f03aa6358f488539cf1ee7d8fe18d6f9e70911dcead16a2bed0e149a92f7b8aac26c86e4f49dbb0afc66a2d736e2783be7300
@@ -1,3 +1,8 @@
1
+ ### Version 0.7.0 / 2017-05-07
2
+
3
+ * Debugging information now uses a Logger, which can be configured.
4
+
5
+
1
6
  ### Version 0.6.3 / 2017-03-24
2
7
 
3
8
  See beta release notes.
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`.
@@ -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
- $stderr.puts msg
179
+ logger.warn msg
168
180
  end
169
181
  end
170
182
 
@@ -176,7 +176,7 @@ module ChildProcess
176
176
  end
177
177
 
178
178
  def log(*args)
179
- $stderr.puts "#{self.inspect} : #{args.inspect}" if $DEBUG
179
+ ChildProcess.logger.debug "#{self.inspect} : #{args.inspect}"
180
180
  end
181
181
 
182
182
  def assert_started
@@ -44,7 +44,8 @@ module ChildProcess
44
44
 
45
45
  @output.flush
46
46
  rescue java.io.IOException => ex
47
- $stderr.puts ex.message, ex.backtrace if $DEBUG
47
+ ChildProcess.logger.debug ex.message
48
+ ChildProcess.logger.debug ex.backtrace
48
49
  end
49
50
 
50
51
  end # Pump
@@ -1,3 +1,3 @@
1
1
  module ChildProcess
2
- VERSION = '0.6.3'
2
+ VERSION = '0.7.0'
3
3
  end
@@ -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
@@ -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.6.3
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-03-25 00:00:00.000000000 Z
12
+ date: 2017-05-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi