]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - src/logger.h
Load all users only when really needed
[sojka/lightdm.git] / src / logger.h
1 #ifndef LOGGER_H_
2 #define LOGGER_H_
3
4 #include <glib-object.h>
5
6 #ifdef __cplusplus
7 #include <cstdarg>  /* for va_list */
8 #else
9 #include <stdarg.h>  /* for va_list */
10 #endif
11
12 G_BEGIN_DECLS
13
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))
18
19 typedef struct Logger Logger;
20
21 typedef struct {
22     GTypeInterface parent;
23
24     gint (*logprefix) (Logger *self, gchar *buf, gulong buflen);
25     void (*logv) (Logger *self, GLogLevelFlags log_level, const gchar *format, va_list ap);
26 } LoggerInterface;
27
28 GType logger_get_type (void);
29
30 /*!
31  * \brief instruct \c self to generate a log message prefix
32  *
33  * the semantics of the \c buf and \c buflen arguments and the return
34  * value are the same as g_snprintf()
35  *
36  * there is no default implementation
37  */
38 gint logger_logprefix (Logger *self, gchar *buf, gulong buflen);
39
40 /*!
41  * \brief instruct \c self to log the given message
42  *
43  * the default implementation prefixes the log message with the
44  * output of logger_logprefix() and then passes the result to
45  * g_log()
46  */
47 void logger_logv (Logger *self, GLogLevelFlags log_level, const gchar *format, va_list ap) __attribute__ ((format (printf, 3, 0)));
48
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)));
51
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__)
57
58 G_END_DECLS
59
60 #endif /* !LOGGER_H_ */