Skip to content

Commit

Permalink
[logging] Add LL_CRUCIAL logging priority. JB#36274
Browse files Browse the repository at this point in the history
Now and then there are issues that can't be easily diagnosed without
logging and the causes might be rare enough that manually enabling
extra logging after hitting the problem does not accomplish anything.

Provide separate logging priority that is easy to spot and demote
from mce code base once some specific issue has been found and fixed.
  • Loading branch information
spiiroin committed Oct 11, 2016
1 parent 5e7c854 commit 9671594
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
37 changes: 26 additions & 11 deletions mce-log.c
Expand Up @@ -78,13 +78,13 @@ static void timestamp(struct timeval *tv)
*
* @return log level clipped to LL_CRIT ... LL_DEBUG range
*/
static loglevel_t mce_log_level_normalize(loglevel_t loglevel)
static loglevel_t mce_log_level_clip(loglevel_t loglevel)
{
if( loglevel < LL_EXTRA ) {
loglevel = LL_EXTRA;
if( loglevel <= LL_MINIMUM ) {
loglevel = LL_MINIMUM;
}
else if( loglevel > LL_DEBUG ) {
loglevel = LL_DEBUG;
else if( loglevel > LL_MAXIMUM ) {
loglevel = LL_MAXIMUM;
}
return loglevel;
}
Expand All @@ -99,6 +99,7 @@ static const char *mce_log_level_tag(loglevel_t loglevel)
{
const char *res = "?";
switch( loglevel ) {
case LL_CRUCIAL:res = "T"; break;
case LL_EXTRA: res = "X"; break;
case LL_CRIT: res = "C"; break;
case LL_ERR: res = "E"; break;
Expand Down Expand Up @@ -169,7 +170,7 @@ void mce_log_file(loglevel_t loglevel, const char *const file,
{
va_list args;

loglevel = mce_log_level_normalize(loglevel);
loglevel = mce_log_level_clip(loglevel);

if( mce_log_p_(loglevel, file, function) ) {
gchar *msg = 0;
Expand All @@ -193,9 +194,16 @@ void mce_log_file(loglevel_t loglevel, const char *const file,
mce_log_level_tag(loglevel),
msg);
} else {
/* LL_EXTRA = devel flavor notice */
if( loglevel == LL_EXTRA )
/* Use NOTICE priority when reporting LL_EXTRA
* and LL_CRUCIAL logging */
switch( loglevel ) {
case LL_EXTRA:
case LL_CRUCIAL:
loglevel = LL_NOTICE;
break;
default:
break;
}

/* loglevels are subset of syslog priorities, so
* we can use loglevel as is for syslog priority */
Expand Down Expand Up @@ -310,7 +318,7 @@ static bool mce_log_check_pattern(const char *func)
*
* @return 1 if logging at givel level is enabled, 0 if not
*/
int mce_log_p_(const loglevel_t loglevel,
int mce_log_p_(loglevel_t loglevel,
const char *const file,
const char *const func)
{
Expand All @@ -321,8 +329,15 @@ int mce_log_p_(const loglevel_t loglevel,
return true;
}

if( loglevel < LL_EXTRA )
return logverbosity >= LL_NOTICE;
/* LL_EXTRA & LL_CRUCIAL are evaluated as WARNING level */
switch( loglevel ) {
case LL_EXTRA:
case LL_CRUCIAL:
loglevel = LL_WARN;;
break;
default:
break;
}

return logverbosity >= loglevel;
}
Expand Down
6 changes: 5 additions & 1 deletion mce-log.h
Expand Up @@ -48,14 +48,18 @@ typedef enum {
LL_MAXIMUM = LOG_DEBUG, /**< Minimum for bounds checking */
LL_MINIMUM = LOG_EMERG, /**< Maximum for bounds checking */

LL_CRUCIAL = LOG_EMERG, /**< Elevated priority for solving
* problems that require logs from
* the whole user base. Should be
* downgraded as soon as possible. */
} loglevel_t;

# ifdef OSSOLOG_COMPILE
void mce_log_add_pattern(const char *pat);
void mce_log_set_verbosity(int verbosity);
int mce_log_get_verbosity(void);

int mce_log_p_(const loglevel_t loglevel,
int mce_log_p_(loglevel_t loglevel,
const char *const file, const char *const function);

void mce_log_file(loglevel_t loglevel, const char *const file,
Expand Down

0 comments on commit 9671594

Please sign in to comment.