Add kludge for IntelliJ IDEA transients
[notion.git] / ioncore / log.c
blobeafed54f9c50ab68080ede0c29801a4b5fd8ac09
1 /*
2 * notion/ioncore/log.c
4 * Copyright (c) the Notion team 2013
6 * See the included file LICENSE for details.
7 */
9 #include <stdarg.h>
10 #include <stddef.h>
11 #include <stdio.h>
12 #include <time.h>
13 #include "log.h"
15 const char* loglevel_names[] = {
16 "DEBUG",
17 "INFO",
18 "WARN",
19 "ERROR",
22 /** For this category, show log messages at this loglevel and above */
23 LogLevel minimumLevel(LogCategory category)
25 switch(category){
26 case VALGRIND:
27 return DEBUG;
28 default:
29 return INFO;
33 #define TIME_BUFFER_MAXSIZE 100
35 void printtime(FILE *stream, const char *format, time_t time)
37 char buf[TIME_BUFFER_MAXSIZE];
38 strftime(buf, TIME_BUFFER_MAXSIZE, format, localtime(&time));
39 fprintf(stream, "%s", buf);
42 void vlog_message(LogLevel level, LogCategory category, const char *file, int line, const char *function, const char *message, va_list argp)
44 if(level >= minimumLevel(category)){
45 printtime(stderr, "%F %T ", time(NULL));
46 fprintf(stderr, "%-6s", loglevel_names[level]);
47 if(file==NULL)
48 fprintf(stderr, "Notion: ");
49 else
50 fprintf(stderr, "/notion/../%s:%d: %s: ", file, line, function);
52 vfprintf(stderr, message, argp);
53 fprintf(stderr, "\n");
57 void log_message(LogLevel level, LogCategory category, const char *file, int line, const char* function, const char* message, ...)
59 va_list argp;
60 va_start(argp, message);
61 vlog_message(level, category, file, line, function, message, argp);
62 va_end(argp);
65 #if __STDC_VERSION__ < 199901L
66 extern void LOG(LogLevel level, LogCategory category, const char* message, ...)
68 va_list argp;
69 va_start(argp, message);
70 vlog_message(level, category, NULL, -1, NULL, message, argp);
71 va_end(argp);
73 #endif