Class: Morpheus::Cli::LogLevelCommand

Inherits:
Object
  • Object
show all
Includes:
CliCommand
Defined in:
lib/morpheus/cli/commands/standard/log_level_command.rb

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from CliCommand

#build_common_options, #build_option_type_options, #command_name, #default_refresh_interval, #default_subcommand, #establish_remote_appliance_connection, #full_command_usage, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_id_list, #parse_list_options, #parse_list_subtitles, #print, #print_error, #puts, #puts_error, #raise_command_error, #render_with_format, #run_command_for_each_arg, #subcommand_aliases, #subcommand_usage, #subcommands, #usage, #verify_access_token!

Instance Method Details

#handle(args) ⇒ Object



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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/morpheus/cli/commands/standard/log_level_command.rb', line 11

def handle(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do|opts|
    opts.banner = "Usage: morpheus #{command_name} [debug|info|0|1]"
    #build_common_options(opts, options, [])
    opts.on('-q','--quiet', "No Output, do not print to stdout") do
      options[:quiet] = true
    end
    opts.on('-h', '--help', "Print this help" ) do
      puts opts
      exit
    end
    opts.footer = "This is intended for use in your morpheus scripts.\nIt allows you to set the global logging level.\nThe only available levels right now are debug [0] and info [1].\nThe default is info [1].\n"
  end
  optparse.parse!(args)
  if args.count == 0
    puts "#{Morpheus::Logging.log_level}"
    return true
  end
  if args.count > 1
    puts optparse
    return false
  end
  debug_was_enabled = Morpheus::Logging.debug?
  if ["debug", "0"].include?(args[0].to_s.strip.downcase)
    Morpheus::Logging.set_log_level(Morpheus::Logging::Logger::DEBUG)
    ::RestClient.log = Morpheus::Logging.debug? ? Morpheus::Logging::DarkPrinter.instance : nil
    Morpheus::Logging::DarkPrinter.puts "debug enabled" unless debug_was_enabled
  elsif ["info", "1"].include?(args[0].to_s.strip.downcase)
    Morpheus::Logging.set_log_level(Morpheus::Logging::Logger::INFO)
    ::RestClient.log = Morpheus::Logging.debug? ? Morpheus::Logging::DarkPrinter.instance : nil
  elsif args[0].to_i < 6
    Morpheus::Logging.set_log_level(args[0].to_i)
    ::RestClient.log = Morpheus::Logging.debug? ? Morpheus::Logging::DarkPrinter.instance : nil
  else
    puts optparse
    return false
  end
  return true
end