Improvements

Code improvements.
Exceptions improvements.
This commit is contained in:
Valentino Orlandi 2022-08-25 01:06:34 +02:00
parent 3f0cf4b728
commit cd56148d28
Signed by: elB4RTO
GPG Key ID: 1719E976DB2D4E71
2 changed files with 28 additions and 16 deletions

View File

@ -186,7 +186,7 @@ const std::unordered_map<int, std::string> LogOps::parseLine( const std::string&
}
if ( stop == std::string::npos ) {
// separator not found, abort
throw GenericException( "Separator not found: '"+sep+"'" );
throw LogParserException( "Separator not found: '"+sep+"'" );
}
// get the field
@ -267,7 +267,7 @@ const std::unordered_map<int, std::string> LogOps::parseLine( const std::string&
// process the date to get year, month, day, hour and minute
if ( StringOps::startsWith( fld, "date_time" ) ) {
std::vector<std::string> dt = DateTimeOps::processDateTime( fld_str, fld.substr( 10 ) ); // cut away the "date_time_" part which is useless from now on
const std::vector<std::string> dt = DateTimeOps::processDateTime( fld_str, fld.substr( 10 ) ); // cut away the "date_time_" part which is useless from now on
if ( dt.at( 0 ) != "" ) {
// year
data.emplace( this->field2id.at("date_time_year"), dt.at( 0 ) );
@ -382,7 +382,7 @@ const std::unordered_map<int, std::string> LogOps::parseLine( const std::string&
// something went wrong
} else {
// hmmm.. no...
throw LogParserException( "Unexpected LogField: "+ fld );
throw LogParserException( "Unexpected LogField: '"+fld+"'" );
}
}
}
@ -453,11 +453,11 @@ void LogOps::resetPerfData()
this->size = 0;
this->lines = 0;
}
const int LogOps::getSize()
const unsigned LogOps::getSize()
{
return this->size;
}
const int LogOps::getLines()
const unsigned LogOps::getLines()
{
return this->lines;
}

View File

@ -39,8 +39,8 @@ public:
void resetPerfData();
// share perf data with craplog
const int getSize(),
getLines();
const unsigned getSize(),
getLines();
private:
@ -53,12 +53,24 @@ private:
{"date_time_hour", 4},
{"date_time_minute", 5},
{"date_time_second", 6},
{"date_time_ncsa", 0},
{"date_time_iso", 0},
{"date_time_mcs", 0},
{"date_time_gmt", 0},
{"date_time_utc_d", 0},
{"date_time_utc_t", 0},
{"date_time_ncsa", 0},
{"date_time_iso", 0},
{"date_time_mcs", 0},
{"date_time_gmt", 0},
{"date_time_utc_d", 0},
{"date_time_utc_t", 0},
{"date_time_epoch_s", 0},
{"date_time_epoch_s.ms", 0},
{"date_time_epoch_ms", 0},
{"date_time_epoch_us", 0},
{"date_time_YYYYMMDD", 0},
{"date_time_MMDDYY", 0},
{"date_time_MDYY", 0},
{"date_time_year_short", 0},
{"date_time_month_str", 0},
{"date_time_clock_12", 0},
{"date_time_clock_24", 0},
{"date_time_clock_short", 0},
// request
{"request_protocol", 10},
{"request_method", 11},
@ -68,9 +80,9 @@ private:
{"request_full", 0},
// performance
{"time_taken_ms", 15},
{"time_taken_us", 0},
{"time_taken_s", 0},
{"time_taken_us", 0},
{"time_taken_s.ms", 0},
{"time_taken_s", 0},
{"bytes_sent", 16},
{"bytes_received", 17},
// referer
@ -91,7 +103,7 @@ private:
const FormatOps::LogsFormat& format
);
// temporary vars
int size=0, lines=0;
unsigned size=0, lines=0;
};