annotate logging.c @ 252:d948e3ced2b9

Fix previous commit
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Thu, 28 May 2015 17:20:45 +0200
parents 307fd62f376d
children 3622e24a443f
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
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
44 static int rotate(struct logger *l, struct tm *t)
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];
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
48
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
49 if (! l->dirpath)
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
50 return 0;
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
51
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
52 if (l->yday == t->tm_yday)
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
53 return 0;
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
54
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
55 /* close old file descriptor */
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
56 close(l->fd);
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
57 l->fd = -1;
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
58
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
59 /* construct new file name */
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
60 strftime(id, sizeof(id), "%y%m%d", t);
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
61 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
62 l->filepath = malloc(len);
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
63 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
64
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
65 /* open new log file */
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
66 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
67 if (rv < 0)
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
68 return rv;
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
69
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
70 /* update status */
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
71 l->fd = rv;
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
72 l->yday = t->tm_yday;
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
73 __logmessage(l, DEBUG, "logging to '%s'", l->filepath);
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
74
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
75 return 1;
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
76 }
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
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
79 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
80 {
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
81 int rv, panel;
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
82 char path[MAX_PATHNAME_LEN], *str;
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
83
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
84 struct logger *l = malloc(sizeof(struct logger));
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
85 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
86
199
111610d871af Show error state in main user inteface panel
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 191
diff changeset
87 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
88 l->fd = -1;
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
89 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
90
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
91 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
92 if (panel < 0)
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
93 return NULL;
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
94 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
95
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
96 /* configuration file path */
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
97 GetIniFilePath(path);
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 /* load configuration file */
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
100 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
101 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
102
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
103 /* logging folder path */
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
104 rv = Ini_GetStringCopy(configuration, "logging", "folder", &l->dirpath);
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
105
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
106 /* logging level */
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
107 rv = Ini_GetStringCopy(configuration, "logging", "level", &str);
229
28a56e4c06a4 Improvements to log file handling
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 199
diff changeset
108 if (rv > 0) {
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
109 l->level = strtolevel(str);
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
110 free(str);
229
28a56e4c06a4 Improvements to log file handling
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 199
diff changeset
111 }
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
112
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
113 Ini_Dispose(configuration);
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
114
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
115 return l;
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
116 }
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
117
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
118
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
119 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
120 {
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
121 char msg[1024];
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
122 int len = 0;
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
123
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
124 /* timestamp */
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
125 len += sprintf(msg, "%014.3f ", utc);
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
126 time_t now = (time_t)utc;
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
127 if (now == 0)
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
128 now = time(NULL);
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
129 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
130 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
131
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
132 /* level */
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
133 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
134
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
135 /* message */
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
136 va_list args;
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
137 va_start(args, frmt);
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
138 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
139 va_end(args);
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
140
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
141 /* newline */
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
142 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
143 msg[len++] = '\r';
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
144 msg[len++] = '\n';
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
145
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
146 /* string terminator */
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
147 msg[len] = '\0';
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
148
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
149 /* rotate log file based on current date */
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
150 rotate(l, t);
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 /* write to log file */
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
153 if ((level <= l->level) && (l->fd >= 0))
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
154 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
155
191
0fed60877099 Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 169
diff changeset
156 /* display message */
169
97112b45b838 Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
157 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
158
199
111610d871af Show error state in main user inteface panel
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 191
diff changeset
159 /* report error */
111610d871af Show error state in main user inteface panel
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 191
diff changeset
160 if (level == ERROR)
111610d871af Show error state in main user inteface panel
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 191
diff changeset
161 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
162 }
251
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
163
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
164
252
d948e3ced2b9 Fix previous commit
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 251
diff changeset
165 void __logger_panel_visible(struct logger *l, int visible)
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 SetPanelAttribute(l->panel, ATTR_VISIBLE, visible);
307fd62f376d Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents: 248
diff changeset
168 }