lib/awestruct/cli/invoker.rb in awestruct-0.4.8 vs lib/awestruct/cli/invoker.rb in awestruct-0.5.0.cr
- old
+ new
@@ -3,12 +3,14 @@
require 'awestruct/cli/init'
require 'awestruct/cli/generate'
require 'awestruct/cli/auto'
require 'awestruct/cli/server'
require 'awestruct/cli/deploy'
+require 'awestruct/logger'
require 'pathname'
+require 'logger'
module Awestruct
module CLI
class Invoker
@@ -26,10 +28,15 @@
@options = Awestruct::CLI::Options.parse! options
end
@threads = []
@profile = nil
@success = true
+ logging_path = Pathname.new '.awestruct'
+ logging_path.mkdir unless logging_path.exist?
+ $LOG = Logger.new(Awestruct::AwestructLoggerMultiIO.new(@options.verbose, STDOUT, File.open('.awestruct/debug.log', 'w')))
+ $LOG.level = @options.verbose ? Logger::DEBUG : Logger::INFO
+ $LOG.formatter = Awestruct::AwestructLogFormatter.new
end
def invoke!
load_profile() unless ( options.init )
@@ -66,15 +73,15 @@
end
end
end
unless @profile
- $stderr.puts "Unable to locate profile: #{options.profile}" if options.profile
+ $LOG.error "Unable to locate profile: #{options.profile}" if options.profile && $LOG.error?
options.profile = 'NONE'
@profile = {}
end
- $stderr.puts "Using profile: #{options.profile}"
+ $LOG.info "Using profile: #{options.profile}" if $LOG.info?
end
def setup_config()
@config = Awestruct::Config.new( Dir.pwd )
@config.track_dependencies = true if ( options.auto )
@@ -99,10 +106,10 @@
def invoke_deploy()
deploy_config = profile[ 'deploy' ]
if ( deploy_config.nil? )
- $stderr.puts "No configuration for 'deploy'"
+ $LOG.error "No configuration for 'deploy'" if $LOG.error?
return
end
Awestruct::CLI::Deploy.new( config, deploy_config ).run
end