#include "extern.h"
#include <cctype>
#include <stdio.h>
-#include <fstream.h>
+#include <fstream>
+#include <iostream>
+
+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(logfile, ios::out | ios::app);
-
- if (outfile.fail())
- {
- cerr << "Error opening " << logfile << 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;
}