1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
static char *getfileofday(void)
{
static char buf[25];
struct tm *tm;
time_t now;
now = time(NULL);
tm = localtime(&now);
strftime(buf, sizeof(buf), "logs/services.%Y-%m-%d", tm);
return buf;
}
int irclog(unsigned int flags, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZE];
FILE *fp;
size_t len;
char *filename = getfileofday();
va_start(ap, fmt);
len = vsprintf(buf, fmt, ap);
va_end(ap);
buf[len++] = '\n';
buf[len] = 0;
if (flags & LOG_FILE) {
if ((fp = file_create(filename))) {
fprintf(fp, buf);
fclose(fp);
}
else return irclog(LOG_TTY, "irclog(); can't open log file '%s'", filename);
}
if ((flags & LOG_TTY) && isatty(1))
puts(buf);
return 0;
} |
Partager