Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/redis_failover/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ def self.parse(source)
options[:chroot] = chroot
end

opts.on('-l', '--log-level LEVEL', 'Log level (default: INFO)') do |log_level|
options[:log_level] = case log_level.to_s.downcase

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given what you're doing down below in: util.rb, I would suggest consolidating your entire log-level switch into one line.

options[:log_level] = Logger.const_get(log_level.upcase) rescue nil

when 'debug'
Logger::DEBUG
when 'info'
Logger::INFO
when 'warn'
Logger::WARN
when 'fatal'
Logger::FATAL
end
end

opts.on('-L', '--log-file /path/to/file', 'Log file (default: STDOUT)') do |log_file|
options[:log_file] = log_file
end

opts.on('-E', '--environment ENV', 'Config environment to use') do |config_env|
options[:config_environment] = config_env
end
Expand Down
1 change: 1 addition & 0 deletions lib/redis_failover/node_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class NodeManager
# @option options [Array<String>] :nodes the nodes to manage
# @option options [String] :max_failures the max failures for a node
def initialize(options)
logger(options[:log_location]) if options[:log_location]
logger.info("Redis Node Manager v#{VERSION} starting (#{RUBY_DESCRIPTION})")
@options = options
@required_node_managers = options.fetch(:required_node_managers, 1)
Expand Down
17 changes: 10 additions & 7 deletions lib/redis_failover/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,18 @@ def different?(ary_a, ary_b)
end

# @return [Logger] the logger instance to use
def self.logger
@logger ||= begin
logger = Logger.new(STDOUT)
logger.level = Logger::INFO
logger.formatter = proc do |severity, datetime, progname, msg|
"#{datetime.utc} RedisFailover #{Process.pid} #{severity}: #{msg}\n"
def self.logger(location=nil, level=nil)
if(@logger.nil? || !location.nil? || !level.nil?)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the way you are handling the defaults, I don't believe you want this if condition. I would delete lines 98, 107-108 (and fix the indentation).

@logger ||= begin
logger = Logger.new(location || STDOUT)
logger.level = level || Logger::INFO
logger.formatter = proc do |severity, datetime, progname, msg|
"#{datetime.utc} RedisFailover #{Process.pid} #{severity}: #{msg}\n"
end
logger
end
logger
end
@logger
end

# Sets a new logger to use.
Expand Down