Greetings Rommers.
Currently using a logsystem I made along time ago, but iam gona remake it as
it has problems,
maybe even more than I know of, but one of the problems I have is that, if I
on the 1th of the month logs on and I quit the sameday,
then if nobody goes on/off until the 3th then I will not have a file for the
2th off the mouth.
To make things alittle more clear, the idea was to have, logs by date made
by the mud,
rather than the normal 1xxx made by the startup script, log files named like
DD-MM-YYYY.log
and inside looks like, HH:MM:SS - bla bla bla.
it works fine like this, but my log functions if the one creating the file,
so if the log functions hasn't been used for more than a day,
then that day the file will be missing instead of being just empty, so what
I need is a way to check for a new day, and I have only
little idea about how to do that, I will include my current log.c for you
reading, hope you can and will help alittle.
<<< log.c >>>
#include "include.h"
char *get_log_time(void);
char *get_log_date(void);
static char time_str[10];
static char date_str[12];
void logf (char * fmt, ...)
{
char buf [2*MSL];
va_list args;
va_start (args, fmt);
vsprintf (buf, fmt, args);
va_end (args);
log(buf);
return;
}
void log(char * fmt, ...)
{
FILE *fstdout;
char buf [2*MAX_STRING_LENGTH];
char logfile [MAX_STRING_LENGTH];
va_list args;
char *date;
char *time;
time = get_log_time();
date = get_log_date();
va_start (args, fmt);
vsprintf (buf, fmt, args);
va_end (args);
sprintf(logfile,"../data/logs/%s.log",date);
if ((fstdout=freopen(logfile,"a",stdout)) == NULL)
{
printf("Can't open Logfile.\n");
}
fprintf(stdout,"%s - %s\n",time,buf);
fflush(stdout);
return;
}
char *get_log_time(void)
{
time_t basictime;
if (time(&basictime) == (time_t) -1)
return NULL;
if (strftime(time_str, 10, "%X",localtime(&basictime)) == 0)
return NULL;
else
return time_str;
}
char *get_log_date(void)
{
time_t basicdate;
if (time(&basicdate) == (time_t) -1)
return NULL;
if (strftime(date_str, 12, "%d-%m-%Y",localtime(&basicdate)) == 0)
return NULL;
else
return date_str;
}
<<< end of log.c >>>