root / mainbox / log.c @ master
History | View | Annotate | Download (523 Bytes)
1 | 5e03b78d | Tom Mullins | #include "log.h" |
---|---|---|---|
2 | #include <stdio.h> |
||
3 | #include <stdarg.h> |
||
4 | #include <time.h> |
||
5 | #include <errno.h> |
||
6 | #include <sys/time.h> |
||
7 | |||
8 | void log_time() {
|
||
9 | char buf[100]; |
||
10 | time_t t; |
||
11 | time(&t); |
||
12 | strftime(buf, sizeof(buf), "%b %e %T %Y", localtime(&t)); |
||
13 | printf("[%s] ", buf);
|
||
14 | } |
||
15 | |||
16 | void log_print(const char *fmt, ...) { |
||
17 | va_list args; |
||
18 | va_start(args, fmt); |
||
19 | log_time(); |
||
20 | vprintf(fmt, args); |
||
21 | printf("\n");
|
||
22 | va_end(args); |
||
23 | 9e26460d | root | fflush(stdout); |
24 | 5e03b78d | Tom Mullins | } |
25 | |||
26 | void log_perror(const char *s) { |
||
27 | log_time(); |
||
28 | cc7646f9 | Tom Mullins | printf("%s: %s\n", s, sys_errlist[errno]);
|
29 | 5e03b78d | Tom Mullins | } |