mirror of
https://github.com/puppetlabs/vmfloaty.git
synced 2026-01-26 05:28:40 -05:00
(DIO-908) Adding a way to set Logger level via --loglevel
this is specially useful if you also use in combination --json to remove superfluous stdout
This commit is contained in:
parent
a3d8484124
commit
4192631d70
2 changed files with 30 additions and 0 deletions
|
|
@ -40,8 +40,12 @@ class Vmfloaty
|
||||||
c.option '--json', 'Prints retrieved vms in JSON format'
|
c.option '--json', 'Prints retrieved vms in JSON format'
|
||||||
c.option '--ondemand', 'Requested vms are provisioned upon receival of the request, tracked by a request ID'
|
c.option '--ondemand', 'Requested vms are provisioned upon receival of the request, tracked by a request ID'
|
||||||
c.option '--continue STRING', String, 'resume polling ABS for job_id, for use when the cli was interrupted'
|
c.option '--continue STRING', String, 'resume polling ABS for job_id, for use when the cli was interrupted'
|
||||||
|
c.option '--loglevel STRING', String, 'the log level to use (debug, info, error)'
|
||||||
c.action do |args, options|
|
c.action do |args, options|
|
||||||
verbose = options.verbose || config['verbose']
|
verbose = options.verbose || config['verbose']
|
||||||
|
if options.loglevel
|
||||||
|
FloatyLogger.setlevel = options.loglevel
|
||||||
|
end
|
||||||
service = Service.new(options, config)
|
service = Service.new(options, config)
|
||||||
use_token = !options.notoken
|
use_token = !options.notoken
|
||||||
force = options.force
|
force = options.force
|
||||||
|
|
@ -93,8 +97,12 @@ class Vmfloaty
|
||||||
c.option '--token STRING', String, 'Token for pooler service'
|
c.option '--token STRING', String, 'Token for pooler service'
|
||||||
c.option '--url STRING', String, 'URL of pooler service'
|
c.option '--url STRING', String, 'URL of pooler service'
|
||||||
c.option '--user STRING', String, 'User to authenticate with'
|
c.option '--user STRING', String, 'User to authenticate with'
|
||||||
|
c.option '--loglevel STRING', String, 'the log level to use (debug, info, error)'
|
||||||
c.action do |args, options|
|
c.action do |args, options|
|
||||||
verbose = options.verbose || config['verbose']
|
verbose = options.verbose || config['verbose']
|
||||||
|
if options.loglevel
|
||||||
|
FloatyLogger.setlevel = options.loglevel
|
||||||
|
end
|
||||||
|
|
||||||
service = Service.new(options, config)
|
service = Service.new(options, config)
|
||||||
filter = args[0]
|
filter = args[0]
|
||||||
|
|
@ -230,8 +238,13 @@ class Vmfloaty
|
||||||
c.option '--token STRING', String, 'Token for pooler service'
|
c.option '--token STRING', String, 'Token for pooler service'
|
||||||
c.option '--url STRING', String, 'URL of pooler service'
|
c.option '--url STRING', String, 'URL of pooler service'
|
||||||
c.option '--user STRING', String, 'User to authenticate with'
|
c.option '--user STRING', String, 'User to authenticate with'
|
||||||
|
c.option '--loglevel STRING', String, 'the log level to use (debug, info, error)'
|
||||||
c.action do |args, options|
|
c.action do |args, options|
|
||||||
verbose = options.verbose || config['verbose']
|
verbose = options.verbose || config['verbose']
|
||||||
|
if options.loglevel
|
||||||
|
FloatyLogger.setlevel = options.loglevel
|
||||||
|
end
|
||||||
|
|
||||||
service = Service.new(options, config)
|
service = Service.new(options, config)
|
||||||
hostnames = args[0]
|
hostnames = args[0]
|
||||||
delete_all = options.all
|
delete_all = options.all
|
||||||
|
|
@ -375,8 +388,12 @@ class Vmfloaty
|
||||||
c.option '--service STRING', String, 'Configured pooler service name'
|
c.option '--service STRING', String, 'Configured pooler service name'
|
||||||
c.option '--url STRING', String, 'URL of pooler service'
|
c.option '--url STRING', String, 'URL of pooler service'
|
||||||
c.option '--json', 'Prints status in JSON format'
|
c.option '--json', 'Prints status in JSON format'
|
||||||
|
c.option '--loglevel STRING', String, 'the log level to use (debug, info, error)'
|
||||||
c.action do |_, options|
|
c.action do |_, options|
|
||||||
verbose = options.verbose || config['verbose']
|
verbose = options.verbose || config['verbose']
|
||||||
|
if options.loglevel
|
||||||
|
FloatyLogger.setlevel = options.loglevel
|
||||||
|
end
|
||||||
service = Service.new(options, config)
|
service = Service.new(options, config)
|
||||||
if options.json
|
if options.json
|
||||||
pp service.status(verbose)
|
pp service.status(verbose)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,19 @@ class FloatyLogger < ::Logger
|
||||||
FloatyLogger.logger.error msg
|
FloatyLogger.logger.error msg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.setlevel=(level)
|
||||||
|
level = level.downcase
|
||||||
|
if level == "debug"
|
||||||
|
self.logger.level = ::Logger::DEBUG
|
||||||
|
elsif level == "info"
|
||||||
|
self.logger.level = ::Logger::INFO
|
||||||
|
elsif level == "error"
|
||||||
|
self.logger.level = ::Logger::ERROR
|
||||||
|
else
|
||||||
|
error("set loglevel to debug, info or error")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
super(STDERR)
|
super(STDERR)
|
||||||
self.level = ::Logger::INFO
|
self.level = ::Logger::INFO
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue