I asked about this quite a while ago... been running it for a while and it
seems to work pretty well...
Basically just cycles logfiles, naming them by day..
Modified slightly to work with stock, so not entirely tested.. but I think
it's error-free.
/* merc.h */
#define LOG_DIR "../log"
void cycle_log();
void set_logfile(char *file);
/*
update.c, in update_handler
You'll probably want to alter it a little to match your
timezone...
and maybe stick it in one of the other pulses so it's
only called every few minutes instead of every second.
*/
static int last_log_cycle;
...
if (last_log_cycle != (current_time/86400))
{
cycle_log();
last_log_cycle = current_time/86400;
}
/* comm.c, main */
sprintf( log_buf, "ROM is ready to rock on port %d.", port );
log_string( log_buf );
+ cycle_log();
game_loop_unix( control );
/* anywhere... probably update.c or comm.c */
void set_logfile(char *file)
{
char buf[255];
FILE *fp;
sprintf(buf, "%s/%s", LOG_DIR, file);
fp = fopen(buf, "a");
if (!fp)
perror(file);
else
{
dup2(fileno(fp), STDOUT_FILENO);
dup2(fileno(fp), STDERR_FILENO);
}
fclose(fp);
}
void cycle_log()
{
struct tm *now;
char buf[255];
time_t t = time(0);
now = localtime(&t);
sprintf(buf, "%02d-%02d-%02d.log", now->tm_mon+1,
now->tm_mday, now->tm_year%100);
set_logfile(buf);
}
like it? hate it? found a problem with it? please let me know..
--Palrich.