root/trunk/src/game/IRCLog.cpp @ 39

Revision 39, 1.8 kB (checked in by yumileroy, 17 years ago)

[svn] * Various small changes here and there.
* Implementing MangChat? IRC system.
* Added new config option, MAX_WHO, can be used to set the limit of characters being sent in a /who request from client.

Original author: XTZGZoReX
Date: 2008-10-12 14:03:38-05:00

Line 
1#include "IRCLog.h"
2#include "Config/ConfigEnv.h"
3#include "IRCClient.h"
4#include <stdarg.h>
5
6IRCLog::IRCLog()
7{
8    std::string logsDir = sConfig.GetStringDefault("LogsDir","");
9    std::string ircLogName = logsDir + "/IRC_";
10    std::string ircLogTimestamp = GetLogDateStr();
11        ircLogName += ircLogTimestamp +".log";
12    ircLogfile.open (ircLogName.c_str(), std::ios::app);
13}
14
15IRCLog::~IRCLog()
16{
17    ircLogfile.close();
18}
19// Was added because using the time for logs is very annoying... one log per day.. much cleaner looking..
20std::string IRCLog::GetLogDateStr() const
21{
22    time_t t = time(NULL);
23    tm* aTm = localtime(&t);
24    //       YYYY   year
25    //       MM     month (2 digits 01-12)
26    //       DD     day (2 digits 01-31)
27    //       HH     hour (2 digits 00-23)
28    //       MM     minutes (2 digits 00-59)
29    //       SS     seconds (2 digits 00-59)
30    char buf[20];
31    snprintf(buf,20,"%04d-%02d-%02d",aTm->tm_year+1900,aTm->tm_mon+1,aTm->tm_mday);
32    return std::string(buf);
33}
34
35std::string IRCLog::GetLogDateTimeStr() const
36{
37    time_t t = time(NULL);
38    tm* aTm = localtime(&t);
39    //       YYYY   year
40    //       MM     month (2 digits 01-12)
41    //       DD     day (2 digits 01-31)
42    //       HH     hour (2 digits 00-23)
43    //       MM     minutes (2 digits 00-59)
44    //       SS     seconds (2 digits 00-59)
45    char buf[30];
46        snprintf(buf,30,"[ %04d-%02d-%02d ] [ %02d:%02d:%02d ]",aTm->tm_year+1900,aTm->tm_mon+1,aTm->tm_mday,aTm->tm_hour,aTm->tm_min,aTm->tm_sec);
47    return std::string(buf);
48}
49
50void IRCLog::WriteLog(const char *what, ...)
51{
52    va_list ap;
53    char tmpoutp[1024];
54    va_start(ap, what);
55    vsnprintf(tmpoutp, 1024, what, ap );
56    va_end(ap);
57    ircLogfile << tmpoutp;
58    ircLogfile << "\n";
59    ircLogfile.flush();
60}
Note: See TracBrowser for help on using the browser.