Mercurial > hg > fxanalyse
diff logging.c @ 169:97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Fri, 14 Feb 2014 16:58:19 +0100 |
parents | |
children | 0fed60877099 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/logging.c Fri Feb 14 16:58:19 2014 +0100 @@ -0,0 +1,53 @@ +#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); +}