Add backtrace information to log and stdout. Update console help behavior(correctly show help info, add information about -c option to example)

This commit is contained in:
Vladmir Sharhsov(warpc) 2013-07-30 21:29:26 +04:00
parent b49940796a
commit 07b68e4ef5
2 changed files with 8 additions and 5 deletions

View File

@ -31,7 +31,7 @@ end
opts = {}
optparse = OptionParser.new do |o|
o.banner = "Usage: bin/astute -f FILENAME"
o.banner = "Usage: bin/astute -c COMMAND -f FILENAME "
o.on("-v", "--[no-]verbose", "Run verbosely") do |v|
opts[:verbose] = v
@ -51,7 +51,7 @@ optparse = OptionParser.new do |o|
end
optparse.parse!(ARGV)
if opts[:filename].nil?
if opts[:filename].nil? || opts[:command].nil?
puts optparse
ERROR_CODE_COMMAND_USAGE = 64
exit ERROR_CODE_COMMAND_USAGE
@ -103,7 +103,9 @@ begin
res
end
rescue => e
puts "Error: #{e.inspect}"
result = Astute::FAIL
puts "Error: #{e.inspect}"
puts "Hint: use astute with --verbose or check log (#{Astute::LOG_PATH}) for more details" unless opts[:verbose]
Astute.logger.error e.backtrace.join("\n")
end
exit result
exit result

View File

@ -42,10 +42,11 @@ module Astute
SUCCESS = 0
FAIL = 1
LOG_PATH = '/var/log/astute.log'
def self.logger
unless @logger
@logger = Logger.new('/var/log/astute.log')
@logger = Logger.new(LOG_PATH)
@logger.formatter = proc do |severity, datetime, progname, msg|
severity_map = {'DEBUG' => 'debug', 'INFO' => 'info', 'WARN' => 'warning', 'ERROR' => 'err', 'FATAL' => 'crit'}
"#{datetime.strftime("%Y-%m-%dT%H:%M:%S")} #{severity_map[severity]}: [#{Process.pid}] #{msg}\n"