Merge lp:~mleith/mysql-proxy/bug55711 into lp:mysql-proxy

Proposed by Leith
Status: Merged
Approved by: Jan Kneschke
Approved revision: 1118
Merged at revision: 1118
Proposed branch: lp:~mleith/mysql-proxy/bug55711
Merge into: lp:mysql-proxy
Diff against target: 82 lines (+27/-15)
2 files modified
src/chassis-log.c (+25/-13)
src/chassis-mainloop.c (+2/-2)
To merge this branch: bzr merge lp:~mleith/mysql-proxy/bug55711
Reviewer Review Type Date Requested Status
Jan Kneschke (community) Approve
Review via email: mp+32190@code.launchpad.net

This proposal supersedes a proposal from 2010-08-06.

Description of the change

Bug#55711 - Agent log rotation : a HUP should rotate the log file
 - always close and re-open the log file before ignoring lower message levels

To post a comment you must log in.
Revision history for this message
Jan Kneschke (jan-kneschke) wrote : Posted in a previous version of this proposal

The 'is_duplicate' handling isn't updated with this change:

If you log "a", send a HUP, and log "a" again. The "a" should not be merged together, but logged as "a" into the old log and as "a" into the new one.

The change as it is in r1117 disables that behaviour and merges them all the time.

review: Needs Fixing
Revision history for this message
Jan Kneschke (jan-kneschke) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/chassis-log.c'
--- src/chassis-log.c 2010-06-30 14:43:13 +0000
+++ src/chassis-log.c 2010-08-10 12:52:44 +0000
@@ -279,12 +279,28 @@
279 int i;279 int i;
280 gchar *log_lvl_name = "(error)";280 gchar *log_lvl_name = "(error)";
281 gboolean is_duplicate = FALSE;281 gboolean is_duplicate = FALSE;
282 gboolean is_log_rotated = FALSE;
283 const char *stripped_message = chassis_log_skip_topsrcdir(message);
282284
283 /**285 /**
284 * make sure we syncronize the order of the write-statements 286 * make sure we syncronize the order of the write-statements
285 */287 */
286 static GStaticMutex log_mutex = G_STATIC_MUTEX_INIT;288 static GStaticMutex log_mutex = G_STATIC_MUTEX_INIT;
287289
290 /**
291 * rotate logs straight away if log->rotate_logs is true
292 * we do this before ignoring any log levels, so that rotation
293 * happens straight away - see Bug#55711
294 */
295 if (-1 != log->log_file_fd) {
296 if (log->rotate_logs) {
297 chassis_log_close(log);
298 chassis_log_open(log);
299
300 is_log_rotated = TRUE; /* we will need to dump even duplicates */
301 }
302 }
303
288 /* ignore the verbose log-levels */304 /* ignore the verbose log-levels */
289 if (log_level > log->min_lvl) return;305 if (log_level > log->min_lvl) return;
290306
@@ -298,24 +314,20 @@
298 }314 }
299315
300 if (log->last_msg->len > 0 &&316 if (log->last_msg->len > 0 &&
301 0 == strcmp(log->last_msg->str, message)) {317 0 == strcmp(log->last_msg->str, stripped_message)) {
302 is_duplicate = TRUE;318 is_duplicate = TRUE;
303 }319 }
304320
305 if (-1 != log->log_file_fd) {321 /**
306 if (log->rotate_logs) {322 * if the log has been rotated, we always dump the last message even if it
307 chassis_log_close(log);323 * was a duplicate. Otherwise, do not print duplicates unless they have been
308 chassis_log_open(log);324 * ignored at least 100 times, or they were last printed greater than
309325 * 30 seconds ago.
310 is_duplicate = FALSE; /* after a log-rotation always dump the queue */326 */
311 }327 if (is_log_rotated ||
312 }328 !is_duplicate ||
313
314
315 if (!is_duplicate ||
316 log->last_msg_count > 100 ||329 log->last_msg_count > 100 ||
317 time(NULL) - log->last_msg_ts > 30) {330 time(NULL) - log->last_msg_ts > 30) {
318 const char *stripped_message = chassis_log_skip_topsrcdir(message);
319331
320 /* if we lave the last message repeating, log it */332 /* if we lave the last message repeating, log it */
321 if (log->last_msg_count) {333 if (log->last_msg_count) {
322334
=== modified file 'src/chassis-mainloop.c'
--- src/chassis-mainloop.c 2010-04-06 17:29:58 +0000
+++ src/chassis-mainloop.c 2010-08-10 12:52:44 +0000
@@ -209,11 +209,11 @@
209static void sighup_handler(int G_GNUC_UNUSED fd, short G_GNUC_UNUSED event_type, void *_data) {209static void sighup_handler(int G_GNUC_UNUSED fd, short G_GNUC_UNUSED event_type, void *_data) {
210 chassis *chas = _data;210 chassis *chas = _data;
211211
212 g_message("received a SIGHUP, rotating logfile"); /* this should go into the old logfile */212 g_message("received a SIGHUP, closing log file"); /* this should go into the old logfile */
213213
214 chassis_log_set_logrotate(chas->log);214 chassis_log_set_logrotate(chas->log);
215 215
216 g_message("rotated logfile"); /* ... and this into the new one */216 g_message("re-opened log file after SIGHUP"); /* ... and this into the new one */
217}217}
218218
219219

Subscribers

People subscribed via source and target branches