added rudimental logging support

This commit is contained in:
Volker Fischer 2007-05-06 12:27:41 +00:00
parent b00a299082
commit c6717bbfee
5 changed files with 73 additions and 18 deletions

View file

@ -45,6 +45,8 @@
#define VERSION "1.0cvs" #define VERSION "1.0cvs"
#define APP_NAME "llcon" #define APP_NAME "llcon"
// file name for logging file
#define LOG_FILE_NAME "llconsrvlog.txt"
/* defined port number for client and server */ /* defined port number for client and server */
#define LLCON_PORT_NUMBER 22122 #define LLCON_PORT_NUMBER 22122

View file

@ -39,6 +39,7 @@ 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;
/* 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 */
@ -60,6 +61,15 @@ int main ( int argc, char** argv )
bIsClient = false; bIsClient = false;
bUseGUI = false; bUseGUI = false;
} }
/* "-sln": start server with GUI disabled and logging enabled */
strShortOpt = "-sln";
if ( !strShortOpt.compare ( argv[1] ) )
{
bIsClient = false;
bUseGUI = false;
bUseServerLogging = true;
}
} }
/* Application object */ /* Application object */
@ -93,7 +103,7 @@ int main ( int argc, char** argv )
{ {
/* server */ /* server */
// actual server object // actual server object
CServer Server; CServer Server ( bUseServerLogging );
if ( bUseGUI ) if ( bUseGUI )
{ {

View file

@ -26,7 +26,7 @@
/* Implementation *************************************************************/ /* Implementation *************************************************************/
CServer::CServer() : Socket ( &ChannelSet, this ) CServer::CServer ( const bool bUseLogging ) : Socket ( &ChannelSet, this )
{ {
vecsSendData.Init ( MIN_BLOCK_SIZE_SAMPLES ); vecsSendData.Init ( MIN_BLOCK_SIZE_SAMPLES );
@ -47,6 +47,12 @@ CServer::CServer() : Socket ( &ChannelSet, 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
Start(); Start();
#endif #endif
// enable logging (if requested)
if ( bUseLogging )
{
Logging.Start();
}
} }
void CServer::OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage ) void CServer::OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage )
@ -80,7 +86,11 @@ void CServer::Stop()
// stop main timer // stop main timer
Timer.stop(); Timer.stop();
qDebug ( CLogTimeDate::toString() + "Server stopped" ); // logging
QString strLogStr = CLogTimeDate::toString() + "Server stopped";
qDebug ( strLogStr ); // on console
Logging << strLogStr; // in log file
} }
void CServer::OnTimer() void CServer::OnTimer()

View file

@ -42,7 +42,7 @@ class CServer : public QObject
Q_OBJECT Q_OBJECT
public: public:
CServer (); CServer ( const bool bUseLogging );
virtual ~CServer() {} virtual ~CServer() {}
void Start (); void Start ();
@ -79,6 +79,9 @@ protected:
CMovingAv<double> RespTimeMoAvBuf; CMovingAv<double> RespTimeMoAvBuf;
QTime TimeLastBlock; QTime TimeLastBlock;
// logging
CLogging Logging;
public slots: public slots:
void OnTimer(); void OnTimer();
void OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage ); void OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage );

View file

@ -467,5 +467,35 @@ public:
}; };
/* Time and Data to String conversion --------------------------------------- */
class CLogging
{
public:
CLogging() : bDoLogging ( false ), pFile ( NULL ) {}
virtual ~CLogging()
{
if ( pFile != NULL )
{
fclose ( pFile );
}
}
void Start()
{
// open file
pFile = fopen ( LOG_FILE_NAME, "a" );
}
CLogging& operator<< ( const QString & sNewStr )
{
fprintf ( pFile, "%s\n", sNewStr.latin1() );
fflush ( pFile );
return *this;
}
protected:
bool bDoLogging;
FILE* pFile;
};
#endif /* !defined(UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_) */ #endif /* !defined(UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_) */