Module: EY::Serverside::LoggedOutput

Included in:
DeployBase, Server, Strategies::Git
Defined in:
lib/engineyard-serverside/logged_output.rb

Defined Under Namespace

Classes: Tee

Constant Summary collapse

@@logfile =

Tee

File.join(ENV['HOME'], 'ey.log')
@@verbose =
false

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.logfileObject



27
28
29
# File 'lib/engineyard-serverside/logged_output.rb', line 27

def self.logfile
  @@logfile
end

.logfile=(filename) ⇒ Object



22
23
24
25
# File 'lib/engineyard-serverside/logged_output.rb', line 22

def self.logfile=(filename)
  File.unlink filename if File.exist?(filename)  # start fresh
  @@logfile = filename
end

.verbose=(v) ⇒ Object



32
33
34
# File 'lib/engineyard-serverside/logged_output.rb', line 32

def self.verbose=(v)
  @@verbose = !!v
end

.verbose?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/engineyard-serverside/logged_output.rb', line 36

def self.verbose?
  @@verbose
end

Instance Method Details

#debug(msg) ⇒ Object



54
55
56
57
58
# File 'lib/engineyard-serverside/logged_output.rb', line 54

def debug(msg)
  with_logfile do |log|
    log << "#{with_timestamp(msg)}\n"
  end
end

#info(msg) ⇒ Object



48
49
50
51
52
# File 'lib/engineyard-serverside/logged_output.rb', line 48

def info(msg)
  with_logfile do |log|
    Tee.new($stdout, log) << ("#{with_timestamp(msg)}\n")
  end
end

#logged_system(cmd) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/engineyard-serverside/logged_output.rb', line 60

def logged_system(cmd)
  with_logfile do |log|
    out = verbose? ? Tee.new($stdout, log) : log
    err = Tee.new($stderr, log)    # we always want to see errors

    cmd = "sh -l -c #{Escape.shell_command([cmd])}"
    puts "running #{cmd}" if ENV['DEBUG']
    out <<  with_timestamp(":: running #{cmd}\n")
    status = systemu cmd, 'stdout' => out, 'stderr' => err
    puts "exit status= #{status.exitstatus}" if ENV['DEBUG']
    status.exitstatus == 0
  end
end

#verbose?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/engineyard-serverside/logged_output.rb', line 40

def verbose?
  EY::Serverside::LoggedOutput.verbose?
end

#warning(msg) ⇒ Object



44
45
46
# File 'lib/engineyard-serverside/logged_output.rb', line 44

def warning(msg)
  info "WARNING: #{msg}\n".gsub(/^/,'!> ')
end