very basic file-based server logger (no syslog yet) / WIP
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@1941 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
// server-side logging of events
|
||||
|
||||
#include "pch.h"
|
||||
#include "cube.h"
|
||||
|
||||
struct filelog : log
|
||||
{
|
||||
FILE *file;
|
||||
|
||||
filelog(char *filepath)
|
||||
{
|
||||
file = fopen(filepath, "w");
|
||||
}
|
||||
|
||||
~filelog()
|
||||
{
|
||||
if(file) fclose(file);
|
||||
}
|
||||
|
||||
virtual void writeline(int level, char *msg, ...)
|
||||
{
|
||||
if(!enabled) return;
|
||||
|
||||
s_sprintfdv(sf, msg);
|
||||
s_sprintfd(out)("%s\n", sf);
|
||||
filtertext(out, out);
|
||||
|
||||
if(console)
|
||||
{
|
||||
puts(out);
|
||||
fflush(stdout);
|
||||
}
|
||||
if(file)
|
||||
{
|
||||
fwrite(out, sizeof(char), strlen(out), file);
|
||||
fflush(file);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct syslog : log
|
||||
{
|
||||
virtual void writeline(int level, char *msg, ...)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct log *newlogger()
|
||||
{
|
||||
return new filelog("serverlog.txt");
|
||||
}
|
||||
Reference in New Issue
Block a user