Class: RightScale::LogLevelManager
- Defined in:
- lib/right_agent/scripts/log_level_manager.rb
Class Method Summary collapse
-
.run ⇒ Object
Convenience wrapper for creating and running log level manager.
Instance Method Summary collapse
-
#manage(options) ⇒ Object
Handle log level request.
-
#parse_args ⇒ Object
Create options hash from command line arguments.
Class Method Details
.run ⇒ Object
Convenience wrapper for creating and running log level manager
Return
- true
-
Always return true
48 49 50 51 |
# File 'lib/right_agent/scripts/log_level_manager.rb', line 48 def self.run m = LogLevelManager.new m.manage(m.parse_args) end |
Instance Method Details
#manage(options) ⇒ Object
Handle log level request
Parameters
- options(Hash)
-
Command line options
Return
- true
-
Always return true
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/right_agent/scripts/log_level_manager.rb', line 60 def manage() # Initialize configuration directory setting AgentConfig.cfg_dir = [:cfg_dir] # Determine command level = [:level] command = { :name => (level ? 'set_log_level' : 'get_log_level') } command[:level] = level.to_sym if level # Determine candidate agents agent_names = if [:agent_name] [[:agent_name]] else AgentConfig.cfg_agents end fail("No agents configured") if agent_names.empty? # Perform command for each agent count = 0 agent_names.each do |agent_name| count += 1 if request_log_level(agent_name, command, ) end puts("No agents running") if count == 0 true end |
#parse_args ⇒ Object
Create options hash from command line arguments
Return
- options(Hash)
-
Hash of options as defined by the command line
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/right_agent/scripts/log_level_manager.rb', line 90 def parse_args = { :verbose => false } [:agent_name] = ARGV[0] unless ARGV[0] =~ /^-/ opts = OptionParser.new do |opts| opts.on('-l', '--log-level LEVEL') do |l| fail("Invalid log level '#{l}'") unless AgentManager::LEVELS.include?(l.downcase.to_sym) [:level] = l.downcase end opts.on("-c", "--cfg-dir DIR") do |d| [:cfg_dir] = d end opts.on('-v', '--verbose') do [:verbose] = true end end opts.on_tail('--help') do puts Usage.scan(__FILE__) exit end begin opts.parse!(ARGV) rescue Exception => e exit 0 if e.is_a?(SystemExit) fail(e. + "\nUse 'rlog --help' for additional information") end end |