engineyard-serverside 1.5.25 → 1.5.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -42,18 +42,18 @@ module EY
|
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def warning(msg)
|
|
45
|
-
info "
|
|
45
|
+
info "WARNING: #{msg}\n".gsub(/^/,'!> ')
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
def info(msg)
|
|
49
49
|
with_logfile do |log|
|
|
50
|
-
Tee.new($stdout, log) << (msg
|
|
50
|
+
Tee.new($stdout, log) << ("#{with_timestamp(msg)}\n")
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
def debug(msg)
|
|
55
55
|
with_logfile do |log|
|
|
56
|
-
log << "#{msg}\n"
|
|
56
|
+
log << "#{with_timestamp(msg)}\n"
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
59
|
|
|
@@ -62,7 +62,7 @@ module EY
|
|
|
62
62
|
out = verbose? ? Tee.new($stdout, log) : log
|
|
63
63
|
err = Tee.new($stderr, log) # we always want to see errors
|
|
64
64
|
|
|
65
|
-
out << ":: running #{cmd}\n"
|
|
65
|
+
out << with_timestamp(":: running #{cmd}\n")
|
|
66
66
|
|
|
67
67
|
# :quiet means don't raise an error on nonzero exit status
|
|
68
68
|
status = Open4.spawn cmd, 0 => '', 1 => out, 2 => err, :quiet => true
|
|
@@ -79,6 +79,12 @@ module EY
|
|
|
79
79
|
EY::Serverside::LoggedOutput.logfile
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
+
def with_timestamp(msg)
|
|
83
|
+
return msg unless respond_to?(:starting_time)
|
|
84
|
+
time_passed = Time.now.to_i - starting_time.to_i
|
|
85
|
+
timestamp = "+%2dm %02ds " % time_passed.divmod(60)
|
|
86
|
+
msg.gsub(/^/, timestamp)
|
|
87
|
+
end
|
|
82
88
|
end
|
|
83
89
|
end
|
|
84
90
|
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'tempfile'
|
|
3
|
+
require 'timecop'
|
|
4
|
+
|
|
5
|
+
class SampleLogUser
|
|
6
|
+
include EY::Serverside::LoggedOutput
|
|
7
|
+
def initialize
|
|
8
|
+
EY::Serverside::LoggedOutput.logfile = tempfile.path
|
|
9
|
+
EY::Serverside::LoggedOutput.verbose = true
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def starting_time
|
|
13
|
+
@starting_time ||= Time.now
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def tempfile
|
|
17
|
+
@tempfile ||= Tempfile.new('logged_output')
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe EY::Serverside::LoggedOutput do
|
|
22
|
+
before do
|
|
23
|
+
EY::Serverside::LoggedOutput.enable_actual_info!
|
|
24
|
+
@log_user = SampleLogUser.new
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
after do
|
|
28
|
+
EY::Serverside::LoggedOutput.disable_actual_info!
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "has a timestamp before each line" do
|
|
32
|
+
time1 = Time.local(2008, 9, 1, 12, 0, 0)
|
|
33
|
+
time2 = Time.local(2008, 9, 1, 12, 3, 5)
|
|
34
|
+
time3 = Time.local(2008, 9, 1, 12, 10, 25)
|
|
35
|
+
|
|
36
|
+
Timecop.freeze(time1) do
|
|
37
|
+
@log_user.debug('test1')
|
|
38
|
+
@log_user.warning('test2')
|
|
39
|
+
end
|
|
40
|
+
Timecop.freeze(time2) do
|
|
41
|
+
@log_user.info('test3')
|
|
42
|
+
|
|
43
|
+
@log_user.debug("test11\ntest12\ntest13")
|
|
44
|
+
@log_user.warning("test21\ntest22\ntest23")
|
|
45
|
+
end
|
|
46
|
+
Timecop.freeze(time3) do
|
|
47
|
+
@log_user.info("test31\ntest32\ntest33")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
timestamp_1 = "+ 0m 00s "
|
|
51
|
+
timestamp_2 = "+ 3m 05s "
|
|
52
|
+
timestamp_3 = "+10m 25s "
|
|
53
|
+
File.read(@log_user.tempfile.path).should == "#{timestamp_1}test1\n#{timestamp_1}!> WARNING: test2\n\n#{timestamp_2}test3\n#{timestamp_2}test11\n#{timestamp_2}test12\n#{timestamp_2}test13\n#{timestamp_2}!> WARNING: test21\n#{timestamp_2}!> test22\n#{timestamp_2}!> test23\n\n#{timestamp_3}test31\n#{timestamp_3}test32\n#{timestamp_3}test33\n"
|
|
54
|
+
end
|
|
55
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -18,7 +18,24 @@ module EY
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
module LoggedOutput
|
|
21
|
-
def
|
|
21
|
+
def self.enable_actual_info!
|
|
22
|
+
@use_actual_info = true
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.disable_actual_info!
|
|
26
|
+
@use_actual_info = false
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.use_actual_info?
|
|
30
|
+
@use_actual_info
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
alias old_info info
|
|
34
|
+
def info(*args)
|
|
35
|
+
if EY::Serverside::LoggedOutput.use_actual_info?
|
|
36
|
+
old_info(*args)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
22
39
|
|
|
23
40
|
def logged_system(cmd)
|
|
24
41
|
output = `#{cmd} 2>&1`
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: engineyard-serverside
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 55
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 1
|
|
8
8
|
- 5
|
|
9
|
-
-
|
|
10
|
-
version: 1.5.
|
|
9
|
+
- 26
|
|
10
|
+
version: 1.5.26
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- EY Cloud Team
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2012-01-
|
|
18
|
+
date: 2012-01-21 00:00:00 Z
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
21
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
|
@@ -64,6 +64,20 @@ dependencies:
|
|
|
64
64
|
type: :development
|
|
65
65
|
prerelease: false
|
|
66
66
|
name: rdoc
|
|
67
|
+
- !ruby/object:Gem::Dependency
|
|
68
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
|
69
|
+
none: false
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
hash: 3
|
|
74
|
+
segments:
|
|
75
|
+
- 0
|
|
76
|
+
version: "0"
|
|
77
|
+
requirement: *id004
|
|
78
|
+
type: :development
|
|
79
|
+
prerelease: false
|
|
80
|
+
name: timecop
|
|
67
81
|
description:
|
|
68
82
|
email: cloud@engineyard.com
|
|
69
83
|
executables:
|
|
@@ -284,7 +298,6 @@ files:
|
|
|
284
298
|
- spec/custom_deploy_spec.rb
|
|
285
299
|
- spec/deploy_hook_spec.rb
|
|
286
300
|
- spec/deprecation_spec.rb
|
|
287
|
-
- spec/fixtures/gitrepo/bar
|
|
288
301
|
- spec/fixtures/gitrepo/foo
|
|
289
302
|
- spec/fixtures/gitrepo.tar.gz
|
|
290
303
|
- spec/fixtures/invalid_hook.rb
|
|
@@ -304,6 +317,7 @@ files:
|
|
|
304
317
|
- spec/fixtures/valid_hook.rb
|
|
305
318
|
- spec/git_strategy_spec.rb
|
|
306
319
|
- spec/lockfile_parser_spec.rb
|
|
320
|
+
- spec/logged_output_spec.rb
|
|
307
321
|
- spec/nodejs_deploy_spec.rb
|
|
308
322
|
- spec/rails31_deploy_spec.rb
|
|
309
323
|
- spec/restart_spec.rb
|
|
@@ -352,7 +366,6 @@ test_files:
|
|
|
352
366
|
- spec/custom_deploy_spec.rb
|
|
353
367
|
- spec/deploy_hook_spec.rb
|
|
354
368
|
- spec/deprecation_spec.rb
|
|
355
|
-
- spec/fixtures/gitrepo/bar
|
|
356
369
|
- spec/fixtures/gitrepo/foo
|
|
357
370
|
- spec/fixtures/gitrepo.tar.gz
|
|
358
371
|
- spec/fixtures/invalid_hook.rb
|
|
@@ -372,6 +385,7 @@ test_files:
|
|
|
372
385
|
- spec/fixtures/valid_hook.rb
|
|
373
386
|
- spec/git_strategy_spec.rb
|
|
374
387
|
- spec/lockfile_parser_spec.rb
|
|
388
|
+
- spec/logged_output_spec.rb
|
|
375
389
|
- spec/nodejs_deploy_spec.rb
|
|
376
390
|
- spec/rails31_deploy_spec.rb
|
|
377
391
|
- spec/restart_spec.rb
|
data/spec/fixtures/gitrepo/bar
DELETED
|
File without changes
|