From 4e9d0c5d09fa933002e95d2da484886279a020fd Mon Sep 17 00:00:00 2001 From: Jef Mathiot Date: Thu, 1 Jan 2015 17:21:45 +0100 Subject: [PATCH] Add a CLI option to override the path to logfile --- lib/electric_sheep/cli.rb | 6 ++++-- spec/electric_sheep/cli_spec.rb | 11 +++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/electric_sheep/cli.rb b/lib/electric_sheep/cli.rb index 79721de..8485807 100644 --- a/lib/electric_sheep/cli.rb +++ b/lib/electric_sheep/cli.rb @@ -10,6 +10,8 @@ def self.startup_options process_options option :workers, aliases: %w(-w), type: :numeric, desc: 'Maximum number of parallel workers', default: 1 + option :logfile, aliases: %w(-l), type: :string, + desc: 'Override path to log file', default: './electric_sheep.log' end def self.run_options @@ -93,8 +95,8 @@ def stdout_logger end def file_logger - # TODO Configure logger output - Lumberjack::Logger.new("electric_sheep.log", level: log_level) + path=File.expand_path(options[:logfile] || 'electric_sheep.log') + Lumberjack::Logger.new(path, level: log_level) end def logger diff --git a/spec/electric_sheep/cli_spec.rb b/spec/electric_sheep/cli_spec.rb index d952ac6..edb094c 100644 --- a/spec/electric_sheep/cli_spec.rb +++ b/spec/electric_sheep/cli_spec.rb @@ -11,8 +11,9 @@ def expects_stdout_logger(level) returns(logger) end - def expects_file_logger(level) - Lumberjack::Logger.expects(:new).with("electric_sheep.log", {level: level}). + def expects_file_logger(level, path=nil) + Lumberjack::Logger.expects(:new). + with(path || File.expand_path("electric_sheep.log"), {level: level}). returns(logger) end @@ -61,6 +62,12 @@ def self.ensure_exception_handling(&block) end end + it 'overrides the path to logfile' do + Lumberjack::Logger.expects(:new). + with('/var/log/electric_sheep.log', level: :info) + subject.new([], logfile: '/var/log/electric_sheep.log').send(:file_logger) + end + describe 'working' do describe 'on successful invocation' do