Skip to content

Commit

Permalink
Per #2609, add logic to the logger class to suppress warning messages…
Browse files Browse the repository at this point in the history
…, and use it in the vx_series_data library to control to limit the missing data warning messages from tc-diag.
  • Loading branch information
JohnHalleyGotway committed Jul 25, 2023
1 parent 8beaa41 commit 95724db
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
28 changes: 26 additions & 2 deletions src/basic/vx_log/logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ static const int ErrorMessageLevel = -1;

static const int WarningMessageLevel = 0;

static const bool DefaultPrintWarning = true;

static const bool DefaultExitOnWarning = false;


//
// these need external linkage, do not make static or extern
//
Expand Down Expand Up @@ -217,6 +220,8 @@ LoggerWarning::LoggerWarning()
{
warn = WarningMessageLevel;

PrintWarning = DefaultPrintWarning;

ExitOnWarning = DefaultExitOnWarning;

NeedToExit = false;
Expand Down Expand Up @@ -246,6 +251,8 @@ LoggerWarning::LoggerWarning(const LoggerWarning & lw)
{
warn = lw.warn;

PrintWarning = lw.PrintWarning;

ExitOnWarning = lw.ExitOnWarning;

NeedToExit = lw.NeedToExit;
Expand All @@ -259,6 +266,8 @@ LoggerWarning & LoggerWarning::operator=(const LoggerWarning & lw)
{
warn = lw.warn;

PrintWarning = lw.PrintWarning;

ExitOnWarning = lw.ExitOnWarning;

NeedToExit = lw.NeedToExit;
Expand Down Expand Up @@ -509,6 +518,19 @@ void Logger::set_verbosity_level(const int i)
//////////////////////////////////////////////////////////////////


void Logger::set_print_warning(bool b)
{
//
// if false, do not print warning messages
//
Warning.PrintWarning = b;

}


//////////////////////////////////////////////////////////////////


void Logger::set_exit_on_warning(bool b)
{
//
Expand All @@ -519,7 +541,6 @@ void Logger::set_exit_on_warning(bool b)
}



//////////////////////////////////////////////////////////////////


Expand Down Expand Up @@ -1604,7 +1625,10 @@ Logger & Logger::operator<<(const LoggerError e)

Logger & Logger::operator<<(const LoggerWarning w)
{
(*this) << level(WarningMessageLevel);
if (Warning.PrintWarning)
{
(*this) << level(WarningMessageLevel);
}

if (Warning.ExitOnWarning) Warning.NeedToExit = true;

Expand Down
3 changes: 3 additions & 0 deletions src/basic/vx_log/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class LoggerWarning {

public:
int warn;
bool PrintWarning;
bool ExitOnWarning;
bool NeedToExit;

Expand Down Expand Up @@ -256,6 +257,8 @@ class Logger

void set_verbosity_level(const int);

void set_print_warning(bool);

void set_exit_on_warning(bool);

//
Expand Down
23 changes: 15 additions & 8 deletions src/libcode/vx_series_data/series_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

////////////////////////////////////////////////////////////////////////

static bool read_single_entry(VarInfo*, const ConcatString&, const GrdFileType,
DataPlane&, Grid&);

////////////////////////////////////////////////////////////////////////

bool get_series_entry(int i_series, VarInfo* data_info,
const StringArray& search_files, const GrdFileType type,
DataPlane& dp, Grid& grid,
Expand All @@ -28,6 +33,9 @@ bool get_series_entry(int i_series, VarInfo* data_info,
int i;
bool found;

// Suppress warnings, if requested
if(!print_warning) mlog.set_print_warning(false);

mlog << Debug(3)
<< "Processing series entry " << i_series + 1 << ": "
<< data_info->magic_time_str() << "\n";
Expand All @@ -41,7 +49,7 @@ bool get_series_entry(int i_series, VarInfo* data_info,
int i_cur = (i_series + i) % search_files.n();

found = read_single_entry(data_info, search_files[i_cur],
type, dp, grid, print_warning);
type, dp, grid);

// Break out of the loop if data was found or not searching all files
if(found || !search_all_files) break;
Expand All @@ -56,32 +64,31 @@ bool get_series_entry(int i_series, VarInfo* data_info,
exit(1);
}

// Restore warnings, if requested
if(!print_warning) mlog.set_print_warning(true);

return(found);
}

////////////////////////////////////////////////////////////////////////

bool read_single_entry(VarInfo* info, const ConcatString& filename,
const GrdFileType type, DataPlane& dp, Grid& grid,
bool print_warning) {
const GrdFileType type, DataPlane& dp, Grid& grid) {

Met2dDataFileFactory mtddf_factory;
Met2dDataFile* mtddf = (Met2dDataFile*) 0;

// Check that file exists
if(!file_exists(filename.c_str())) {
if(print_warning) {
mlog << Warning << "\nread_single_entry() -> "
<< "File does not exist: " << filename << "\n\n";
}
mlog << Warning << "\nread_single_entry() -> "
<< "File does not exist: " << filename << "\n\n";
return(false);
}

// Open data file
mtddf = mtddf_factory.new_met_2d_data_file(filename.c_str(), type);

// Attempt to read gridded data
// TODO: Should we pass print_warning as an option to data_plane?
bool found = mtddf->data_plane(*info, dp);

// Store grid
Expand Down
4 changes: 0 additions & 4 deletions src/libcode/vx_series_data/series_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ bool get_series_entry(int, VarInfo*, const StringArray&,
bool print_warning=true,
bool search_all_files=true);

bool read_single_entry(VarInfo*, const ConcatString&, const GrdFileType,
DataPlane&, Grid&,
bool print_warning=true);

////////////////////////////////////////////////////////////////////////

#endif // __SERIES_DATA_H__
Expand Down

0 comments on commit 95724db

Please sign in to comment.