Commit da644535 authored by Lucas Russo's avatar Lucas Russo

libs/liberrhand/*: change HALT bit semantics to SIMPLE printing

This HALT bit was unused. So, we cahnged its meaning
to "print without prefix/headers", which is useful
for more complex printing, like SDB records.
parent fc69d2f5
......@@ -49,7 +49,7 @@ void errhand_log_print_zmq_msg (struct _zmsg_t *msg);
/* dbg has the following format:
* 31 - 4 3 - 1 0-0
* ERRHAND_SUBSYS ERRHAND_LVL ERRHAND_HALT
* ERRHAND_SUBSYS ERRHAND_LVL ERRHAND_SIMPLE
*/
#ifdef ERRHAND_DBG
......@@ -59,12 +59,8 @@ void errhand_log_print_zmq_msg (struct _zmsg_t *msg);
if (((dbg) & ERRHAND_SUBSYS_ON) && \
(((dbg) & ERRHAND_LVL_MASK) >= \
ERRHAND_MIN_LEVEL)) { \
errhand_log_print((dbg) & ERRHAND_LVL_MASK, \
errhand_log_print((dbg) & ERRHAND_LVL_SIMPLE_MASK, \
fmt, ## __VA_ARGS__); \
\
if ((dbg) & ERRHAND_LVL_HALT) { \
while(1); \
} \
} \
} while(0)
......@@ -74,9 +70,6 @@ void errhand_log_print_zmq_msg (struct _zmsg_t *msg);
(((dbg) & ERRHAND_LVL_MASK) >= \
ERRHAND_MIN_LEVEL)) { \
errhand_print_vec(fmt, data, len); \
\
if ((dbg) & ERRHAND_LVL_HALT) \
while(1); \
} \
} while(0)
......
......@@ -112,31 +112,46 @@ extern "C" {
extern const char *errhand_lvl_str [ERRHAND_LVL_NUM];
char *errhand_lvl_to_str (int errhand_lvl);
/****************** Debug halt macros ******************/
/****************** Debug simple macros ******************/
/*
* ERRHAND_HALT variable is binary encoded in bit 0:
* ERRHAND_SIMPLE variable is binary encoded in bit 0:
* bit 31 ... bit 4 bit 3 ... bit 1 bit 0
* X X X X [1|0]
*/
/* Debug halt */
#define ERRHAND_HALT_SHIFT 0
#define ERRHAND_HALT_MAX 1
#define ERRHAND_HALT_MASK_RAW ((1 << ERRHAND_HALT_SHIFT)-1)
#define ERRHAND_HALT_MASK (ERRHAND_HALT_MASK_RAW << ERRHAND_HALT_SHIFT)
/* This bits sets the simple mode for writing without headers/prefix,
* just plain text */
/* 1 halt signal */
#define ERRHAND_HALT_GEN(val) ((val & ERRHAND_HALT_MASK_RAW) << ERRHAND_HALT_SHIFT)
#define ERRHAND_HALT_DEGEN(val) ((val & ERRHAND_HALT_MASK) >> ERRHAND_HALT_SHIFT)
/* Debug simple */
#define ERRHAND_SIMPLE_SHIFT 0
#define ERRHAND_SIMPLE_MAX 1
#define ERRHAND_SIMPLE_MASK_RAW ((1 << ERRHAND_SIMPLE_MAX)-1)
#define ERRHAND_SIMPLE_MASK (ERRHAND_SIMPLE_MASK_RAW << ERRHAND_SIMPLE_SHIFT)
/* Debug halt raw */
#define ERRHAND_LVL_HALT_RAW 0x1
/* 1 simple signal */
#define ERRHAND_SIMPLE_GEN(val) ((val & ERRHAND_SIMPLE_MASK_RAW) << ERRHAND_SIMPLE_SHIFT)
#define ERRHAND_SIMPLE_DEGEN(val) ((val & ERRHAND_SIMPLE_MASK) >> ERRHAND_SIMPLE_SHIFT)
/* Debug halt mask'ed and shift'ed */
#define ERRHAND_LVL_HALT ERRHAND_HALT_GEN(ERRHAND_LVL_HALT_RAW)
/* Debug simple raw */
#define ERRHAND_LVL_SIMPLE_RAW 0x1
/* Debug simple mask'ed and shift'ed */
#define ERRHAND_LVL_SIMPLE ERRHAND_SIMPLE_GEN(ERRHAND_LVL_SIMPLE_RAW)
/* For compatibility */
#define DBG_LVL_HALT ERRHAND_LVL_HALT
#define DBG_LVL_SIMPLE ERRHAND_LVL_SIMPLE
/****************** Debug levels + simple macros ******************/
/* Debug simple */
#define ERRHAND_LVL_SIMPLE_SHIFT 0
#define ERRHAND_LVL_SIMPLE_MAX 4
#define ERRHAND_LVL_SIMPLE_MASK_RAW ((1 << ERRHAND_LVL_SIMPLE_MAX)-1)
#define ERRHAND_LVL_SIMPLE_MASK (ERRHAND_LVL_SIMPLE_MASK_RAW << ERRHAND_LVL_SIMPLE_SHIFT)
/* 1 simple signal */
#define ERRHAND_LVL_SIMPLE_GEN(val) ((val & ERRHAND_LVL_SIMPLE_MASK_RAW) << ERRHAND_LVL_SIMPLE_SHIFT)
#define ERRHAND_LVL_SIMPLE_DEGEN(val) ((val & ERRHAND_LVL_SIMPLE_MASK) >> ERRHAND_LVL_SIMPLE_SHIFT)
#ifdef __cplusplus
}
......
......@@ -8,6 +8,8 @@
#include "errhand.h"
#define ERRHAND_PRINT_PAD_FMT "-5"
#define ERRHAND_DATE_LENGTH 20
#define ERRHAND_TEXT_LENGTH 1024
/* Our logfile */
static FILE *_errhand_logfile = NULL;
......@@ -23,7 +25,7 @@ void errhand_print (const char *fmt, ...)
/* Based on CZMQ s_log () function. Available in
* https://github.com/zeromq/czmq/blob/master/src/zsys.c */
static void _errhand_log_write (char *errhand_lvl_str, char *msg)
static void _errhand_log_write (char *errhand_lvl_str, char *msg, bool verbose)
{
/* Default to stdout */
if (!_errhand_logfile) {
......@@ -32,13 +34,18 @@ static void _errhand_log_write (char *errhand_lvl_str, char *msg)
time_t curtime = time (NULL);
struct tm *loctime = localtime (&curtime);
char date [20];
char date [ERRHAND_DATE_LENGTH];
char log_text [ERRHAND_TEXT_LENGTH];
strftime (date, 20, "%y-%m-%d %H:%M:%S", loctime);
if (verbose) {
strftime (date, ERRHAND_DATE_LENGTH, "%y-%m-%d %H:%M:%S", loctime);
snprintf (log_text, ERRHAND_TEXT_LENGTH, "%" ERRHAND_PRINT_PAD_FMT "s: [%s] %s",
errhand_lvl_str, date, msg);
}
else {
snprintf (log_text, ERRHAND_TEXT_LENGTH, "%s", msg);
}
char log_text [1024];
snprintf (log_text, 1024, "%" ERRHAND_PRINT_PAD_FMT "s: [%s] %s",
errhand_lvl_str, date, msg);
fprintf (_errhand_logfile, "%s", log_text);
fflush (_errhand_logfile);
}
......@@ -52,9 +59,12 @@ void errhand_log_print (int errhand_lvl, const char *fmt, ...)
char *msg = errhand_lprint_vprintf (fmt, argptr);
va_end (argptr);
/* Check if we opted for the simple print (i.e., no warning level and date) */
bool verbose = !(ERRHAND_SIMPLE_DEGEN(errhand_lvl) & ERRHAND_LVL_SIMPLE_RAW);
/* Convert errhand level code to string */
char *errhand_lvl_str = errhand_lvl_to_str (errhand_lvl);
_errhand_log_write (errhand_lvl_str, msg);
_errhand_log_write (errhand_lvl_str, msg, verbose);
free (msg);
free (errhand_lvl_str);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment