4 #include <glib-object.h>
7 #include <cstdarg> /* for va_list */
9 #include <stdarg.h> /* for va_list */
14 #define LOGGER_TYPE (logger_get_type ())
15 #define LOGGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOGGER_TYPE, Logger))
16 #define IS_LOGGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOGGER_TYPE))
17 #define LOGGER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), LOGGER_TYPE, LoggerInterface))
19 typedef struct Logger Logger;
22 GTypeInterface parent;
24 gint (*logprefix) (Logger *self, gchar *buf, gulong buflen);
25 void (*logv) (Logger *self, GLogLevelFlags log_level, const gchar *format, va_list ap);
28 GType logger_get_type (void);
31 * \brief instruct \c self to generate a log message prefix
33 * the semantics of the \c buf and \c buflen arguments and the return
34 * value are the same as g_snprintf()
36 * there is no default implementation
38 gint logger_logprefix (Logger *self, gchar *buf, gulong buflen);
41 * \brief instruct \c self to log the given message
43 * the default implementation prefixes the log message with the
44 * output of logger_logprefix() and then passes the result to
47 void logger_logv (Logger *self, GLogLevelFlags log_level, const gchar *format, va_list ap) __attribute__ ((format (printf, 3, 0)));
49 /*! \brief convenience wrapper around \c logger_logv() */
50 void logger_log (Logger *self, GLogLevelFlags log_level, const gchar *format, ...) __attribute__ ((format (printf, 3, 4)));
52 /* convenience wrappers around logger_log() */
53 #define l_debug(self, ...) \
54 logger_log (LOGGER (self), G_LOG_LEVEL_DEBUG, __VA_ARGS__)
55 #define l_warning(self, ...) \
56 logger_log (LOGGER (self), G_LOG_LEVEL_WARNING, __VA_ARGS__)
60 #endif /* !LOGGER_H_ */