X-Git-Url: https://jfr.im/git/irc/gameservirc.git/blobdiff_plain/fb37ecc77caa85e78ea60e0ed9aa37ccaa3c2c5c..f71a53ab6e251712c26a11c0b373d41014f775d5:/gameserv/log.cpp diff --git a/gameserv/log.cpp b/gameserv/log.cpp index fda60ba..d7c8ee5 100644 --- a/gameserv/log.cpp +++ b/gameserv/log.cpp @@ -2,68 +2,69 @@ #include #include #include +#include -using std::endl; -using std::cerr; -using std::ofstream; -using std::ios; +using namespace std; void log(const char *fmt, ...) { - if (fmt[0] == '\0') - return; - - ofstream outfile; - char *ts, *output; - const char *t = fmt; - - ts = new char[32]; - output = new char[4096]; - - outfile.open("gameserv.log", ios::out | ios::app); - - if (outfile.fail()) - { - cerr << "Error opening gameserv.log" << endl; + if (fmt[0] == '\0') return; - } - - struct tm *tm; - time_t ti; - time(&ti); - tm = localtime(&ti); - strftime(ts, 32, "%Y%m%d", tm); - - sprintf(output, "[%s]: ", ts); - - va_list args; - va_start(args, fmt); - - for (; *t; t++) + + ofstream outfile; + char *ts, *output; + const char *t = fmt; + + ts = new char[64]; + output = new char[4096]; + + outfile.open("gameserv.log", ios::out | ios::app); + + if (outfile.fail()) + { + delete []ts; + delete []output; + cerr << "Error opening gameserv.log" << endl; + return; + } + + struct tm *tm; + time_t ti; + time(&ti); + tm = localtime(&ti); + strftime(ts, 64, "%m/%d/%Y %H:%M:%S", tm); + + sprintf(output, "[%s]: ", ts); + + va_list args; + va_start(args, fmt); + + for (; *t; t++) { - if (*t == '%') + if (*t == '%') { - switch(*++t) { - case 'd': sprintf(output, "%s%d", output, va_arg(args, int)); break; - case 's': sprintf(output, "%s%s", output, va_arg(args, char *)); break; - case 'S': sprintf(output, "%s%s", output, s_GameServ); break; - case 'l': - if (*++t == 'd') - sprintf(output, "%s%ld", output, va_arg(args, long int)); break; - } + switch(*++t) { + case 'd': sprintf(output, "%s%d", output, va_arg(args, int)); break; + case 's': sprintf(output, "%s%s", output, va_arg(args, char *)); break; + case 'S': sprintf(output, "%s%s", output, s_GameServ); break; + case 'c': sprintf(output, "%s%c", output, va_arg(args, int)); break; + case 'l': + if (*++t == 'd') + sprintf(output, "%s%ld", output, va_arg(args, long int)); break; + } } - else + else { - sprintf(output, "%s%c", output, *t); + sprintf(output, "%s%c", output, *t); } - + } - - outfile << output << endl; - - outfile.close(); - va_end(args); - - delete [] ts; - delete [] output; + + outfile << output << endl; + + outfile.close(); + va_end(args); + + delete [] ts; + delete [] output; }