Mercurial > hg > fxanalyse
comparison logging.c @ 260:3622e24a443f
Also rotate log file at midnight UTC not local time
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Tue, 16 Jun 2015 15:06:19 +0200 |
parents | d948e3ced2b9 |
children |
comparison
equal
deleted
inserted
replaced
259:6c748ed6a7c5 | 260:3622e24a443f |
---|---|
39 } | 39 } |
40 return DEBUG; | 40 return DEBUG; |
41 } | 41 } |
42 | 42 |
43 | 43 |
44 static int rotate(struct logger *l, struct tm *t) | 44 static int rotate(struct logger *l, time_t now) |
45 { | 45 { |
46 int len, rv; | 46 int len, rv; |
47 char id[7]; | 47 char id[7]; |
48 struct tm *t; | |
48 | 49 |
49 if (! l->dirpath) | 50 if (! l->dirpath) |
50 return 0; | 51 return 0; |
51 | 52 |
53 /* utc day */ | |
54 t = gmtime(&now); | |
52 if (l->yday == t->tm_yday) | 55 if (l->yday == t->tm_yday) |
53 return 0; | 56 return 0; |
54 | 57 |
55 /* close old file descriptor */ | 58 /* close old file descriptor */ |
56 close(l->fd); | 59 close(l->fd); |
145 | 148 |
146 /* string terminator */ | 149 /* string terminator */ |
147 msg[len] = '\0'; | 150 msg[len] = '\0'; |
148 | 151 |
149 /* rotate log file based on current date */ | 152 /* rotate log file based on current date */ |
150 rotate(l, t); | 153 rotate(l, now); |
151 | 154 |
152 /* write to log file */ | 155 /* write to log file */ |
153 if ((level <= l->level) && (l->fd >= 0)) | 156 if ((level <= l->level) && (l->fd >= 0)) |
154 write(l->fd, msg, len); | 157 write(l->fd, msg, len); |
155 | 158 |