Re: Logging functions



> is there a reason why there are the functions
>    g_error
>    g_critical
>    g_warning
>    g_message
> but not
>    g_info
>    g_debug
> ?

I've been wondering about the same thing.


> #define g_info(...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, 
__VA_ARGS__)
> 
> #ifdef G_DEBUG
> #define g_debug(...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, 
__VA_ARGS__)
> #else
> #define g_debug(...)
> #endif

Here's what I use to extend GLib:

#ifdef NDEBUG
# define debug(msg)
# define debugf(fmt, args...)
#else
# ifdef __GNUC__
#  define debug(msg) \
        g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s:%d %s: " msg, 
\
              __FILE__, __LINE__, __PRETTY_FUNCTION__)
#  define debugf(fmt, args...) \
        g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s:%d %s: " fmt, 
\
              __FILE__, __LINE__, __PRETTY_FUNCTION__, ##args)
# else
#  define debug(msg) \
        g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s:%d: " msg, \
              __FILE__, __LINE__)
#  define debugf(fmt, args...) \
        g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s:%d: " fmt, \
              __FILE__, __LINE__, ##args)
# endif
#endif

Tell me how I can merge the debug(msg) and debugf(fmt, args...) 
macros. :)


Timo Savola






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]