tinywebd
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libtinyweb/src/logger.c Sat Apr 18 22:47:57 2015 +0300 1.3 @@ -0,0 +1,34 @@ 1.4 +#include <stdio.h> 1.5 +#include <stdlib.h> 1.6 +#include <string.h> 1.7 +#include <stdarg.h> 1.8 +#include <errno.h> 1.9 +#include "logger.h" 1.10 + 1.11 +static FILE *logfile; 1.12 + 1.13 +int set_log_file(const char *fname) 1.14 +{ 1.15 + FILE *fp; 1.16 + 1.17 + if(!(fp = fopen(fname, "w"))) { 1.18 + fprintf(stderr, "failed to open logfile: %s: %s\n", fname, strerror(errno)); 1.19 + return -1; 1.20 + } 1.21 + setvbuf(fp, 0, _IONBF, 0); 1.22 + logfile = fp; 1.23 + return 0; 1.24 +} 1.25 + 1.26 +void logmsg(const char *fmt, ...) 1.27 +{ 1.28 + va_list ap; 1.29 + 1.30 + if(!logfile) { 1.31 + logfile = stderr; 1.32 + } 1.33 + 1.34 + va_start(ap, fmt); 1.35 + vfprintf(logfile, fmt, ap); 1.36 + va_end(ap); 1.37 +}