-
Notifications
You must be signed in to change notification settings - Fork 897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add logging to standard output for report generator tool #18640
Add logging to standard output for report generator tool #18640
Conversation
@lpichler Cannot apply the following label because they are not recognized: report |
tools/generate_report.rb
Outdated
banner "USAGE: #{__FILE__} -u <name of userid which runs report, default: admin> \n" \ | ||
" #{__FILE__} -n <name of report or id of report, default: last created report> \n" \ | ||
" #{__FILE__} -l <log level, if this option is set log messages are forwarded to \n" \ | ||
" standard output, allowed levels are debug, info, warn, error> \n" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be necessary...optimist builds all of this for you.
tools/generate_report.rb
Outdated
|
||
include ActionDispatch::Routing::UrlFor | ||
include Rails.application.routes.url_helpers | ||
|
||
USER_ID = "admin".freeze | ||
REPORT_PARAMS = {:userid => USER_ID, :mode => "async", :report_source => "Requested by user"}.freeze | ||
options = Optimist.options(ARGV) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ARGV is the default, so no need to pass it.
tools/generate_report.rb
Outdated
if ARGV.empty? | ||
opt :user, "userid", :short => "u", :type => String, :default => "admin" | ||
opt :report_name_or_id, "report name or report id", :short => "n", :type => :string | ||
opt :log_level, "log level (debug, info, warn, error)", :short => "l", :type => :string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the short options are automatic, so no need to define them
EDIT: (You do need the short option for report_name_or_id)
tools/generate_report.rb
Outdated
|
||
def report_from_args | ||
if ARGV.empty? | ||
opt :user, "userid", :short => "u", :type => String, :default => "admin" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type is not necessary because you provided a default. If you want to leave it for consistency with other options, use the symbol style like you did in the other ones.
tools/generate_report.rb
Outdated
end | ||
|
||
if options[:log_level] | ||
Optimist.die "Log level #{options[:log_level]} is not supported, supported levels are: debug, info, warn, error" unless Vmdb::LogProxy::LEVELS.include?(options[:log_level].to_sym) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer building the message from the same list you are checking from, if possible.. that is, instead of hardcoding debug, info, etc. do Vmdb::LogProxy::LEVELS.join(", ")
tools/generate_report.rb
Outdated
|
||
if options[:log_level] | ||
Optimist.die "Log level #{options[:log_level]} is not supported, supported levels are: debug, info, warn, error" unless Vmdb::LogProxy::LEVELS.include?(options[:log_level].to_sym) | ||
$log = Logger.new(STDOUT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a VmdbLogger or similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, VMDBLogger (we have it in other scripts in /tools
)
96d3ce0
to
5557675
Compare
I updated PR according to the suggestions. thanks for the review @Fryguy 👍 |
5557675
to
6a5794d
Compare
@miq-bot add_label changelog/yes |
Checked commits lpichler/manageiq@cd34aa0~...6a5794d with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
I added parsing with https://github.com/ManageIQ/optimist in first commit.
example of output with logging:
cc @gtanzillo
@miq-bot assign @jrafanie
@miq-bot add_label report, tools