Improvements and updates
This commit is contained in:
parent
1e21756f5c
commit
2dcf0fc59a
|
@ -55,11 +55,11 @@ Craplog::Craplog()
|
||||||
|
|
||||||
// initialize formats
|
// initialize formats
|
||||||
this->logs_formats.emplace(
|
this->logs_formats.emplace(
|
||||||
APACHE_ID, this->formatOps.processApacheFormatString( this->logs_format_strings.at(APACHE_ID) ) );
|
APACHE_ID, LogsFormat() );
|
||||||
this->logs_formats.emplace(
|
this->logs_formats.emplace(
|
||||||
NGINX_ID, this->formatOps.processNginxFormatString( this->logs_format_strings.at(NGINX_ID) ) );
|
NGINX_ID, LogsFormat() );
|
||||||
this->logs_formats.emplace(
|
this->logs_formats.emplace(
|
||||||
IIS_ID, this->formatOps.processIisFormatString( this->logs_format_strings.at(IIS_ID), 0 ) );
|
IIS_ID, LogsFormat() );
|
||||||
|
|
||||||
this->current_LF = this->logs_formats.at( APACHE_ID );
|
this->current_LF = this->logs_formats.at( APACHE_ID );
|
||||||
|
|
||||||
|
@ -457,7 +457,7 @@ size_t Craplog::getLogsListSize() const
|
||||||
return this->logs_list.size();
|
return this->logs_list.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the list. rescan if fresh is true
|
// return the current list
|
||||||
const std::vector<LogFile>& Craplog::getLogsList() const
|
const std::vector<LogFile>& Craplog::getLogsList() const
|
||||||
{
|
{
|
||||||
return this->logs_list;
|
return this->logs_list;
|
||||||
|
@ -604,7 +604,7 @@ bool Craplog::isFileNameValid( const std::string& name ) const
|
||||||
}
|
}
|
||||||
// serach for incremental numbers
|
// serach for incremental numbers
|
||||||
for ( size_t i{start}; i<=stop; i++ ) {
|
for ( size_t i{start}; i<=stop; i++ ) {
|
||||||
if ( ! StringOps::isNumeric( name.at( i ) ) ) {
|
if ( ! CharOps::isNumeric( name.at( i ) ) ) {
|
||||||
valid &= false;
|
valid &= false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -625,7 +625,7 @@ bool Craplog::isFileNameValid( const std::string& name ) const
|
||||||
// search for date
|
// search for date
|
||||||
std::string date;
|
std::string date;
|
||||||
for ( size_t i{start}; i<=stop; i++ ) {
|
for ( size_t i{start}; i<=stop; i++ ) {
|
||||||
if ( ! StringOps::isNumeric( name.at( i ) ) ) {
|
if ( ! CharOps::isNumeric( name.at( i ) ) ) {
|
||||||
valid &= false;
|
valid &= false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,9 +100,7 @@ public:
|
||||||
\param web_server The ID of the Web Server
|
\param web_server The ID of the Web Server
|
||||||
\param new_path The new path
|
\param new_path The new path
|
||||||
*/
|
*/
|
||||||
void setLogsPath( const unsigned& web_server,
|
void setLogsPath( const unsigned& web_server, const std::string& new_path );
|
||||||
const std::string& new_path
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////
|
///////////////////
|
||||||
|
|
|
@ -204,6 +204,17 @@ std::string parseNginxEscapes( std::string_view string )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Checks whether the given character is valid or not
|
||||||
|
/*!
|
||||||
|
\param chr The target character
|
||||||
|
\return The result of the check
|
||||||
|
\see findNginxFieldEnd
|
||||||
|
*/
|
||||||
|
bool checkNginxFieldChar( const char& chr )
|
||||||
|
{
|
||||||
|
return CharOps::isAlnum( chr ) || chr == '_';
|
||||||
|
}
|
||||||
|
|
||||||
//! Finds the end of a Nginx log field
|
//! Finds the end of a Nginx log field
|
||||||
/*!
|
/*!
|
||||||
\param string The format string
|
\param string The format string
|
||||||
|
@ -211,24 +222,28 @@ std::string parseNginxEscapes( std::string_view string )
|
||||||
\return The ending poin of the field in the string
|
\return The ending poin of the field in the string
|
||||||
\see processNginxFormatString()
|
\see processNginxFormatString()
|
||||||
*/
|
*/
|
||||||
size_t findNginxFieldEnd( std::string_view string, const size_t start )
|
size_t findNginxFieldEnd( const std::string& string, const size_t start )
|
||||||
{
|
{
|
||||||
size_t stop{ start };
|
if ( string.empty() || start >= string.size()-1ul ) {
|
||||||
const size_t max{ string.size()-1ul };
|
return start;
|
||||||
if ( start < max ) { // if start equals max there's no need to loop
|
|
||||||
for ( size_t i{start}; i<=max; i++ ) {
|
|
||||||
const char& c{ string.at( i ) };
|
|
||||||
if ( StringOps::isAlnum( c ) || c == '_' ) {
|
|
||||||
stop = i;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return stop;
|
return std::distance( std::cbegin(string), std::find_if_not( string.cbegin()+start, string.cend(), checkNginxFieldChar ) ) - 1ul;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Checks whether the given character is valid or not
|
||||||
|
/*!
|
||||||
|
\param chr The target character
|
||||||
|
\return The result of the check
|
||||||
|
\see checkIisString
|
||||||
|
*/
|
||||||
|
bool checkIisChar( const char& chr )
|
||||||
|
{
|
||||||
|
return CharOps::isAlnum( chr )
|
||||||
|
|| chr == ' ' || chr == '-' || chr == ',' || chr == ':'
|
||||||
|
|| chr == '(' || chr == ')' || chr == '[' || chr == ']';
|
||||||
|
}
|
||||||
|
|
||||||
//! Checks whether the format string contains invalid characters or not
|
//! Checks whether the format string contains invalid characters or not
|
||||||
/*!
|
/*!
|
||||||
\param string The format string
|
\param string The format string
|
||||||
|
@ -237,11 +252,10 @@ size_t findNginxFieldEnd( std::string_view string, const size_t start )
|
||||||
*/
|
*/
|
||||||
void checkIisString( std::string_view string )
|
void checkIisString( std::string_view string )
|
||||||
{
|
{
|
||||||
for ( const char chr : string ) {
|
if ( const auto it{ std::find_if_not( string.cbegin(), string.cend(), checkIisChar ) };
|
||||||
if ( !(StringOps::isAlnum( chr ) || chr == ' ' || chr == '-' || chr == ',' || chr == ':' || chr == '(' || chr == ')' || chr == '[' || chr == ']') ) {
|
it != string.cend() ) {
|
||||||
// unwanted character
|
// unwanted character
|
||||||
throw LogFormatException( "Unexpected character found: '"+std::string{chr}+"'" );
|
throw LogFormatException( "Unexpected character found in string: '"+std::string{*it}+"'" );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +313,7 @@ LogsFormat FormatOps::processApacheFormatString( const std::string& f_str ) cons
|
||||||
// the percent sign character, will be used as separator, skip
|
// the percent sign character, will be used as separator, skip
|
||||||
stop = aux + 2ul;
|
stop = aux + 2ul;
|
||||||
continue;
|
continue;
|
||||||
} else if ( ! StringOps::isAlnum( c ) ) {
|
} else if ( ! CharOps::isAlnum( c ) ) {
|
||||||
// invalid, there must be a field code, a status code or a percent sign after a '%'
|
// invalid, there must be a field code, a status code or a percent sign after a '%'
|
||||||
throw LogFormatException( "Invalid format: there must be a valid format code, a status code or a percent sign character after a '%', found: '%"+std::string{c}+"'" );
|
throw LogFormatException( "Invalid format: there must be a valid format code, a status code or a percent sign character after a '%', found: '%"+std::string{c}+"'" );
|
||||||
}
|
}
|
||||||
|
@ -320,7 +334,7 @@ LogsFormat FormatOps::processApacheFormatString( const std::string& f_str ) cons
|
||||||
|
|
||||||
char c = f_str.at( aux );
|
char c = f_str.at( aux );
|
||||||
// remove the per-status directives (if any)
|
// remove the per-status directives (if any)
|
||||||
if ( StringOps::isNumeric( c ) || c == '!' || c == ',' ) {
|
if ( CharOps::isNumeric( c ) || c == '!' || c == ',' ) {
|
||||||
// per-status, not important for LogDoctor
|
// per-status, not important for LogDoctor
|
||||||
size_t aux_aux{ aux+1ul };
|
size_t aux_aux{ aux+1ul };
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -328,7 +342,7 @@ LogsFormat FormatOps::processApacheFormatString( const std::string& f_str ) cons
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
c = f_str.at( aux_aux );
|
c = f_str.at( aux_aux );
|
||||||
if ( StringOps::isNumeric( c ) || c == '!' || c == ',' ) {
|
if ( CharOps::isNumeric( c ) || c == '!' || c == ',' ) {
|
||||||
// skip these chars
|
// skip these chars
|
||||||
aux_aux ++;
|
aux_aux ++;
|
||||||
continue;
|
continue;
|
||||||
|
@ -612,11 +626,12 @@ LogsFormat FormatOps::processNginxFormatString( const std::string& f_str ) const
|
||||||
}
|
}
|
||||||
aux ++;
|
aux ++;
|
||||||
// find the end of the current field
|
// find the end of the current field
|
||||||
stop = findNginxFieldEnd( f_str, aux ) + 1ul;
|
stop = findNginxFieldEnd( f_str, aux );
|
||||||
if ( stop == max ) {
|
if ( stop == max ) {
|
||||||
// this is the last field, and ther's no final separator
|
// this is the last field, and ther's no final separator
|
||||||
finished |= true;
|
finished |= true;
|
||||||
}
|
}
|
||||||
|
stop ++;
|
||||||
|
|
||||||
cur_sep = f_str.substr( start, aux-start-1ul );
|
cur_sep = f_str.substr( start, aux-start-1ul );
|
||||||
cur_fld = f_str.substr( aux, stop-aux );
|
cur_fld = f_str.substr( aux, stop-aux );
|
||||||
|
@ -686,10 +701,6 @@ QString FormatOps::getNginxLogSample( const LogsFormat& log_format ) const
|
||||||
|
|
||||||
LogsFormat FormatOps::processIisFormatString( const std::string& f_str, const int& l_mod ) const
|
LogsFormat FormatOps::processIisFormatString( const std::string& f_str, const int& l_mod ) const
|
||||||
{
|
{
|
||||||
if ( f_str.empty() ) {
|
|
||||||
return LogsFormat();
|
|
||||||
}
|
|
||||||
|
|
||||||
checkIisString( f_str );
|
checkIisString( f_str );
|
||||||
std::string initial, final;
|
std::string initial, final;
|
||||||
std::vector<std::string> separators, fields;
|
std::vector<std::string> separators, fields;
|
||||||
|
|
|
@ -344,9 +344,9 @@ private:
|
||||||
{"ssl_server_name", "NONE"},
|
{"ssl_server_name", "NONE"},
|
||||||
{"ssl_session_id", "NONE"},
|
{"ssl_session_id", "NONE"},
|
||||||
{"ssl_session_reused", "NONE"},
|
{"ssl_session_reused", "NONE"},
|
||||||
{"tcpinfo_rtt,", "NONE"},
|
{"tcpinfo_rtt", "NONE"},
|
||||||
{"tcpinfo_rttvar,", "NONE"},
|
{"tcpinfo_rttvar", "NONE"},
|
||||||
{"tcpinfo_snd_cwnd,", "NONE"},
|
{"tcpinfo_snd_cwnd", "NONE"},
|
||||||
{"tcpinfo_rcv_space", "NONE"},
|
{"tcpinfo_rcv_space", "NONE"},
|
||||||
{"uid_got", "NONE"},
|
{"uid_got", "NONE"},
|
||||||
{"uid_reset", "NONE"},
|
{"uid_reset", "NONE"},
|
||||||
|
|
Loading…
Reference in a new issue