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
1=== modified file 'src/chassis-log.c'
2--- src/chassis-log.c 2010-06-30 14:43:13 +0000
3+++ src/chassis-log.c 2010-08-10 12:52:44 +0000
4@@ -279,12 +279,28 @@
5 int i;
6 gchar *log_lvl_name = "(error)";
7 gboolean is_duplicate = FALSE;
8+ gboolean is_log_rotated = FALSE;
9+ const char *stripped_message = chassis_log_skip_topsrcdir(message);
10
11 /**
12 * make sure we syncronize the order of the write-statements
13 */
14 static GStaticMutex log_mutex = G_STATIC_MUTEX_INIT;
15
16+ /**
17+ * rotate logs straight away if log->rotate_logs is true
18+ * we do this before ignoring any log levels, so that rotation
19+ * happens straight away - see Bug#55711
20+ */
21+ if (-1 != log->log_file_fd) {
22+ if (log->rotate_logs) {
23+ chassis_log_close(log);
24+ chassis_log_open(log);
25+
26+ is_log_rotated = TRUE; /* we will need to dump even duplicates */
27+ }
28+ }
29+
30 /* ignore the verbose log-levels */
31 if (log_level > log->min_lvl) return;
32
33@@ -298,24 +314,20 @@
34 }
35
36 if (log->last_msg->len > 0 &&
37- 0 == strcmp(log->last_msg->str, message)) {
38+ 0 == strcmp(log->last_msg->str, stripped_message)) {
39 is_duplicate = TRUE;
40 }
41
42- if (-1 != log->log_file_fd) {
43- if (log->rotate_logs) {
44- chassis_log_close(log);
45- chassis_log_open(log);
46-
47- is_duplicate = FALSE; /* after a log-rotation always dump the queue */
48- }
49- }
50-
51-
52- if (!is_duplicate ||
53+ /**
54+ * if the log has been rotated, we always dump the last message even if it
55+ * was a duplicate. Otherwise, do not print duplicates unless they have been
56+ * ignored at least 100 times, or they were last printed greater than
57+ * 30 seconds ago.
58+ */
59+ if (is_log_rotated ||
60+ !is_duplicate ||
61 log->last_msg_count > 100 ||
62 time(NULL) - log->last_msg_ts > 30) {
63- const char *stripped_message = chassis_log_skip_topsrcdir(message);
64
65 /* if we lave the last message repeating, log it */
66 if (log->last_msg_count) {
67
68=== modified file 'src/chassis-mainloop.c'
69--- src/chassis-mainloop.c 2010-04-06 17:29:58 +0000
70+++ src/chassis-mainloop.c 2010-08-10 12:52:44 +0000
71@@ -209,11 +209,11 @@
72 static void sighup_handler(int G_GNUC_UNUSED fd, short G_GNUC_UNUSED event_type, void *_data) {
73 chassis *chas = _data;
74
75- g_message("received a SIGHUP, rotating logfile"); /* this should go into the old logfile */
76+ g_message("received a SIGHUP, closing log file"); /* this should go into the old logfile */
77
78 chassis_log_set_logrotate(chas->log);
79
80- g_message("rotated logfile"); /* ... and this into the new one */
81+ g_message("re-opened log file after SIGHUP"); /* ... and this into the new one */
82 }
83
84

Subscribers

People subscribed via source and target branches