Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 58 lines (53 sloc) 1.477 kb
d7e37a6 @karlp Replace all logging
karlp authored
1 /*
2 * UglyLogging. Slow, yet another wheel reinvented, but enough to make the
3 * rest of our code pretty enough.
4 *
5 */
6
7 #include <stddef.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <stdarg.h>
11 #include <time.h>
12
13 #include "uglylogging.h"
14
15 static int max_level;
16
17 int ugly_init(int maximum_threshold) {
18 max_level = maximum_threshold;
19 return 0;
20 }
21
22 int ugly_log(int level, const char *tag, const char *format, ...) {
23 if (level > max_level) {
24 return 0;
25 }
26 va_list args;
27 va_start(args, format);
28 time_t mytt = time(NULL);
29 struct tm *tt;
30 tt = localtime(&mytt);
31 fprintf(stderr, "%d-%02d-%02dT%02d:%02d:%02d ", tt->tm_year + 1900, tt->tm_mon + 1, tt->tm_mday, tt->tm_hour, tt->tm_min, tt->tm_sec);
32 switch (level) {
33 case UDEBUG:
34 fprintf(stderr, "DEBUG %s: ", tag);
35 break;
36 case UINFO:
37 fprintf(stderr, "INFO %s: ", tag);
38 break;
39 case UWARN:
40 fprintf(stderr, "WARN %s: ", tag);
41 break;
42 case UERROR:
43 fprintf(stderr, "ERROR %s: ", tag);
44 break;
45 case UFATAL:
46 fprintf(stderr, "FATAL %s: ", tag);
47 vfprintf(stderr, format, args);
48 exit(EXIT_FAILURE);
49 // NEVER GETS HERE!!!
50 break;
51 default:
52 fprintf(stderr, "%d %s: ", level, tag);
53 break;
54 }
55 vfprintf(stderr, format, args);
56 va_end(args);
57 return 1;
58 }
Something went wrong with that request. Please try again.