Added logging for server using syslog.

This commit is contained in:
lotodore
2007-10-23 21:26:07 +00:00
parent ae030a3669
commit b4848532f9
12 changed files with 175 additions and 111 deletions
+3 -2
View File
@@ -19,6 +19,7 @@
***************************************************************************/
#include "configfile.h"
#include <qttoolsinterface.h>
#include <core/loghelper.h>
#define MODUS 0711
@@ -325,7 +326,7 @@ void ConfigFile::fillBuffer() {
}
else { cout << "Could not find the element to fill the config-buffer with!"; }
else { LOG_ERROR("Could not find the root element in the config file!"); }
// cout << configBufferList[i].name << " " << configBufferList[i].defaultValue << endl;
}
@@ -522,7 +523,7 @@ void ConfigFile::updateConfig(ConfigState myConfigState) {
}
newDoc.SaveFile( configFileName );
}
else { cout << "cannot update config file. did not found it" << endl; }
else { LOG_ERROR("Cannot update config file: Unable to load configuration."); }
}
+95 -95
View File
@@ -1,95 +1,95 @@
/***************************************************************************
* Copyright (C) 2007 by Lothar May *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "convhelper.h"
#ifdef _WIN32
#error This file is not for Windows.
#endif
#include <string>
#include <iostream>
#include <iconv.h>
#include <errno.h>
using namespace std;
string
ConvHelper::NativeToUtf8(const std::string &inStr)
{
string retStr(inStr);
size_t insize = inStr.length();
char *inbuf = const_cast<char *>(inStr.data());
const size_t c_outsize = insize * 6; // max size of utf-8 char is 6 per input char
size_t outsize = c_outsize;
char *c_outbuf = new char[outsize];
char *outbuf = c_outbuf;
//nl_langinfo(CODESET)
iconv_t conversion = iconv_open("UTF-8", "ISO-8859-1");
if (conversion == (iconv_t)(-1))
cout << "iconv_open() failed: " << strerror(errno) << endl;
else
{
size_t retval = iconv(conversion, &inbuf, &insize, &outbuf, &outsize);
if (retval == -1)
cout << "iconv() failed: " << strerror(errno) << endl;
retStr = string(c_outbuf, c_outsize - outsize);
}
delete[] c_outbuf;
iconv_close(conversion);
return retStr;
}
string
ConvHelper::Utf8ToNative(const std::string &inStr)
{
string retStr(inStr);
size_t insize = inStr.length();
char *inbuf = const_cast<char *>(inStr.data());
const size_t c_outsize = insize;
size_t outsize = c_outsize;
char *c_outbuf = new char[outsize];
char *outbuf = c_outbuf;
iconv_t conversion = iconv_open("ISO-8859-1", "UTF-8");
if (conversion == (iconv_t)(-1))
cout << "iconv_open() failed: " << strerror(errno) << endl;
else
{
size_t retval = iconv(conversion, &inbuf, &insize, &outbuf, &outsize);
if (retval == -1)
cout << "iconv() failed: " << strerror(errno) << endl;
retStr = string(c_outbuf, c_outsize - outsize);
}
delete[] c_outbuf;
iconv_close(conversion);
return retStr;
}
/***************************************************************************
* Copyright (C) 2007 by Lothar May *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "convhelper.h"
#include <core/loghelper.h>
#ifdef _WIN32
#error This file is not for Windows.
#endif
#include <string>
#include <iconv.h>
#include <errno.h>
using namespace std;
string
ConvHelper::NativeToUtf8(const std::string &inStr)
{
string retStr(inStr);
size_t insize = inStr.length();
char *inbuf = const_cast<char *>(inStr.data());
const size_t c_outsize = insize * 6; // max size of utf-8 char is 6 per input char
size_t outsize = c_outsize;
char *c_outbuf = new char[outsize];
char *outbuf = c_outbuf;
//nl_langinfo(CODESET)
iconv_t conversion = iconv_open("UTF-8", "ISO-8859-1");
if (conversion == (iconv_t)(-1))
LOG_ERROR("iconv_open() failed: " << strerror(errno));
else
{
size_t retval = iconv(conversion, &inbuf, &insize, &outbuf, &outsize);
if (retval == -1)
LOG_ERROR("iconv() failed: " << strerror(errno));
retStr = string(c_outbuf, c_outsize - outsize);
}
delete[] c_outbuf;
iconv_close(conversion);
return retStr;
}
string
ConvHelper::Utf8ToNative(const std::string &inStr)
{
string retStr(inStr);
size_t insize = inStr.length();
char *inbuf = const_cast<char *>(inStr.data());
const size_t c_outsize = insize;
size_t outsize = c_outsize;
char *c_outbuf = new char[outsize];
char *outbuf = c_outbuf;
iconv_t conversion = iconv_open("ISO-8859-1", "UTF-8");
if (conversion == (iconv_t)(-1))
LOG_ERROR("iconv_open() failed: " << strerror(errno));
else
{
size_t retval = iconv(conversion, &inbuf, &insize, &outbuf, &outsize);
if (retval == -1)
LOG_ERROR("iconv() failed: " << strerror(errno));
retStr = string(c_outbuf, c_outsize - outsize);
}
delete[] c_outbuf;
iconv_close(conversion);
return retStr;
}
+47
View File
@@ -0,0 +1,47 @@
/***************************************************************************
* Copyright (C) 2007 by Lothar May *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
/* Helper class for logging. */
#ifndef _LOGHELPER_H_
#define _LOGHELPER_H_
#ifndef _WIN32
#ifdef POKERTH_DEDICATED_SERVER
#include <sstream>
#include <syslog.h>
#include <stdarg.h>
#define LOG_ERROR(e) \
do \
{ \
std::ostringstream outStream; \
outStream << e << std::endl; \
syslog(LOG_ERR, "%s", outStream.str()); \
} \
while(false)
#endif
#endif
#ifndef LOG_ERROR
#include <iostream>
#define LOG_ERROR(e) \
std::cout << e << std::endl
#endif
#endif
+8 -1
View File
@@ -21,6 +21,7 @@
#include "localexception.h"
#include "engine_msg.h"
#include <core/loghelper.h>
using namespace std;
@@ -61,6 +62,12 @@ LocalBeRo::~LocalBeRo()
{
}
int LocalBeRo::getHighestCardsValue() const
{
LOG_ERROR(__FILE__ << " (" << __LINE__ << "): getHighestCardsValue() in wrong BeRo");
return 0;
}
void LocalBeRo::nextPlayer() {
PlayerListConstIterator currentPlayersTurnConstIt = myHand->getRunningPlayerIt(currentPlayersTurnId);
@@ -137,7 +144,7 @@ void LocalBeRo::run() {
break;
case GAME_STATE_RIVER: myHand->getGuiInterface()->logDealBoardCardsMsg(myBeRoID, tempBoardCardsArray[0], tempBoardCardsArray[1], tempBoardCardsArray[2], tempBoardCardsArray[3], tempBoardCardsArray[4]);
break;
default: { cout << "ERROR in localbero.cpp - wrong myBeRoID" << endl;}
default: { LOG_ERROR(__FILE__ << " (" << __LINE__ << "): ERROR - wrong myBeRoID"); }
}
logBoardCardsDone = true;
+1 -2
View File
@@ -21,7 +21,6 @@
#define LOCALBERO_H
#include <iostream>
#include "game_defs.h"
#include "berointerface.h"
@@ -34,7 +33,7 @@ public:
GameState getMyBeRoID() const { return myBeRoID; }
int getHighestCardsValue() const { std::cout << "getHighestCardsValue() in wrong BeRo" << std::endl; return 0; }
int getHighestCardsValue() const;
void setHighestCardsValue(int /*theValue*/) { }
void setMinimumRaise ( int theValue ) { minimumRaise = theValue; }
+2 -1
View File
@@ -21,6 +21,7 @@
#include "handinterface.h"
#include <game_defs.h>
#include <core/loghelper.h>
#include "localexception.h"
#include "engine_msg.h"
@@ -214,7 +215,7 @@ void LocalBoard::distributePot() {
// ERROR-Outputs
if(pot!=0) cout << "distributePot-ERROR: Pot = " << pot << endl;
if(pot!=0) LOG_ERROR(__FILE__ << " (" << __LINE__ << "): distributePot-ERROR: Pot = " << pot);
int sum = 0;
+3 -2
View File
@@ -21,6 +21,7 @@
#include "tools.h"
#include "cardsvalue.h"
#include <game_defs.h>
#include <core/loghelper.h>
#include "localexception.h"
#include "engine_msg.h"
@@ -79,7 +80,7 @@ LocalHand::LocalHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, BoardI
// error-check
for(j=0; j<5; j++) {
if (bestHandPos[j] == -1) {
cout << "ERROR getMyBestHandPosition in localhand.cpp" << endl;
LOG_ERROR(__FILE__ << " (" << __LINE__ << "): ERROR getMyBestHandPosition");
}
}
@@ -336,7 +337,7 @@ void LocalHand::start() {
if(it_sB != getActivePlayerList()->end() && it_bB != getActivePlayerList()->end()) {
myGui->logNewBlindsSetsMsg((*it_sB)->getMySet(), (*it_bB)->getMySet(), (*it_sB)->getMyName().c_str(), (*it_bB)->getMyName().c_str());
}
else { cout << "Log Error: cannot find sBID or bBID" << "\n"; }
else { LOG_ERROR(__FILE__ << " (" << __LINE__ << "): Log Error: cannot find sBID or bBID"); }
myGui->flushLogAtHand();
// deal cards
+8 -4
View File
@@ -22,8 +22,10 @@
#include "tools.h"
#include "cardsvalue.h"
#include <configfile.h>
#include <core/loghelper.h>
#include <fstream>
#include <sstream>
using namespace std;
@@ -3524,7 +3526,7 @@ void LocalPlayer::calcMyOdds() {
break;
}
}
if(myOdds == -1) cout << "ERROR myOdds - " << handCode << endl;
if (myOdds == -1) LOG_ERROR(__FILE__ << " (" << __LINE__ << "): ERROR myOdds - " << handCode);
}
break;
@@ -3559,8 +3561,10 @@ void LocalPlayer::calcMyOdds() {
}
}
if(myOdds == -1) {
cout << "ERROR" << endl;
for(i=0; i<5; i++) cout << tempArray[i] << " ";
ostringstream logger;
logger << "ERROR myOdds is -1: ";
for(i=0; i<5; i++) logger << tempArray[i] << " ";
LOG_ERROR(__FILE__ << " (" << __LINE__ << "): " << logger.str());
// cout << "\t" << handCode << "\t" << myID << endl;
} else {
// cout << myHoleCardsValue << endl;
@@ -3679,7 +3683,7 @@ void LocalPlayer::calcMyOdds() {
}
break;
default: cout <<"ERROR - wrong init of currentRound" << endl;
default: LOG_ERROR(__FILE__ << " (" << __LINE__ << "): ERROR - wrong init of currentRound");
}
+3 -3
View File
@@ -102,7 +102,7 @@ Log::Log(mainWindowImpl* w, ConfigFile *c) : myW(w), myConfig(c), myLogDir(0), m
}
}
else { cout << "Log directory doesn't exists. Cannot create log files"; }
else { cout << "Log directory doesn't exist. Cannot create log files"; }
}
}
@@ -1624,9 +1624,9 @@ void Log::writeLogFileStream(QString streamString) {
stream << streamString;
myLogFile->close();
}
else { cout << "could not open log-file to write log-messages!" << endl; }
else { cout << "Could not open log-file to write log-messages!" << endl; }
}
else { cout << "could not find log-file to write log-messages!" << endl; }
else { cout << "Could not find log-file to write log-messages!" << endl; }
}
void Log::flushLogAtHand() {
+1 -1
View File
@@ -1907,7 +1907,7 @@ void mainWindowImpl::provideMyActions() {
//if text changed on checked button --> uncheck to prevent unwanted actions
if((pushButtonCallCheckString != lastPushButtonCallCheckString && pushButton_CallCheck->isChecked()) || (pushButtonBetRaiseString != lastPushButtonBetRaiseString && pushButton_BetRaise->isChecked()) ) {
cout << "jo" << endl;
// cout << "jo" << endl;
uncheckMyButtons();
resetMyButtonsCheckStateMemory();
}
+2
View File
@@ -25,6 +25,7 @@
#include <net/serverexception.h>
#include <net/socket_msg.h>
#include <net/socket_startup.h>
#include <core/loghelper.h>
#define ACCEPT_TIMEOUT_MSEC 50
#define NET_SERVER_LISTEN_BACKLOG 5
@@ -87,6 +88,7 @@ ServerAcceptThread::Main()
} catch (const PokerTHException &e)
{
GetCallback().SignalNetServerError(e.GetErrorId(), e.GetOsErrorCode());
LOG_ERROR(e.what());
}
GetLobbyThread().SignalTermination();
GetLobbyThread().Join(LOBBY_THREAD_TERMINATE_TIMEOUT);
+2
View File
@@ -25,6 +25,7 @@
#include <net/receiverhelper.h>
#include <net/socket_msg.h>
#include <core/avatarmanager.h>
#include <core/loghelper.h>
#include <openssl/rand.h>
#include <boost/lambda/lambda.hpp>
@@ -289,6 +290,7 @@ ServerLobbyThread::Main()
} catch (const PokerTHException &e)
{
GetCallback().SignalNetServerError(e.GetErrorId(), e.GetOsErrorCode());
LOG_ERROR(e.what());
}
TerminateGames();