annotate logging.c @ 270:a451d4618dbf

Simplify code moving the update of the DDS frequency display to the wrappers
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Fri, 10 Jul 2015 15:21:15 +0200
parents 3622e24a443f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
1 #include <ansi_c.h>
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
2 #include <inifile.h>
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
3 #include <lowlvlio.h>
229
28a56e4c06a4 Improvements to log file handling
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 199
diff changeset
4 #include <ansi_c.h>
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
5
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
6 #include "config.h"
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
7 #include "logging.h"
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
8
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
9 /* this refers to the event time defined as a global variable in the main program */
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
10 extern double utc;
199
111610d871af Show error state in main user inteface panel
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 191
diff changeset
11 /* main panel id */
111610d871af Show error state in main user inteface panel
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 191
diff changeset
12 extern unsigned int MainPanel;
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
13
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
14
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
15 struct logger {
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
16 unsigned int panel;
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
17 char *dirpath;
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
18 char *filepath;
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
19 int fd;
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
20 int level;
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
21 int yday;
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
22 void(*onerror)(int, const char *);
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
23 };
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
24
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
25
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
26 static const char *levels[] = {
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
27 [ERROR] = "ERROR",
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
28 [WARNING] = "WARNING",
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
29 [INFO] = "INFO",
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
30 [DEBUG] = "DEBUG",
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
31 };
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
32
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
33
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
34 static inline int strtolevel(const char *str)
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
35 {
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
36 for (int i = 0; i < 4; i++) {
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
37 if (streq(levels[i], str))
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
38 return i;
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
39 }
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
40 return DEBUG;
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
41 }
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
42
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
43
260
3622e24a443f Also rotate log file at midnight UTC not local time
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 252
diff changeset
44 static int rotate(struct logger *l, time_t now)
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
45 {
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
46 int len, rv;
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
47 char id[7];
260
3622e24a443f Also rotate log file at midnight UTC not local time
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 252
diff changeset
48 struct tm *t;
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
49
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
50 if (! l->dirpath)
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
51 return 0;
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
52
260
3622e24a443f Also rotate log file at midnight UTC not local time
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 252
diff changeset
53 /* utc day */
3622e24a443f Also rotate log file at midnight UTC not local time
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 252
diff changeset
54 t = gmtime(&now);
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
55 if (l->yday == t->tm_yday)
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
56 return 0;
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
57
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
58 /* close old file descriptor */
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
59 close(l->fd);
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
60 l->fd = -1;
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
61
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
62 /* construct new file name */
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
63 strftime(id, sizeof(id), "%y%m%d", t);
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
64 len = strlen(l->dirpath) + 1 + sizeof(id) + strlen("-Log.txt") + 1;
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
65 l->filepath = malloc(len);
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
66 snprintf(l->filepath, len, "%s\\%s-Log.txt", l->dirpath, id);
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
67
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
68 /* open new log file */
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
69 rv = open(l->filepath, O_CREAT|O_WRONLY|O_APPEND, 00744);
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
70 if (rv < 0)
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
71 return rv;
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
72
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
73 /* update status */
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
74 l->fd = rv;
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
75 l->yday = t->tm_yday;
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
76 __logmessage(l, DEBUG, "logging to '%s'", l->filepath);
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
77
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
78 return 1;
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
79 }
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
80
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
81
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
82 struct logger * __logger_init(void(*onerror)(int, const char *))
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
83 {
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
84 int rv, panel;
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
85 char path[MAX_PATHNAME_LEN], *str;
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
86
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
87 struct logger *l = malloc(sizeof(struct logger));
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
88 memset(l, 0, sizeof(*l));
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
89
199
111610d871af Show error state in main user inteface panel
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 191
diff changeset
90 l->onerror = onerror;
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
91 l->fd = -1;
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
92 l->level = DEBUG;
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
93
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
94 panel = LoadPanel(0, "FXAnalyse.uir", LOGGING);
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
95 if (panel < 0)
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
96 return NULL;
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
97 l->panel = panel;
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
98
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
99 /* configuration file path */
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
100 GetIniFilePath(path);
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
101
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
102 /* load configuration file */
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
103 IniText configuration = Ini_New(TRUE);
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
104 Ini_ReadFromFile(configuration, path);
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
105
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
106 /* logging folder path */
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
107 rv = Ini_GetStringCopy(configuration, "logging", "folder", &l->dirpath);
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
108
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
109 /* logging level */
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
110 rv = Ini_GetStringCopy(configuration, "logging", "level", &str);
229
28a56e4c06a4 Improvements to log file handling
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 199
diff changeset
111 if (rv > 0) {
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
112 l->level = strtolevel(str);
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
113 free(str);
229
28a56e4c06a4 Improvements to log file handling
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 199
diff changeset
114 }
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
115
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
116 Ini_Dispose(configuration);
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
117
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
118 return l;
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
119 }
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
120
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
121
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
122 void __logmessage(struct logger *l, enum loglevel level, const char *frmt, ...)
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
123 {
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
124 char msg[1024];
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
125 int len = 0;
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
126
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
127 /* timestamp */
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
128 len += sprintf(msg, "%014.3f ", utc);
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
129 time_t now = (time_t)utc;
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
130 if (now == 0)
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
131 now = time(NULL);
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
132 struct tm *t = localtime(&now);
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
133 len += strftime(msg + len, sizeof(msg) - len, "%d-%m-%Y %H:%M:%S ", t);
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
134
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
135 /* level */
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
136 len += snprintf(msg + len, sizeof(msg) - len, "%s: ", levels[level]);
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
137
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
138 /* message */
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
139 va_list args;
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
140 va_start(args, frmt);
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
141 len += vsnprintf(msg + len, sizeof(msg) - len, frmt, args);
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
142 va_end(args);
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
143
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
144 /* newline */
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
145 len = MIN(len, sizeof(msg) - 3);
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
146 msg[len++] = '\r';
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
147 msg[len++] = '\n';
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
148
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
149 /* string terminator */
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
150 msg[len] = '\0';
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
151
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
152 /* rotate log file based on current date */
260
3622e24a443f Also rotate log file at midnight UTC not local time
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 252
diff changeset
153 rotate(l, now);
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
154
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
155 /* write to log file */
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
156 if ((level <= l->level) && (l->fd >= 0))
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
157 write(l->fd, msg, len);
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
158
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
159 /* display message */
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
160 SetCtrlVal(l->panel, LOGGING_LOGGING, msg);
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
161
199
111610d871af Show error state in main user inteface panel
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 191
diff changeset
162 /* report error */
111610d871af Show error state in main user inteface panel
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 191
diff changeset
163 if (level == ERROR)
111610d871af Show error state in main user inteface panel
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 191
diff changeset
164 l->onerror(level, msg);
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
165 }
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
166
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
167
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
168 void __logger_panel_visible(struct logger *l, int visible)
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
169 {
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
170 SetPanelAttribute(l->panel, ATTR_VISIBLE, visible);
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
171 }