commit
bec19d06eb
@ -0,0 +1,3 @@
|
||||
*.log
|
||||
*.o
|
||||
webdis
|
@ -0,0 +1,27 @@
|
||||
/* A slog is a simple log. Basically extracted from antirez/redis. */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void slog(const char *logfile, int level, const char *body) {
|
||||
const char *c = ".-*#";
|
||||
time_t now = time(NULL);
|
||||
FILE *fp;
|
||||
char buf[64];
|
||||
char msg[1024];
|
||||
|
||||
snprintf(msg, sizeof(msg), "%s", body);
|
||||
|
||||
fp = (logfile == NULL) ? stdout : fopen(logfile,"a");
|
||||
if (!fp) return;
|
||||
|
||||
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(stdout,"[%d] %s %c %s\n",(int)getpid(),buf,c[level],msg);
|
||||
fflush(fp);
|
||||
|
||||
if (logfile) fclose(fp);
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
#ifndef SLOG_H
|
||||
#define SLOG_H
|
||||
|
||||
void slog(const char *logfile, int level, const char *body);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue