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 LogLevel
minimumLevel(LogCategory category
)
27 /** For https://sourceforge.net/p/notion/bugs/63/ */
34 #define TIME_BUFFER_MAXSIZE 100
36 void printtime(FILE *stream
, const char *format
, time_t time
)
38 char buf
[TIME_BUFFER_MAXSIZE
];
39 strftime(buf
, TIME_BUFFER_MAXSIZE
, format
, localtime(&time
));
40 fprintf(stream
, "%s", buf
);
43 void vlog_message(LogLevel level
, LogCategory category
, const char *file
, int line
, const char *function
, const char *message
, va_list argp
)
45 if(level
>= minimumLevel(category
)){
46 printtime(stderr
, "%F %T ", time(NULL
));
47 fprintf(stderr
, "%-6s", loglevel_names
[level
]);
49 fprintf(stderr
, "Notion: ");
51 fprintf(stderr
, "/notion/../%s:%d: %s: ", file
, line
, function
);
53 vfprintf(stderr
, message
, argp
);
54 fprintf(stderr
, "\n");
58 void log_message(LogLevel level
, LogCategory category
, const char *file
, int line
, const char* function
, const char* message
, ...)
61 va_start(argp
, message
);
62 vlog_message(level
, category
, file
, line
, function
, message
, argp
);
66 #if __STDC_VERSION__ < 199901L
67 extern void LOG(LogLevel level
, LogCategory category
, const char* message
, ...)
70 va_start(argp
, message
);
71 vlog_message(level
, category
, NULL
, -1, NULL
, message
, argp
);