Skip to content

Commit

Permalink
Add a CLI option to override the path to logfile
Browse files Browse the repository at this point in the history
  • Loading branch information
jefmathiot committed Jan 1, 2015
1 parent f96c8fe commit 4e9d0c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/electric_sheep/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions spec/electric_sheep/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4e9d0c5

Please sign in to comment.