#ifndef _SK_LOG_H #define _SK_LOG_H #include "util/font.h" /* types */ enum sk_log_level { SK_LOG_ERROR = 1, SK_LOG_WARN, SK_LOG_INFO, SK_LOG_DEBUG, SK_LOG_TRACE, SK_LOG_MIN = SK_LOG_ERROR, SK_LOG_MAX = SK_LOG_TRACE }; typedef enum sk_log_level sk_log_level; typedef const char * sk_font_map[SK_LOG_MAX+1]; /* font maps */ extern sk_font_map _SK_LOG_COLOURED; extern sk_font_map _SK_LOG_MONOCHROME; #define SK_LOG_COLOURED &_SK_LOG_COLOURED #define SK_LOG_MONOCHROME &_SK_LOG_MONOCHROME /* type conversion functions */ /** * sk_log_level_to_string: * converts an sk_log_level to its string representation. * * @param level: the log level * @return the string representation of level. */ const char *sk_log_level_to_string(sk_log_level level); /** * sk_log_level_of_string: * converts a string representation to its sk_log_level. * * s is compared case-insensitively. * In case an invalid string representation is given, * 0 is returned. * * @param s: the string representation of the log level * @return sk_log_level */ sk_log_level sk_log_level_of_string(const char *s); /* getters/setters for global state variables */ /** * sk_log_level_get: * returns the current minimum log level to be logged. * * @return the log level */ sk_log_level sk_log_level_get(); /** * sk_log_level_set: * sets a new minimum log level to be logged. * * @param new: the new minimum log level. */ void sk_log_level_set(sk_log_level new); /** * sk_log_font_get: * get the current logging font map. * * @return the current logging font map */ sk_font_map *sk_log_font_get(); /** * sk_log_font_set: * sets a new logging font map. * * @param font: the new logging font map. */ void sk_log_font_set(sk_font_map *restrict font); /* logging functions */ /** * sk_log: * a generic logging function accepting the log level as a function argument. * * The message given using a format and format arguments will be formatted using * a standard format and a new line will be appended. * * @param level: the log level of this message. * @param format: the message as a format string, cf. printf(3). * @param varg: format arguments if needed. * @return the number of bytes logged (0 if no message was logged due to * "insufficient" log level, and a negative number if an error occurred) */ int sk_log(sk_log_level level, const char *restrict format, ...); /** * sk_error: * log an error message. * * cf. sk_log(). */ #define sk_error(...) sk_log(SK_LOG_ERROR, __VA_ARGS__) /** * sk_warn: * log a warning message. * * cf. sk_log(). */ #define sk_warn(...) sk_log(SK_LOG_WARN, __VA_ARGS__) /** * sk_info: * log an informational message. * * cf. sk_log(). */ #define sk_info(...) sk_log(SK_LOG_INFO, __VA_ARGS__) /** * sk_debug: * log a debug message. * * cf. sk_log(). */ #define sk_debug(...) sk_log(SK_LOG_DEBUG, __VA_ARGS__) /** * sk_trace: * log a trace message. * * cf. sk_log(). */ #define sk_trace(...) sk_log(SK_LOG_TRACE, __VA_ARGS__) #endif