comparison 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
comparison
equal deleted inserted replaced
168:4de7f2c9f328 169:97112b45b838
1 #include <ansi_c.h>
2
3 #include "logging.h"
4
5 /* this refers to the event time defined as a global variable in the main program */
6 extern double utc;
7
8
9 int __logger_init(struct logger *l)
10 {
11 int panel = LoadPanel(0, "FXAnalyse.uir", LOGGING);
12 if (panel < 0)
13 return -1;
14 l->panel = panel;
15 return 0;
16 }
17
18
19 void __logmessage(struct logger *l, enum loglevel level, const char *frmt, ...)
20 {
21 static const char levels[][16] = {
22 "DEBUG",
23 "INFO",
24 "WARNING",
25 "ERROR",
26 };
27
28 char msg[1024];
29 int len = 0;
30
31 // timestamp
32 len += sprintf(msg, "%014.3f ", utc);
33 time_t now = time(NULL);
34 struct tm *t = localtime(&now);
35 len += strftime(msg + len, sizeof(msg) - len, "%d-%m-%Y %H:%M:%S ", t);
36
37 // level
38 len += snprintf(msg + len, sizeof(msg) - len, "%s: ", levels[level]);
39
40 // message
41 va_list args;
42 va_start(args, frmt);
43 len += vsnprintf(msg + len, sizeof(msg) - len, frmt, args);
44 va_end(args);
45
46 // add newline
47 len = MIN(len, sizeof(msg) - 2);
48 msg[len] = '\n';
49 msg[len + 1] = '\0';
50
51 // display message
52 SetCtrlVal(l->panel, LOGGING_LOGGING, msg);
53 }