Skip to content

Commit

Permalink
Added mce_log_p() predicate
Browse files Browse the repository at this point in the history
For testing whether - say LL_DEBUG - logging is enabled before spending
cpu cycles for constructing parameters that mce_log() call might ignore
due to logging level settings.
  • Loading branch information
spiiroin committed Dec 7, 2012
1 parent 2fc838b commit 1b394f5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions mce-log.c
Expand Up @@ -139,4 +139,20 @@ void mce_log_close(void)
if (logtype == MCE_LOG_SYSLOG)
closelog();
}

/**
* Log level testing predicate
*
* For testing whether given level of logging is allowed
* before spending cpu time for gathering parameters etc
*
* @param loglevel level of logging we might do
*
* @return 1 if logging at givel level is enabled, 0 if not
*/
int mce_log_p(const loglevel_t loglevel)
{
return logverbosity >= loglevel;
}

#endif /* OSSOLOG_COMPILE */
3 changes: 3 additions & 0 deletions mce-log.h
Expand Up @@ -46,6 +46,7 @@ void mce_log_file(const loglevel_t loglevel, const char *const file,
void mce_log_set_verbosity(const int verbosity);
void mce_log_open(const char *const name, const int facility, const int type);
void mce_log_close(void);
int mce_log_p(const loglevel_t loglevel);
#else
/** Dummy version used when logging is disabled at compile time */
#define mce_log(_loglevel, _fmt, ...) do {} while (0)
Expand All @@ -55,6 +56,8 @@ void mce_log_close(void);
#define mce_log_open(_name, _facility, _type) do {} while (0)
/** Dummy version used when logging is disabled at compile time */
#define mce_log_close() do {} while (0)
/** Dummy version used when logging is disabled at compile time */
#define mce_log_p(_loglevel) 0
#endif /* OSSOLOG_COMPILE */

#endif /* _MCE_LOG_H_ */

0 comments on commit 1b394f5

Please sign in to comment.