|
|
@ -13,23 +13,22 @@
|
|
|
|
void slog(const struct server *s, log_level level, const char *body) {
|
|
|
|
void slog(const struct server *s, log_level level, const char *body) {
|
|
|
|
const char *c = ".-*#";
|
|
|
|
const char *c = ".-*#";
|
|
|
|
time_t now = time(NULL);
|
|
|
|
time_t now = time(NULL);
|
|
|
|
FILE *fp;
|
|
|
|
static FILE *fp = NULL;
|
|
|
|
char buf[64];
|
|
|
|
char buf[64];
|
|
|
|
char msg[1024];
|
|
|
|
char msg[124];
|
|
|
|
|
|
|
|
|
|
|
|
if(level > s->cfg->verbosity) {
|
|
|
|
static pid_t self = 0;
|
|
|
|
return;
|
|
|
|
if(!self) self = getpid();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
snprintf(msg, sizeof(msg), "%s", body);
|
|
|
|
if(level > s->cfg->verbosity) return; /* too verbose */
|
|
|
|
|
|
|
|
|
|
|
|
fp = (s->cfg->logfile == NULL) ? stdout : fopen(s->cfg->logfile,"a");
|
|
|
|
if(!fp) fp = (s->cfg->logfile == NULL) ? stdout : fopen(s->cfg->logfile, "a");
|
|
|
|
if(!fp) return;
|
|
|
|
if(!fp) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* limit message size */
|
|
|
|
|
|
|
|
snprintf(msg, sizeof(msg), "%s", body);
|
|
|
|
|
|
|
|
|
|
|
|
strftime(buf,sizeof(buf),"%d %b %H:%M:%S",localtime(&now));
|
|
|
|
strftime(buf,sizeof(buf),"%d %b %H:%M:%S",localtime(&now));
|
|
|
|
fprintf(fp,"[%d] %s %c %s\n",(int)getpid(),buf,c[level],msg);
|
|
|
|
fprintf(fp,"[%d] %s %c %s\n", (int)self, buf, c[level], msg);
|
|
|
|
fprintf(stdout,"[%d] %s %c %s\n",(int)getpid(),buf,c[level],msg);
|
|
|
|
|
|
|
|
fflush(fp);
|
|
|
|
fflush(fp);
|
|
|
|
|
|
|
|
|
|
|
|
if(s->cfg->logfile) fclose(fp);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|