4 * Copyright (c) the Notion team 2013
6 * See the included file LICENSE for details.
15 const char* loglevel_names
[] = {
22 /** For this category, show log messages at this loglevel and above */
23 static LogLevel
minimumLevel(LogCategory category
)
33 #define TIME_BUFFER_MAXSIZE 100
35 static 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 static 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
]);
48 fprintf(stderr
, "Notion: ");
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
, ...)
60 va_start(argp
, message
);
61 vlog_message(level
, category
, file
, line
, function
, message
, argp
);
65 #if __STDC_VERSION__ < 199901L
66 extern void LOG(LogLevel level
, LogCategory category
, const char* message
, ...)
69 va_start(argp
, message
);
70 vlog_message(level
, category
, NULL
, -1, NULL
, message
, argp
);