/*
* log_file.c
*
* SFUN: Log a message to file
*
* (C) Frank Schmidt, Jesus@NorseMUD
*
*/
#include <std.h>
/* max filesizes for logfiles */
#define MAX_LOG_SIZE 200000
#define MAX_ENTER_LOG 1000000
static int log_file(string file, string what) {
int maxlog, nr;
string pre;
/* wrong file? */
if (!file || !strlen(file))
return 0;
/* absolute path, or not? */
if (file[0] != '/') {
/* parse the path into domains and playerdirs */
string pfile, domain;
pfile = file_name();
if (sscanf(pfile, DOMAIN_DIR+"%s/%*s", domain) == 2)
file = DOMAIN_DIR+domain+LOCAL_LOG_DIR+file;
else if (sscanf(pfile, PLAYER_DIR+"%s/%*s", domain) == 2)
file = PLAYER_DIR+domain+LOCAL_LOG_DIR+file;
else
/* set default path for log_file */
file = LOG_DIR + file;
}
/*D_LOGWATCH->logwatch(file, what); */
if (file == LOG_DIR+"ENTER")
maxlog = MAX_ENTER_LOG;
else
maxlog = MAX_LOG_SIZE;
/* save exceeded log file, and start fresh? */
if (file_size(file) > maxlog) {
rename_file(file, file+".old");
}
pre = short_ctime(time()) + " ";
if (nr=GLOBAL->log_file(file, what))
pre = "Last message repeated "+(string)nr+" times.\n" + pre;
if (nr != -1)
/* append <what> message to logfile */
return write_file(file, pre + what);
return 1;
}