mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-28 14:30:09 +01:00
logging: introduce an alternative set of logging macros
We already have the macros _LOGD(), _LOGI(), etc. to provide context sensitive
logging (such as printing the object pointer as prefix).
In some implementations, we would like to have a second set of logging
macros, that shall be used differently. For example, use the default
_LOGD() for messages that are explicitly issued by one objects, and use
_LOG2D() in a static context when no object is around.
The "_LOG2" prefix is not great from a naming point of view. However, it is
meant to be a second (alternative) set of logging macros with the same
usage pattern as the _LOGD() macros.
(cherry picked from commit ed5ebf7e74)
This commit is contained in:
parent
4297db4f4c
commit
1bfd5b098d
1 changed files with 33 additions and 1 deletions
|
|
@ -191,11 +191,43 @@ void nm_logging_syslog_closelog (void);
|
|||
#define _LOGt_ENABLED(...) _NMLOG_ENABLED (LOGL_TRACE, ##__VA_ARGS__)
|
||||
#define _LOGt(...) _NMLOG (LOGL_TRACE, __VA_ARGS__)
|
||||
#else
|
||||
/* still call the logging macros to get compile time checks, but they will be optimize out. */
|
||||
/* still call the logging macros to get compile time checks, but they will be optimized out. */
|
||||
#define _LOGt_ENABLED(...) ( FALSE && (_NMLOG_ENABLED (LOGL_TRACE, ##__VA_ARGS__)) )
|
||||
#define _LOGt(...) G_STMT_START { if (FALSE) { _NMLOG (LOGL_TRACE, __VA_ARGS__); } } G_STMT_END
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* Some implementation define a second set of logging macros, for a separate
|
||||
* use. As with the _LOGD() macro familiy above, the exact implementation
|
||||
* depends on the file that uses them.
|
||||
* Still, it encourages a common pattern to have the common set of macros
|
||||
* like _LOG2D(), _LOG2I(), etc. and have _LOG2t() which by default
|
||||
* is disabled at compile time. */
|
||||
|
||||
#define _NMLOG2_ENABLED(level) ( nm_logging_enabled ((level), (_NMLOG2_DOMAIN)) )
|
||||
|
||||
#define _LOG2T(...) _NMLOG2 (LOGL_TRACE, __VA_ARGS__)
|
||||
#define _LOG2D(...) _NMLOG2 (LOGL_DEBUG, __VA_ARGS__)
|
||||
#define _LOG2I(...) _NMLOG2 (LOGL_INFO , __VA_ARGS__)
|
||||
#define _LOG2W(...) _NMLOG2 (LOGL_WARN , __VA_ARGS__)
|
||||
#define _LOG2E(...) _NMLOG2 (LOGL_ERR , __VA_ARGS__)
|
||||
|
||||
#define _LOG2T_ENABLED(...) _NMLOG2_ENABLED (LOGL_TRACE, ##__VA_ARGS__)
|
||||
#define _LOG2D_ENABLED(...) _NMLOG2_ENABLED (LOGL_DEBUG, ##__VA_ARGS__)
|
||||
#define _LOG2I_ENABLED(...) _NMLOG2_ENABLED (LOGL_INFO , ##__VA_ARGS__)
|
||||
#define _LOG2W_ENABLED(...) _NMLOG2_ENABLED (LOGL_WARN , ##__VA_ARGS__)
|
||||
#define _LOG2E_ENABLED(...) _NMLOG2_ENABLED (LOGL_ERR , ##__VA_ARGS__)
|
||||
|
||||
#ifdef NM_MORE_LOGGING
|
||||
#define _LOG2t_ENABLED(...) _NMLOG2_ENABLED (LOGL_TRACE, ##__VA_ARGS__)
|
||||
#define _LOG2t(...) _NMLOG2 (LOGL_TRACE, __VA_ARGS__)
|
||||
#else
|
||||
/* still call the logging macros to get compile time checks, but they will be optimized out. */
|
||||
#define _LOG2t_ENABLED(...) ( FALSE && (_NMLOG2_ENABLED (LOGL_TRACE, ##__VA_ARGS__)) )
|
||||
#define _LOG2t(...) G_STMT_START { if (FALSE) { _NMLOG2 (LOGL_TRACE, __VA_ARGS__); } } G_STMT_END
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#endif /* __NETWORKMANAGER_LOGGING_H__ */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue