Mercurial > hg > fxanalyse
view logging.c @ 182:4d1f9e222e9e
Update default configuration file
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Fri, 21 Feb 2014 18:42:29 +0100 |
parents | 97112b45b838 |
children | 0fed60877099 |
line wrap: on
line source
#include <ansi_c.h> #include "logging.h" /* this refers to the event time defined as a global variable in the main program */ extern double utc; int __logger_init(struct logger *l) { int panel = LoadPanel(0, "FXAnalyse.uir", LOGGING); if (panel < 0) return -1; l->panel = panel; return 0; } void __logmessage(struct logger *l, enum loglevel level, const char *frmt, ...) { static const char levels[][16] = { "DEBUG", "INFO", "WARNING", "ERROR", }; char msg[1024]; int len = 0; // timestamp len += sprintf(msg, "%014.3f ", utc); time_t now = time(NULL); struct tm *t = localtime(&now); len += strftime(msg + len, sizeof(msg) - len, "%d-%m-%Y %H:%M:%S ", t); // level len += snprintf(msg + len, sizeof(msg) - len, "%s: ", levels[level]); // message va_list args; va_start(args, frmt); len += vsnprintf(msg + len, sizeof(msg) - len, frmt, args); va_end(args); // add newline len = MIN(len, sizeof(msg) - 2); msg[len] = '\n'; msg[len + 1] = '\0'; // display message SetCtrlVal(l->panel, LOGGING_LOGGING, msg); }