log.c
TinyMAZE/src/io/log.c · 2.2 KB
From the archive TinyMAZEv2.5a.tar.gz
Download the archive « Back to the archive contents
/* log.c */
/* $Id: log.c,v 1.7 1993/12/19 17:59:51 nils Exp $ */
#include <stdio.h>
#include "db.h"
#include "config.h"
#include "externs.h"
#include "log.h"
struct log
command_log = { NULL, -1, "logs/commands", "*log_command" },
important_log = { NULL, -1, "logs/important", "*log_imp" },
sensitive_log = { NULL, -1, "logs/sensitive", "*log_sens" },
error_log = { NULL, -1, "logs/error", "*log_err" },
io_log = { NULL, -1, "logs/io", "*log_io" },
gripe_log = { NULL, -1, "logs/gripe", "*log_gripe" },
root_log = { NULL, -1, "logs/root", "*log_root" },
huh_log = { NULL, -1, "logs/huh", "*log_huh" },
denied_log = {NULL, -1, "logs/denied", "*log_denied" },
suspect_log = {NULL, -1, "logs/suspect", "*log_suspect" },
force_log = {NULL, -1, "logs/force", "*log_force" },
misc_log = {NULL, -1, "logs/misc", "*log_misc" },
guest_log = {NULL, -1, "logs/guest", "*log_guest" },
complaint_log = {NULL, -1, "logs/complaint", ".complaint" }
;
struct log *logs[] = {
&command_log,
&important_log,
&sensitive_log,
&error_log,
&io_log,
&gripe_log,
&root_log,
&huh_log,
&denied_log,
&suspect_log,
&force_log,
&misc_log,
&guest_log,
&complaint_log,
0
};
void muse_log(struct log *l, char *str)
{
time_t when;
struct tm *bdown;
char buf[2048];
if(l->com_channel)
{
sprintf(buf, "|R|* |n|%s", str);
com_send(l->com_channel, NULL, buf);
}
if(!l->fptr)
{
l->fptr = fopen(l->filename, "a");
if(!l->fptr)
{
mkdir("logs", 0755);
l->fptr = fopen(l->filename, "a");
if(!l->fptr)
{
fprintf(stderr,
"BLEEEP! couldn't open log file %s\n", l->filename);
return;
}
}
}
when = time(0);
bdown = localtime(&when);
fprintf(l->fptr, "%02d/%02d:%02d:%02d:%02d| %s\n",
bdown->tm_mon+1, bdown->tm_mday, bdown->tm_hour, bdown->tm_min,
bdown->tm_sec, color(str, REMOVE));
fflush(l->fptr);
if(l->counter-- < 0)
{
l->counter = 100;
fclose(l->fptr);
l->fptr = NULL;
if(l == &command_log)
{
char oldfilename[64];
sprintf(oldfilename, "%s~", l->filename);
unlink(oldfilename);
rename(l->filename, oldfilename);
}
}
}
void close_logs()
{
int i;
for(i = 0;logs[i];i++)
if(logs[i]->fptr)
fclose(logs[i]->fptr);
}