Skip to content

Commit

Permalink
[python-package] respect 'verbose' setting when using custom objectiv…
Browse files Browse the repository at this point in the history
…e function (fixes #6014)
  • Loading branch information
jameslamb committed Apr 25, 2024
1 parent 1443548 commit 032d0fa
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/io/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,25 @@ void GetFirstValueAsInt(const std::unordered_map<std::string, std::vector<std::s
}

void Config::SetVerbosity(const std::unordered_map<std::string, std::vector<std::string>>& params) {
int verbosity = Config().verbosity;
GetFirstValueAsInt(params, "verbose", &verbosity);
GetFirstValueAsInt(params, "verbosity", &verbosity);

int verbosity = 1;

// if "verbosity" was found in params, prefer that to any other aliases
const auto verbosity_iter = params.find("verbosity");
if (verbosity_iter != params.end()) {
GetFirstValueAsInt(params, "verbosity", &verbosity);
} else {
// if "verbose" was found in params and "verbosity" was not, use that value
const auto verbose_iter = params.find("verbose");
if (verbose_iter != params.end()) {
GetFirstValueAsInt(params, "verbose", &verbosity);
} else {
// if "verbosity" and "verbose" were both missing from params, don't modify LightGBM's log level
return;
}
}

// otherwise, update LightGBM's log level based on the passed-in value
if (verbosity < 0) {
LightGBM::Log::ResetLogLevel(LightGBM::LogLevel::Fatal);
} else if (verbosity == 0) {
Expand Down

0 comments on commit 032d0fa

Please sign in to comment.