improved server logging functionality

This commit is contained in:
Volker Fischer 2008-12-02 18:02:40 +00:00
parent ce9e842601
commit 810268a61c
6 changed files with 48 additions and 22 deletions

View File

@ -284,6 +284,9 @@ bool CChannelSet::PutData ( const CVector<unsigned char>& vecbyRecBuf,
// the message here since the received data has to be put to the // the message here since the received data has to be put to the
// channel first so that this channel is marked as connected // channel first so that this channel is marked as connected
bCreateChanList = true; bCreateChanList = true;
// send message about new channel
emit ChannelConnected ( HostAdr );
} }
else else
{ {

View File

@ -323,6 +323,7 @@ public slots:
signals: signals:
void MessReadyForSending ( int iChID, CVector<uint8_t> vecMessage ); void MessReadyForSending ( int iChID, CVector<uint8_t> vecMessage );
void ChannelConnected ( CHostAddress ChanAddr );
}; };
#endif /* !defined ( CHANNEL_HOIH9345KJH98_3_4344_BB23945IUHF1912__INCLUDED_ ) */ #endif /* !defined ( CHANNEL_HOIH9345KJH98_3_4344_BB23945IUHF1912__INCLUDED_ ) */

View File

@ -31,7 +31,7 @@
#include "settings.h" #include "settings.h"
/* Implementation *************************************************************/ // Implementation **************************************************************
// these pointers are only used for the post-event routine // these pointers are only used for the post-event routine
QApplication* pApp = NULL; QApplication* pApp = NULL;
QDialog* pMainWindow = NULL; QDialog* pMainWindow = NULL;
@ -45,19 +45,19 @@ int main ( int argc, char** argv )
/* check if server or client application shall be started */ /* check if server or client application shall be started */
bool bIsClient = true; bool bIsClient = true;
bool bUseGUI = true; bool bUseGUI = true;
bool bUseServerLogging = false;
bool bForceLowUploadRate = false; bool bForceLowUploadRate = false;
quint16 iPortNumber = LLCON_PORT_NUMBER; quint16 iPortNumber = LLCON_PORT_NUMBER;
std::string strIniFileName = ""; std::string strIniFileName = "";
std::string strHTMLStatusFileName = ""; std::string strHTMLStatusFileName = "";
std::string strServerName = ""; std::string strServerName = "";
std::string strLoggingFileName = "";
/* QT docu: argv()[0] is the program name, argv()[1] is the first /* QT docu: argv()[0] is the program name, argv()[1] is the first
argument and argv()[argc()-1] is the last argument. argument and argv()[argc()-1] is the last argument.
Start with first argument, therefore "i = 1" */ Start with first argument, therefore "i = 1" */
for ( int i = 1; i < argc; i++ ) for ( int i = 1; i < argc; i++ )
{ {
/* Server mode flag ------------------------------------------------------- */ // server mode flag ----------------------------------------------------------
if ( GetFlagArgument ( argc, argv, i, "-s", "--server" ) ) if ( GetFlagArgument ( argc, argv, i, "-s", "--server" ) )
{ {
bIsClient = false; bIsClient = false;
@ -65,7 +65,7 @@ int main ( int argc, char** argv )
continue; continue;
} }
/* Use GUI flag ----------------------------------------------------------- */ // use GUI flag --------------------------------------------------------------
if ( GetFlagArgument ( argc, argv, i, "-n", "--nogui" ) ) if ( GetFlagArgument ( argc, argv, i, "-n", "--nogui" ) )
{ {
bUseGUI = false; bUseGUI = false;
@ -73,15 +73,15 @@ int main ( int argc, char** argv )
continue; continue;
} }
/* Use logging flag ------------------------------------------------------- */ // use logging ---------------------------------------------------------------
if ( GetFlagArgument ( argc, argv, i, "-l", "--log" ) ) if ( GetStringArgument ( argc, argv, i, "-l", "--log", strArgument ) )
{ {
bUseServerLogging = true; strLoggingFileName = strArgument;
cerr << "logging enabled" << std::endl; cerr << "logging file name: " << strLoggingFileName << std::endl;
continue; continue;
} }
/* Force low upload data rate flag ---------------------------------------- */ // force low upload data rate flag -------------------------------------------
if ( GetFlagArgument ( argc, argv, i, "-u", "--lowuploadrate" ) ) if ( GetFlagArgument ( argc, argv, i, "-u", "--lowuploadrate" ) )
{ {
bForceLowUploadRate = true; bForceLowUploadRate = true;
@ -89,7 +89,7 @@ int main ( int argc, char** argv )
continue; continue;
} }
/* Port number ------------------------------------------------------------ */ // port number ---------------------------------------------------------------
if ( GetNumericArgument ( argc, argv, i, "-p", "--port", if ( GetNumericArgument ( argc, argv, i, "-p", "--port",
0, 65535, rDbleArgument ) ) 0, 65535, rDbleArgument ) )
{ {
@ -98,7 +98,7 @@ int main ( int argc, char** argv )
continue; continue;
} }
/* HTML status file ------------------------------------------------------- */ // HTML status file ----------------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-m", "--htmlstatus", strArgument ) ) if ( GetStringArgument ( argc, argv, i, "-m", "--htmlstatus", strArgument ) )
{ {
strHTMLStatusFileName = strArgument; strHTMLStatusFileName = strArgument;
@ -113,7 +113,7 @@ int main ( int argc, char** argv )
continue; continue;
} }
/* Initialization file ---------------------------------------------------- */ // initialization file -------------------------------------------------------
if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) ) if ( GetStringArgument ( argc, argv, i, "-i", "--inifile", strArgument ) )
{ {
strIniFileName = strArgument; strIniFileName = strArgument;
@ -121,7 +121,7 @@ int main ( int argc, char** argv )
continue; continue;
} }
/* Help (usage) flag ------------------------------------------------------ */ // help (usage) flag ---------------------------------------------------------
if ( ( !strcmp ( argv[i], "--help" ) ) || if ( ( !strcmp ( argv[i], "--help" ) ) ||
( !strcmp ( argv[i], "-h" ) ) || ( !strcmp ( argv[i], "-?" ) ) ) ( !strcmp ( argv[i], "-h" ) ) || ( !strcmp ( argv[i], "-?" ) ) )
{ {
@ -130,7 +130,7 @@ int main ( int argc, char** argv )
exit ( 1 ); exit ( 1 );
} }
/* Unknown option --------------------------------------------------------- */ // unknown option ------------------------------------------------------------
cerr << argv[0] << ": "; cerr << argv[0] << ": ";
cerr << "Unknown option '" << argv[i] << "' -- use '--help' for help" cerr << "Unknown option '" << argv[i] << "' -- use '--help' for help"
<< endl; << endl;
@ -190,7 +190,8 @@ int main ( int argc, char** argv )
// TODO use QString // TODO use QString
CServer Server ( bUseServerLogging, iPortNumber, CServer Server ( strLoggingFileName.c_str(),
iPortNumber,
strHTMLStatusFileName.c_str(), strHTMLStatusFileName.c_str(),
strServerName.c_str(), strServerName.c_str(),
bForceLowUploadRate ); bForceLowUploadRate );

View File

@ -26,7 +26,8 @@
/* Implementation *************************************************************/ /* Implementation *************************************************************/
CServer::CServer ( const bool bUseLogging, const quint16 iPortNumber, CServer::CServer ( const QString& strLoggingFileName,
const quint16 iPortNumber,
const QString& strHTMLStatusFileName, const QString& strHTMLStatusFileName,
const QString& strServerNameForHTMLStatusFile, const QString& strServerNameForHTMLStatusFile,
const bool bForceLowUploadRate ) : const bool bForceLowUploadRate ) :
@ -47,6 +48,11 @@ CServer::CServer ( const bool bUseLogging, const quint16 iPortNumber,
SIGNAL ( MessReadyForSending ( int, CVector<uint8_t> ) ), SIGNAL ( MessReadyForSending ( int, CVector<uint8_t> ) ),
this, SLOT ( OnSendProtMessage ( int, CVector<uint8_t> ) ) ); this, SLOT ( OnSendProtMessage ( int, CVector<uint8_t> ) ) );
// connection for logging
QObject::connect ( &ChannelSet,
SIGNAL ( ChannelConnected ( CHostAddress ) ),
this, SLOT ( OnNewChannel ( CHostAddress ) ) );
#ifdef _WIN32 #ifdef _WIN32
// event handling of custom events seems not to work under Windows in this // event handling of custom events seems not to work under Windows in this
// class, do not use automatic start/stop of server in Windows version // class, do not use automatic start/stop of server in Windows version
@ -54,9 +60,9 @@ CServer::CServer ( const bool bUseLogging, const quint16 iPortNumber,
#endif #endif
// enable logging (if requested) // enable logging (if requested)
if ( bUseLogging ) if ( !strLoggingFileName.isEmpty() )
{ {
Logging.Start(); Logging.Start ( strLoggingFileName );
} }
// HTML status file writing // HTML status file writing
@ -110,7 +116,18 @@ void CServer::Stop()
Timer.stop(); Timer.stop();
// logging // logging
QString strLogStr = CLogTimeDate::toString() + "Server stopped"; const QString strLogStr = CLogTimeDate::toString() + ": server stopped "
"#####################################################";
qDebug() << strLogStr; // on console
Logging << strLogStr; // in log file
}
void CServer::OnNewChannel ( CHostAddress ChanAddr )
{
// logging of new connected channel
const QString strLogStr = CLogTimeDate::toString() + ": " +
ChanAddr.InetAddr.toString() + " connected";
qDebug() << strLogStr; // on console qDebug() << strLogStr; // on console
Logging << strLogStr; // in log file Logging << strLogStr; // in log file

View File

@ -41,7 +41,8 @@ class CServer : public QObject
Q_OBJECT Q_OBJECT
public: public:
CServer ( const bool bUseLogging, const quint16 iPortNumber, CServer ( const QString& strLoggingFileName,
const quint16 iPortNumber,
const QString& strHTMLStatusFileName, const QString& strHTMLStatusFileName,
const QString& strServerNameForHTMLStatusFile, const QString& strServerNameForHTMLStatusFile,
const bool bForceLowUploadRate ); const bool bForceLowUploadRate );
@ -87,6 +88,7 @@ protected:
public slots: public slots:
void OnTimer(); void OnTimer();
void OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage ); void OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage );
void OnNewChannel ( CHostAddress ChanAddr );
}; };
#endif /* !defined ( SERVER_HOIHGE7LOKIH83JH8_3_43445KJIUHF1912__INCLUDED_ ) */ #endif /* !defined ( SERVER_HOIHGE7LOKIH83JH8_3_43445KJIUHF1912__INCLUDED_ ) */

View File

@ -487,10 +487,11 @@ public:
} }
} }
void Start() void Start ( const QString& strLoggingFileName )
{ {
// open file // open file
if ( File.open ( QIODevice::Append ) ) File.setFileName ( strLoggingFileName );
if ( File.open ( QIODevice::Append | QIODevice::Text ) )
{ {
bDoLogging = true; bDoLogging = true;
} }
@ -503,6 +504,7 @@ public:
// append new line in logging file // append new line in logging file
QTextStream out ( &File ); QTextStream out ( &File );
out << sNewStr << endl; out << sNewStr << endl;
File.flush();
} }
} }