Class: Smith::Commands::Logger

Inherits:
Smith::CommandBase show all
Defined in:
lib/smith/commands/agency/logger.rb

Instance Attribute Summary

Attributes inherited from Smith::CommandBase

#options, #target

Instance Method Summary collapse

Methods inherited from Smith::CommandBase

#banner, #format_help, #initialize, #parse_options

Methods included from Logger

included

Constructor Details

This class inherits a constructor from Smith::CommandBase

Instance Method Details

#_logger(&blk) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/smith/commands/agency/logger.rb', line 9

def _logger(&blk)
  error_messages = []
  if options[:level].nil?
    error_messages << "No log level. You must specify a log level and a target"
  else
    case target.first
    when 'all'
      agents.state(:running).each do |agent|
        error_messages << set_log_level(agent.uuid)
      end
      ''
    when 'agency'
      begin
        logger.info { "Setting agency log level to: #{options[:level]}" }
        log_level(options[:level])
      rescue ArgumentError
        m = "Incorrect log level: #{options[:level]}"
        logger.error { m }
        error_messages << m
      end
      ''
    when nil
      error_messages << "No target. You must specify one of the following: 'agency', 'all' or a list of agents"
    else
      target.each do |uuid|
        error_messages << set_log_level(uuid)
      end
    end
  end
  error_messages.compact.join(", ")
end

#executeObject



5
6
7
# File 'lib/smith/commands/agency/logger.rb', line 5

def execute
  responder.succeed((_logger))
end