Skip to content

Commit

Permalink
[toggle-log-level] toggle log level w/ kill -USR2 PID
Browse files Browse the repository at this point in the history
  • Loading branch information
portertech committed Nov 30, 2011
1 parent de30bc0 commit 347513a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/sensu/api.rb
Expand Up @@ -29,6 +29,10 @@ def self.setup(options={})
$logger.debug('[setup] -- connecting to rabbitmq')
connection = AMQP.connect(@settings.rabbitmq.to_hash.symbolize_keys)
$amq = MQ.new(connection)

Signal.trap('USR1') do
config.toggle_log_level
end
end

def self.stop(signal)
Expand Down
4 changes: 4 additions & 0 deletions lib/sensu/client.rb
Expand Up @@ -23,6 +23,10 @@ def initialize(options={})
config = Sensu::Config.new(options)
@settings = config.settings
@logger = config.logger

Signal.trap('USR1') do
config.toggle_log_level
end
end

def stop(signal)
Expand Down
6 changes: 5 additions & 1 deletion lib/sensu/config.rb
Expand Up @@ -26,7 +26,7 @@ def initialize(options={})
invalid_config('log file is not writable: ' + log_file)
end
@logger.subscribe(Cabin::Outputs::EmStdlibLogger.new(ruby_logger))
@logger.level = options[:verbose] ? 'debug' : 'info'
@logger.level = options[:verbose] ? :debug : :info
config_file = options[:config_file] || '/etc/sensu/config.json'
if File.readable?(config_file)
begin
Expand All @@ -40,6 +40,10 @@ def initialize(options={})
validate_config(options['type'])
end

def toggle_log_level
@logger.level = @logger.level == :info ? :debug : :info
end

def validate_config(type)
@logger.debug('[config] -- validating configuration')
has_keys(%w[rabbitmq])
Expand Down
4 changes: 4 additions & 0 deletions lib/sensu/server.rb
Expand Up @@ -33,6 +33,10 @@ def initialize(options={})
@settings = config.settings
@logger = config.logger
@is_worker = options[:worker]

Signal.trap('USR1') do
config.toggle_log_level
end
end

def stop(signal)
Expand Down

0 comments on commit 347513a

Please sign in to comment.