Log to file as dedicated server (do not use syslog any more).
This commit is contained in:
@@ -27,6 +27,12 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
void
|
||||||
|
loghelper_init(const std::string & /*logDir*/)
|
||||||
|
{
|
||||||
|
// Do not log to file as client.
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
internal_log_err(const string &msg)
|
internal_log_err(const string &msg)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,34 +21,57 @@
|
|||||||
#error This file is only for the server.
|
#error This file is only for the server.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <core/loghelper.h>
|
#ifdef _MSC_VER
|
||||||
#ifdef _WIN32
|
#pragma warning(push)
|
||||||
#include <iostream>
|
#pragma warning(disable : 4100)
|
||||||
#else
|
|
||||||
#include <syslog.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <core/loghelper.h>
|
||||||
|
#include <fstream>
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <boost/date_time.hpp>
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace boost::filesystem;
|
||||||
|
using namespace boost::posix_time;
|
||||||
|
|
||||||
|
#define SERVER_MSG_LOG_FILE_NAME "server_messages.log"
|
||||||
|
|
||||||
|
static string g_logFile;
|
||||||
|
|
||||||
|
void
|
||||||
|
loghelper_init(const string &logDir)
|
||||||
|
{
|
||||||
|
path tmpLogFile(logDir);
|
||||||
|
tmpLogFile /= SERVER_MSG_LOG_FILE_NAME;
|
||||||
|
|
||||||
|
g_logFile = tmpLogFile.directory_string();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
internal_log_err(const string &msg)
|
internal_log_err(const string &msg)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
if (!g_logFile.empty())
|
||||||
cout << msg;
|
{
|
||||||
#else
|
ofstream o(g_logFile.c_str(), ios_base::out | ios_base::app);
|
||||||
syslog(LOG_ERR, "%s", msg.c_str());
|
if (!o.fail())
|
||||||
#endif
|
o << second_clock::local_time() << " ERR: " << msg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
internal_log_msg(const std::string &msg)
|
internal_log_msg(const std::string &msg)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
if (!g_logFile.empty())
|
||||||
cout << msg;
|
{
|
||||||
#else
|
ofstream o(g_logFile.c_str(), ios_base::out | ios_base::app);
|
||||||
syslog(LOG_INFO, "%s", msg.c_str());
|
if (!o.fail())
|
||||||
#endif
|
o << second_clock::local_time() << " MSG: " << msg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
void loghelper_init(const std::string &logDir);
|
||||||
|
|
||||||
void internal_log_err(const std::string &msg);
|
void internal_log_err(const std::string &msg);
|
||||||
void internal_log_msg(const std::string &msg);
|
void internal_log_msg(const std::string &msg);
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
//create defaultconfig
|
//create defaultconfig
|
||||||
ConfigFile *myConfig = new ConfigFile(argc, argv);
|
ConfigFile *myConfig = new ConfigFile(argc, argv);
|
||||||
|
loghelper_init(myConfig->readConfigString("LogDir"));
|
||||||
|
|
||||||
// TODO: Hack
|
// TODO: Hack
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
@@ -103,7 +104,7 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
myServerGuiInterface->getSession().terminateNetworkServer();
|
myServerGuiInterface->getSession().terminateNetworkServer();
|
||||||
|
|
||||||
LOG_MSG("Terminating PokerTH dedicated server.");
|
LOG_MSG("Terminating PokerTH dedicated server." << endl);
|
||||||
socket_cleanup();
|
socket_cleanup();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user