[PATCH btbridge] Add timestamps to output messages
OpenBMC Patches
openbmc-patches at stwcx.xyz
Wed Dec 9 10:00:08 AEDT 2015
From: Cyril Bur <cyril.bur at au1.ibm.com>
---
btbridged.c | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/btbridged.c b/btbridged.c
index 115ae63..2fd1e4f 100644
--- a/btbridged.c
+++ b/btbridged.c
@@ -35,7 +35,7 @@
#include <systemd/sd-bus.h>
-#define PREFIX "[BTBRIDGED] "
+#define PREFIX "BTBRIDGED"
#define BT_HOST_PATH "/dev/bt-host"
#define BT_HOST_TIMEOUT_SEC 1
@@ -49,13 +49,8 @@
#define TIMER_FD 2
#define TOTAL_FDS 3
-#define MSG_OUT(f_, ...) do { if (verbose) { printf(PREFIX); printf((f_), ##__VA_ARGS__); } } while(0)
-#define MSG_ERR(f_, ...) do { \
- if (verbose) { \
- fprintf(stderr, PREFIX); \
- fprintf(stderr, (f_), ##__VA_ARGS__); \
- } \
- } while(0)
+#define MSG_OUT(f_, ...) do { if (verbose) { log(stdout, f_, ##__VA_ARGS__); } } while(0)
+#define MSG_ERR(f_, ...) do { if (verbose) { log(stderr, f_, ##__VA_ARGS__); } } while(0)
struct ipmi_msg {
uint8_t netfn;
@@ -86,6 +81,22 @@ static int running = 1;
static int verbose;
static int debug;
+__attribute__((format(printf, 2, 3)))
+static void log(FILE *s, const char *fmt, ...)
+{
+ va_list args;
+ struct timespec time;
+
+ clock_gettime(CLOCK_REALTIME, &time);
+
+ fprintf(s, "[%s %ld.%ld] ", PREFIX, time.tv_sec, time.tv_nsec);
+
+ va_start(args, fmt);
+ vfprintf(s, fmt, args);
+ va_end(args);
+
+}
+
static struct bt_queue *bt_q_get_head(struct btbridged_context *context)
{
return context ? context->bt_q : NULL;
--
2.6.3
More information about the openbmc
mailing list