Mercurial > hg > fxanalyse
annotate logging.c @ 251:307fd62f376d
Implement log file rotation
author | Daniele Nicolodi <daniele@grinta.net> |
---|---|
date | Thu, 28 May 2015 16:12:18 +0200 |
parents | eaac96094640 |
children | d948e3ced2b9 |
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 |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
26 static inline int strtolevel(const char *str) |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
27 { |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
28 for (int i = 0; i < 4; i++) { |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
29 if (streq(levels[i], str)) |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
30 return i; |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
31 } |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
32 return DEBUG; |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
33 } |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
34 |
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 static int rotate(struct logger *l, struct tm *t) |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
37 { |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
38 int rv; |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
39 char id[7]; |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
40 |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
41 if (! l->dirpath) |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
42 return; |
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 if (l->yday == t.rm_yday) |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
45 return 0; |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
46 |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
47 /* close old file descriptor */ |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
48 close(l->fd); |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
49 l->fd = -1; |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
50 |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
51 /* construct new file name */ |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
52 strftime(id, sizeof(id), "%y%m%d", t); |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
53 rv = asprintf(&l->filepath, "%s\\%s-Log.txt", l->dirpath, id); |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
54 if (rv < 0) |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
55 return rv; |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
56 |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
57 /* open new log file */ |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
58 rv = open(filename, O_CREAT|O_WRONLY|O_APPEND, 00744); |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
59 if (rv < 0) |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
60 return rv; |
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 /* update status */ |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
63 l->fd = rv; |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
64 l->yday = t.rm_yday; |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
65 |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
66 return 1; |
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 |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
69 |
199
111610d871af
Show error state in main user inteface panel
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
191
diff
changeset
|
70 int __logger_init(struct logger *l, 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
|
71 { |
191
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
72 int rv, panel; |
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
73 char path[MAX_PATHNAME_LEN], *filename; |
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 l = malloc(sizeof(struct logger)); |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
76 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
|
77 |
199
111610d871af
Show error state in main user inteface panel
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
191
diff
changeset
|
78 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
|
79 l->fd = -1; |
251
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
80 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
|
81 |
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
82 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
|
83 if (panel < 0) |
97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
84 return -1; |
97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
85 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
|
86 |
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
87 /* configuration file path */ |
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
88 GetIniFilePath(path); |
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
89 |
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
90 /* load configuration file */ |
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
91 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
|
92 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
|
93 |
251
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
94 /* logging folder path */ |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
95 rv = Ini_GetStringCopy(configuration, "logging", "folder", &l->dirname); |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
96 |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
97 /* logging level */ |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
98 rv = Ini_GetStringCopy(configuration, "logging", "level", &str); |
229
28a56e4c06a4
Improvements to log file handling
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
199
diff
changeset
|
99 if (rv > 0) { |
251
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
100 l->level = strtolevel(str); |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
101 free(str); |
229
28a56e4c06a4
Improvements to log file handling
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
199
diff
changeset
|
102 } |
251
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
103 |
191
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
104 Ini_Dispose(configuration); |
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
105 |
169
97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
106 return 0; |
97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
107 } |
97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
108 |
97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
109 |
97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
110 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
|
111 { |
191
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
112 static const char *levels[] = { |
248
eaac96094640
Minor style improvements
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
239
diff
changeset
|
113 [ERROR] = "ERROR", |
eaac96094640
Minor style improvements
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
239
diff
changeset
|
114 [DEBUG] = "DEBUG", |
eaac96094640
Minor style improvements
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
239
diff
changeset
|
115 [INFO] = "INFO", |
eaac96094640
Minor style improvements
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
239
diff
changeset
|
116 [WARNING] = "WARNING", |
169
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 char msg[1024]; |
97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
120 int len = 0; |
97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
121 |
191
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
122 /* timestamp */ |
169
97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
123 len += sprintf(msg, "%014.3f ", utc); |
251
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
124 time_t now = (time_t)utc; |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
125 if (now == 0) |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
126 now = time(NULL); |
169
97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
127 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
|
128 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
|
129 |
191
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
130 /* level */ |
169
97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
131 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
|
132 |
191
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
133 /* message */ |
169
97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
134 va_list args; |
97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
135 va_start(args, frmt); |
97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
136 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
|
137 va_end(args); |
97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
138 |
191
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
139 /* newline */ |
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
140 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
|
141 msg[len++] = '\r'; |
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
142 msg[len++] = '\n'; |
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
143 |
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
144 /* string terminator */ |
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
145 msg[len] = '\0'; |
169
97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
146 |
191
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
147 /* display message */ |
169
97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
148 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
|
149 |
199
111610d871af
Show error state in main user inteface panel
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
191
diff
changeset
|
150 /* report error */ |
111610d871af
Show error state in main user inteface panel
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
191
diff
changeset
|
151 if (level == ERROR) |
111610d871af
Show error state in main user inteface panel
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
191
diff
changeset
|
152 l->onerror(level, msg); |
111610d871af
Show error state in main user inteface panel
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
191
diff
changeset
|
153 |
251
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
154 /* rotate log file based on current date */ |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
155 rotate(l, t); |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
156 |
191
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
157 /* write to log file */ |
251
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
158 if ((level <= l->level) && (l->fd >= 0)) |
191
0fed60877099
Allow to write log to file specified in configuration file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
169
diff
changeset
|
159 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
|
160 } |
251
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
161 |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
162 |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
163 void __logger_panel_visible(struct logger *l, visible) |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
164 { |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
165 SetPanelAttribute(l->panel, ATTR_VISIBLE, visible); |
307fd62f376d
Implement log file rotation
Daniele Nicolodi <daniele@grinta.net>
parents:
248
diff
changeset
|
166 } |