xglcomp
diff src/logger.h @ 0:d9b3fba68705
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 21 Jan 2016 08:45:31 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/logger.h Thu Jan 21 08:45:31 2016 +0200 1.3 @@ -0,0 +1,54 @@ 1.4 +#ifndef LOGGER_H_ 1.5 +#define LOGGER_H_ 1.6 + 1.7 +#include <stdio.h> 1.8 +#include <stdarg.h> 1.9 + 1.10 +enum { 1.11 + LOG_INFO = 1, 1.12 + LOG_WARNING = 2, 1.13 + LOG_ERROR = 4, 1.14 + LOG_DEBUG = 8 1.15 +}; 1.16 + 1.17 +#ifdef __cplusplus 1.18 +extern "C" { 1.19 +#endif 1.20 + 1.21 +/* Clear log outputs. Initially info/debug messages go to stdout, and 1.22 + * warning/error messages to stderr. 1.23 + */ 1.24 +void log_clear_targets(void); 1.25 + 1.26 +/* set logging outputs for any combination of message types. 1.27 + * type_mask expects a bitmask. 1.28 + */ 1.29 +int log_add_stream(unsigned int type_mask, FILE *fp); 1.30 +int log_add_file(unsigned int type_mask, const char *fname); 1.31 +int log_add_func(unsigned int type_mask, void (*func)(const char*, void*), void *cls); 1.32 + 1.33 +void log_msg(unsigned int type, const char *fmt, ...); 1.34 +/* log_msg helpers */ 1.35 +void log_info(const char *fmt, ...); 1.36 +void log_warning(const char *fmt, ...); 1.37 +void log_error(const char *fmt, ...); 1.38 +void log_debug(const char *fmt, ...); 1.39 + 1.40 +void log_va_msg(unsigned int type, const char *fmt, va_list va); 1.41 +/* log_va_msg helpers */ 1.42 +void log_va_info(const char *fmt, va_list ap); 1.43 +void log_va_warning(const char *fmt, va_list ap); 1.44 +void log_va_error(const char *fmt, va_list ap); 1.45 +void log_va_debug(const char *fmt, va_list ap); 1.46 + 1.47 +/* Intercept stdout/stderr and handle them through the logger. stdout as an 1.48 + * info log, and stderr as an error log. This only works on UNIX. 1.49 + */ 1.50 +void log_grab_stdout(void); 1.51 +void log_grab_stderr(void); 1.52 + 1.53 +#ifdef __cplusplus 1.54 +} 1.55 +#endif 1.56 + 1.57 +#endif /* LOGGER_H_ */