Skip to content
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

Fix #4918 - Add a -l / --loglevel argument to the labs CLI #4919

Merged
merged 3 commits into from
Jun 29, 2023

Conversation

jmarrec
Copy link
Collaborator

@jmarrec jmarrec commented Jun 19, 2023

Pull request overview

Pull Request Author

  • Model API Changes / Additions
  • Any new or modified fields have been implemented in the EnergyPlus ForwardTranslator (and ReverseTranslator as appropriate)
  • Model API methods are tested (in src/model/test)
  • EnergyPlus ForwardTranslator Tests (in src/energyplus/Test)
  • If a new object or method, added a test in NREL/OpenStudio-resources: Add Link
  • If needed, added VersionTranslation rules for the objects (src/osversion/VersionTranslator.cpp)
  • Verified that C# bindings built fine on Windows, partial classes used as needed, etc.
  • All new and existing tests passes
  • If methods have been deprecated, update rest of code to use the new methods

Labels:

  • If change to an IDD file, add the label IDDChange
  • If breaking existing API, add the label APIChange
  • If deemed ready, add label Pull Request - Ready for CI so that CI builds your PR

Review Checklist

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • Code Style, strip trailing whitespace, etc.
  • All related changes have been implemented: model changes, model tests, FT changes, FT tests, VersionTranslation, OS App
  • Labeling is ok
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified

@jmarrec jmarrec added component - CLI Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge. labels Jun 19, 2023
@jmarrec jmarrec self-assigned this Jun 19, 2023
Comment on lines +98 to +114
auto* const verboseOpt = experimentalApp->add_flag_function(
"--verbose",
[](auto count) {
if (count == 1) {
fmt::print("Setting log Level to Debug\n");
fmt::print("Setting Log Level to Debug ({})\n", LogLevel::Debug);
openstudio::Logger::instance().standardOutLogger().setLogLevel(LogLevel::Debug);
} else if (count == 2) {
fmt::print("Setting log Level to Trace\n");
fmt::print("Setting Log Level to Trace ({})\n", LogLevel::Trace);
openstudio::Logger::instance().standardOutLogger().setLogLevel(LogLevel::Trace);
}
},
"Print the full log to STDOUT");
"Print the full log to STDOUT - sets verbosity to Debug if given once and Trace if given twice.");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just remove the --verbose option... instead of having to maintain two excluding options/flags that ultimately achieve the same goal.

@kbenne thoughts please?

src/cli/main.cpp Outdated
Comment on lines 111 to 133
// specify string->value mappings
const std::map<std::string, LogLevel> logLevelMap{
{"Trace", LogLevel::Trace}, {"Debug", LogLevel::Debug}, {"Info", LogLevel::Info},
{"Warn", LogLevel::Warn}, {"Error", LogLevel::Error}, {"Fatal", LogLevel::Fatal},
};
static constexpr std::array<std::string_view, 6> logLevelStrs = {"Trace", "Debug", "Info", "Warn", "Error", "Fatal"};

experimentalApp
->add_option_function<LogLevel>(
"-l,--loglevel",
[](const LogLevel& level) {
fmt::print("Setting log Level to {} ({})\n", logLevelStrs[static_cast<size_t>(level) - static_cast<size_t>(LogLevel::Trace)], level);
openstudio::Logger::instance().standardOutLogger().setLogLevel(level);
},
"LogLevel settings: One of {Trace, Debug, Info, Warn, Error, Fatal} [Default: Warn] Excludes: --verbose")
->excludes(verboseOpt)
->option_text("LEVEL")
->transform(CLI::CheckedTransformer(logLevelMap, CLI::ignore_case));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New option

  --verbose Excludes: --loglevel   Print the full log to STDOUT - sets verbosity to Debug if given once and Trace if given twice.
  -l,--loglevel LEVEL              LogLevel settings: One of {Trace, Debug, Info, Warn, Error, Fatal} [Default: Warn] Excludes: --verbose

@jmarrec jmarrec merged commit 900cf9a into develop Jun 29, 2023
@jmarrec jmarrec deleted the 4918_cli_verbosity_option branch June 29, 2023 14:35
@jmarrec
Copy link
Collaborator Author

jmarrec commented Jun 29, 2023

@kbenne I'd still like to know if we can remove the --verbose option, that can be done after. Merging for now.

kbenne added a commit that referenced this pull request Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component - CLI Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a --verbosity / --log-level to the Labs cli
2 participants