tinywebd
view libtinyweb/src/logger.c @ 12:86f703031228
Attribution headers
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 19 Apr 2015 00:01:01 +0300 |
parents | 0dd50a23f3dd |
children |
line source
1 /* tinyweb - tiny web server library and daemon
2 * Author: John Tsiombikas <nuclear@member.fsf.org>
3 *
4 * This program is placed in the public domain. Feel free to use it any
5 * way you like. Mentions and retaining this attribution header will be
6 * appreciated, but not required.
7 */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <stdarg.h>
12 #include <errno.h>
13 #include "logger.h"
15 static FILE *logfile;
17 int set_log_file(const char *fname)
18 {
19 FILE *fp;
21 if(!(fp = fopen(fname, "w"))) {
22 fprintf(stderr, "failed to open logfile: %s: %s\n", fname, strerror(errno));
23 return -1;
24 }
25 setvbuf(fp, 0, _IONBF, 0);
26 logfile = fp;
27 return 0;
28 }
30 void logmsg(const char *fmt, ...)
31 {
32 va_list ap;
34 if(!logfile) {
35 logfile = stderr;
36 }
38 va_start(ap, fmt);
39 vfprintf(logfile, fmt, ap);
40 va_end(ap);
41 }