tinywebd

view libtinyweb/src/logger.c @ 10:0dd50a23f3dd

separated all the tinyweb functionality out as a library
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 18 Apr 2015 22:47:57 +0300
parents src/logger.c@5ec50ca0d071
children 86f703031228
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <stdarg.h>
5 #include <errno.h>
6 #include "logger.h"
8 static FILE *logfile;
10 int set_log_file(const char *fname)
11 {
12 FILE *fp;
14 if(!(fp = fopen(fname, "w"))) {
15 fprintf(stderr, "failed to open logfile: %s: %s\n", fname, strerror(errno));
16 return -1;
17 }
18 setvbuf(fp, 0, _IONBF, 0);
19 logfile = fp;
20 return 0;
21 }
23 void logmsg(const char *fmt, ...)
24 {
25 va_list ap;
27 if(!logfile) {
28 logfile = stderr;
29 }
31 va_start(ap, fmt);
32 vfprintf(logfile, fmt, ap);
33 va_end(ap);
34 }