Improvements

Added new-lines support.
Removed support for carriage-return in the LogsFormat.
This commit is contained in:
Valentino Orlandi 2022-08-16 22:02:27 +02:00
parent 0976eb0d42
commit 0d1e23e110
Signed by: elB4RTO
GPG Key ID: 1719E976DB2D4E71
2 changed files with 28 additions and 8 deletions

View File

@ -10,6 +10,20 @@ FormatOps::FormatOps()
}
// count the new lines
const int FormatOps::countNewLines( const std::string& initial, const std::string& final, const std::vector<std::string>& separators )
{
int nl = 0;
nl += StringOps::count( initial, "\n" );
nl += StringOps::count( final, "\n" );
for ( const std::string& sep : separators ) {
nl += StringOps::count( sep, "\n" );
}
return nl;
}
// process escapes like apache
const std::string FormatOps::parseApacheEscapes( const std::string& string , const bool& strftime )
{
@ -70,8 +84,8 @@ const std::string FormatOps::parseApacheEscapes( const std::string& string , con
str2.push_back( '\n' );
i++;
} else if ( cc == 'r' ) {
str2.push_back( '\r' );
i++;
// not supported
throw LogFormatException( "LogDoctor doesn't support the usage of the Carriage Return: '\\r'." );
} else if ( cc == 't' ) {
str2.push_back( '\t' );
i++;
@ -134,8 +148,8 @@ const std::string FormatOps::parseNginxEscapes( const std::string& string )
str.push_back( '\n' );
i++;
} else if ( cc == 'r' ) {
str.push_back( '\r' );
i++;
// not supported
throw LogFormatException( "LogDoctor doesn't support the usage of the Carriage Return: '\\r'." );
} else if ( cc == 't' ) {
str.push_back( '\t' );
i++;
@ -465,7 +479,8 @@ const FormatOps::LogsFormat FormatOps::processApacheFormatString( const std::str
.initial = initial,
.final = final,
.separators = separators,
.fields = fields
.fields = fields,
.new_lines = this->countNewLines( initial, final, separators )
};
}
@ -566,7 +581,8 @@ const FormatOps::LogsFormat FormatOps::processNginxFormatString( const std::stri
.initial = initial,
.final = final,
.separators = separators,
.fields = fields
.fields = fields,
.new_lines = this->countNewLines( initial, final, separators )
};
}
// sample
@ -666,7 +682,8 @@ const FormatOps::LogsFormat FormatOps::processIisFormatString( const std::string
.initial = initial,
.final = final,
.separators = separators,
.fields = fields
.fields = fields,
.new_lines = 0
};
}
// sample

View File

@ -20,6 +20,7 @@ public:
std::string final;
std::vector<std::string> separators;
std::vector<std::string> fields;
int new_lines;
};
const LogsFormat processApacheFormatString( const std::string& formatted_string );
@ -35,6 +36,8 @@ private:
const std::string parseApacheEscapes( const std::string& string, const bool& strftime=false );
const std::string parseNginxEscapes( const std::string& string );
const int countNewLines( const std::string& initial, const std::string& final, const std::vector<std::string>& separatprs );
const int findNginxFieldEnd( const std::string& string, const int& start );
void checkIisString( const std::string& string );
@ -314,7 +317,7 @@ private:
const std::unordered_map<std::string, QString> NGINX_ALF_SAMPLES = {
{"NONE", "<span style=\"color:#7f7f7f\">DISCARDED</span>"},
{"date_time_epoch_s.ms", "<b><span style=\"color:#00cc6f\">946771199.000</span></b>"},
{"date_time_iso", "<b><span style=\"color:#00cc6f\">2000-01-01T23:59:59+00:00]</span></b>"},
{"date_time_iso", "<b><span style=\"color:#00cc6f\">2000-01-01T23:59:59+00:00</span></b>"},
{"date_time_mcs", "<b><span style=\"color:#00cc6f\">Sat Jan 01 23:59:59 2000</span></b>"},
{"date_time_gmt", "<b><span style=\"color:#00cc6f\">Saturday, 01-Jan-2000 23:59:59 UTC</span></b>"},
{"request_full", "<b><span style=\"color:#00cc6f\">GET /index.php?query=x HTTP/1.1</span></b>"},