More verbose logging for the server.

This commit is contained in:
lotodore
2008-03-19 23:39:59 +00:00
parent 0575d1eb1c
commit c8b38d0e57
6 changed files with 88 additions and 11 deletions
+24 -5
View File
@@ -39,14 +39,16 @@ using namespace boost::posix_time;
#define SERVER_MSG_LOG_FILE_NAME "server_messages.log"
static string g_logFile;
static int g_logLevel = 1;
void
loghelper_init(const string &logDir)
loghelper_init(const string &logDir, int logLevel)
{
path tmpLogFile(logDir);
tmpLogFile /= SERVER_MSG_LOG_FILE_NAME;
g_logFile = tmpLogFile.directory_string();
g_logLevel = logLevel;
}
void
@@ -63,11 +65,28 @@ internal_log_err(const string &msg)
void
internal_log_msg(const std::string &msg)
{
if (!g_logFile.empty())
if (g_logLevel)
{
ofstream o(g_logFile.c_str(), ios_base::out | ios_base::app);
if (!o.fail())
o << second_clock::local_time() << " MSG: " << msg;
if (!g_logFile.empty())
{
ofstream o(g_logFile.c_str(), ios_base::out | ios_base::app);
if (!o.fail())
o << second_clock::local_time() << " MSG: " << msg;
}
}
}
void
internal_log_level(const std::string &msg, int logLevel)
{
if (g_logLevel >= logLevel)
{
if (!g_logFile.empty())
{
ofstream o(g_logFile.c_str(), ios_base::out | ios_base::app);
if (!o.fail())
o << second_clock::local_time() << " OUT: " << msg;
}
}
}