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
// channel first so that this channel is marked as connected
bCreateChanList = true;
// send message about new channel
emit ChannelConnected ( HostAdr );
}
else
{

View File

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

View File

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

View File

@ -26,7 +26,8 @@
/* Implementation *************************************************************/
CServer::CServer ( const bool bUseLogging, const quint16 iPortNumber,
CServer::CServer ( const QString& strLoggingFileName,
const quint16 iPortNumber,
const QString& strHTMLStatusFileName,
const QString& strServerNameForHTMLStatusFile,
const bool bForceLowUploadRate ) :
@ -47,6 +48,11 @@ CServer::CServer ( const bool bUseLogging, const quint16 iPortNumber,
SIGNAL ( MessReadyForSending ( 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
// 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
@ -54,9 +60,9 @@ CServer::CServer ( const bool bUseLogging, const quint16 iPortNumber,
#endif
// enable logging (if requested)
if ( bUseLogging )
if ( !strLoggingFileName.isEmpty() )
{
Logging.Start();
Logging.Start ( strLoggingFileName );
}
// HTML status file writing
@ -110,7 +116,18 @@ void CServer::Stop()
Timer.stop();
// 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
Logging << strLogStr; // in log file

View File

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

View File

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