Moved LogType definition to LogOps
This commit is contained in:
parent
2cf9e0669e
commit
fe844dd5b3
5 changed files with 94 additions and 84 deletions
|
@ -192,9 +192,9 @@ void MainWindow::on_buttonViewFile_clicked()
|
|||
Craplog::LogFile item = this->craplog.getLogFileItem(
|
||||
this->ui->listLogFiles->selectedItems().takeFirst()->text(0) );
|
||||
FormatOps::LogsFormat format;
|
||||
if ( item.type == Craplog::LogType::Access ) {
|
||||
if ( item.type == LogOps::LogType::Access ) {
|
||||
format = this->craplog.getCurrentALF();
|
||||
} else if ( item.type == Craplog::LogType::Error ) {
|
||||
} else if ( item.type == LogOps::LogType::Error ) {
|
||||
format = this->craplog.getCurrentELF();
|
||||
} else {
|
||||
// this shouldn't be
|
||||
|
|
|
@ -133,9 +133,9 @@ void Craplog::scanLogsDir()
|
|||
.name = QString::fromStdString( name ),
|
||||
.hash = this->hashOps.digestFile( path ),
|
||||
.path = path,
|
||||
.type = this->defineFileType( name, IOutils::readLines( path ) )
|
||||
.type = this->logOps.defineFileType( name, IOutils::readLines( path ), this->logs_formats[ this->current_WS ] )
|
||||
};
|
||||
if ( logfile.type == Craplog::LogType::Failed ) {
|
||||
if ( logfile.type == LogOps::LogType::Failed ) {
|
||||
// failed to get the log type
|
||||
// error message displayed while defining as failed in logOps
|
||||
continue;
|
||||
|
@ -170,74 +170,6 @@ bool Craplog::isFileNameValid( std::string name )
|
|||
}
|
||||
|
||||
|
||||
Craplog::LogType Craplog::defineFileType( std::string name, std::vector<std::string> lines )
|
||||
{
|
||||
int n_acc=0, n_err=0;
|
||||
Craplog::LogType supposed_type, real_type;
|
||||
if ( StringOps::startsWith( name, "access" ) ) {
|
||||
supposed_type = Craplog::LogType::Access;
|
||||
} else if ( StringOps::startsWith( name, "error" ) ) {
|
||||
supposed_type = Craplog::LogType::Error;
|
||||
} else {
|
||||
// this shouldn't be
|
||||
// !!! PUT A DIALOG ERROR MESSAGE HERE !!!
|
||||
}
|
||||
real_type = Craplog::LogType::Failed;
|
||||
for ( const std::string& line : lines ) {
|
||||
if ( supposed_type == Craplog::LogType::Access ) {
|
||||
if ( this->current_ALF.initial.size() > 0 ) {
|
||||
// a fixed starter char is set
|
||||
if ( StringOps::startsWith( line, this->current_ALF.initial ) == false ) {
|
||||
// but wasn't found
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ( this->current_ALF.final.size() > 0 ) {
|
||||
// a fixed starter char is set
|
||||
if ( StringOps::endsWith( line, this->current_ALF.final ) == false ) {
|
||||
// but wasn't found
|
||||
continue;
|
||||
}
|
||||
}
|
||||
n_acc++;
|
||||
} else {
|
||||
if ( this->current_ELF.initial.size() > 0 ) {
|
||||
// a fixed starter char is set
|
||||
if ( StringOps::startsWith( line, this->current_ELF.initial ) == false ) {
|
||||
// but wasn't found
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ( this->current_ELF.final.size() > 0 ) {
|
||||
// a fixed starter char is set
|
||||
if ( StringOps::endsWith( line, this->current_ELF.final ) == false ) {
|
||||
// but wasn't found
|
||||
continue;
|
||||
}
|
||||
}
|
||||
n_err++;
|
||||
}
|
||||
}
|
||||
if ( n_acc > 0 && n_err == 0 ) {
|
||||
// access logs
|
||||
real_type = Craplog::LogType::Access;
|
||||
} else if ( n_err > 0 && n_acc == 0 ) {
|
||||
// error logs
|
||||
real_type = Craplog::LogType::Error;
|
||||
} else {
|
||||
// something is wrong with these logs, put a warnin
|
||||
if ( n_acc > 0 && n_err > 0 ) {
|
||||
// both access and error types found
|
||||
// !!! PUT A DIALOG ERROR MESSAGE HERE !!!
|
||||
} else {
|
||||
// every line was invalid
|
||||
// !!! PUT A DIALOG ERROR MESSAGE HERE !!!
|
||||
}
|
||||
}
|
||||
return real_type;
|
||||
}
|
||||
|
||||
|
||||
// get the logs format
|
||||
FormatOps::LogsFormat Craplog::getAccessLogsFormat( int web_server_id )
|
||||
{
|
||||
|
|
|
@ -16,7 +16,7 @@ class Craplog
|
|||
public:
|
||||
Craplog();
|
||||
|
||||
// web servers
|
||||
// web servers ID constants
|
||||
const unsigned int APACHE_ID=11, NGINX_ID=12, IIS_ID=13;
|
||||
|
||||
// logs formats
|
||||
|
@ -31,21 +31,16 @@ public:
|
|||
FormatOps::LogsFormat getCurrentALF();
|
||||
FormatOps::LogsFormat getCurrentELF();
|
||||
|
||||
|
||||
// log file infoes
|
||||
enum LogType {
|
||||
Failed=0,
|
||||
Access=1,
|
||||
Error=2
|
||||
};
|
||||
// log file item
|
||||
// log type constants
|
||||
const unsigned int FAILED=0, ACCESS_LOGS=1, ERROR_LOGS=2;
|
||||
// log file item's infoes
|
||||
struct LogFile {
|
||||
bool selected;
|
||||
int size;
|
||||
QString name;
|
||||
std::string hash;
|
||||
std::string path;
|
||||
LogType type;
|
||||
LogOps::LogType type;
|
||||
};
|
||||
// logs list related methods
|
||||
std::vector<LogFile> getLogsList( bool fresh=false );
|
||||
|
@ -57,8 +52,6 @@ public:
|
|||
int setLogFileSelected( QString file_name );
|
||||
// check if a file name respects the one set
|
||||
bool isFileNameValid( std::string name );
|
||||
// define if really access and/or error logs
|
||||
Craplog::LogType defineFileType( std::string name, std::vector<std::string> lines );
|
||||
|
||||
// logs usage control
|
||||
HashOps hashOps;
|
||||
|
|
|
@ -7,6 +7,77 @@ LogOps::LogOps()
|
|||
|
||||
}
|
||||
|
||||
|
||||
LogOps::LogType LogOps::defineFileType( std::string name, std::vector<std::string> lines, std::unordered_map<int, FormatOps::LogsFormat> formats )
|
||||
{
|
||||
int n_acc=0, n_err=0;
|
||||
LogOps::LogType supposed_type, real_type;
|
||||
FormatOps::LogsFormat current_ALF = formats[1],
|
||||
current_ELF = formats[2];
|
||||
if ( StringOps::startsWith( name, "access" ) ) {
|
||||
supposed_type = LogOps::LogType::Access;
|
||||
} else if ( StringOps::startsWith( name, "error" ) ) {
|
||||
supposed_type = LogOps::LogType::Error;
|
||||
} else {
|
||||
// this shouldn't be
|
||||
// !!! PUT A DIALOG ERROR MESSAGE HERE !!!
|
||||
}
|
||||
real_type = this->LogType::Failed;
|
||||
for ( const std::string& line : lines ) {
|
||||
if ( supposed_type == LogOps::LogType::Access ) {
|
||||
if ( current_ALF.initial.size() > 0 ) {
|
||||
// a fixed starter char is set
|
||||
if ( StringOps::startsWith( line, current_ALF.initial ) == false ) {
|
||||
// but wasn't found
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ( current_ALF.final.size() > 0 ) {
|
||||
// a fixed starter char is set
|
||||
if ( StringOps::endsWith( line, current_ALF.final ) == false ) {
|
||||
// but wasn't found
|
||||
continue;
|
||||
}
|
||||
}
|
||||
n_acc++;
|
||||
} else {
|
||||
if ( current_ELF.initial.size() > 0 ) {
|
||||
// a fixed starter char is set
|
||||
if ( StringOps::startsWith( line, current_ELF.initial ) == false ) {
|
||||
// but wasn't found
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ( current_ELF.final.size() > 0 ) {
|
||||
// a fixed starter char is set
|
||||
if ( StringOps::endsWith( line, current_ELF.final ) == false ) {
|
||||
// but wasn't found
|
||||
continue;
|
||||
}
|
||||
}
|
||||
n_err++;
|
||||
}
|
||||
}
|
||||
if ( n_acc > 0 && n_err == 0 ) {
|
||||
// access logs
|
||||
real_type = LogOps::LogType::Access;
|
||||
} else if ( n_err > 0 && n_acc == 0 ) {
|
||||
// error logs
|
||||
real_type = LogOps::LogType::Error;
|
||||
} else {
|
||||
// something is wrong with these logs, put a warnin
|
||||
if ( n_acc > 0 && n_err > 0 ) {
|
||||
// both access and error types found
|
||||
// !!! PUT A DIALOG ERROR MESSAGE HERE !!!
|
||||
} else {
|
||||
// every line was invalid
|
||||
// !!! PUT A DIALOG ERROR MESSAGE HERE !!!
|
||||
}
|
||||
}
|
||||
return real_type;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> LogOps::splitLine( std::string line, int type )
|
||||
{
|
||||
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "utilities/strings.h"
|
||||
#include "tools/craplog/modules/formats.h"
|
||||
|
||||
|
||||
class LogOps
|
||||
|
@ -10,6 +14,16 @@ class LogOps
|
|||
public:
|
||||
LogOps();
|
||||
|
||||
// log file types
|
||||
enum LogType {
|
||||
Failed=0,
|
||||
Access=1,
|
||||
Error=2
|
||||
};
|
||||
|
||||
// define if really access and/or error logs
|
||||
LogType defineFileType( std::string name, std::vector<std::string> lines, std::unordered_map<int, FormatOps::LogsFormat> format );
|
||||
|
||||
std::vector<std::string> splitLine( std::string line, int type );
|
||||
std::vector<std::string> splitLines( std::string line, int type );
|
||||
|
||||
|
|
Loading…
Reference in a new issue