Skip to content

Commit fef9692

Browse files
takaidohigasiclaude
andcommitted
Implement special handling for /dev/stdout and /dev/stderr logging
- Remove rotation mode configuration variables that caused linking errors - Add special case handling for /dev/stdout and /dev/stderr paths - For stdout/stderr: use path as-is without numbering, flush without rotation - For regular files: maintain original numbered file behavior - This enables container-friendly logging while preserving existing functionality 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 0aeaff3 commit fef9692

File tree

4 files changed

+24
-110
lines changed

4 files changed

+24
-110
lines changed

include/MySQL_Thread.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,8 @@ class MySQL_Threads_Handler
534534
int eventslog_default_log;
535535
int eventslog_format;
536536
int eventslog_stmt_parameters;
537-
char *eventslog_file_rotation_mode;
538537
char *auditlog_filename;
539538
int auditlog_filesize;
540-
char *auditlog_file_rotation_mode;
541539
// SSL related, proxy to server
542540
char * ssl_p2s_ca;
543541
char * ssl_p2s_capath;

include/proxysql_structs.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,12 +1623,10 @@ extern __thread int mysql_thread___eventslog_buffer_max_query_length;
16231623
extern __thread int mysql_thread___eventslog_default_log;
16241624
extern __thread int mysql_thread___eventslog_format;
16251625
extern __thread int mysql_thread___eventslog_stmt_parameters;
1626-
extern __thread char * mysql_thread___eventslog_file_rotation_mode;
16271626

16281627
/* variables used by audit log */
16291628
extern __thread char * mysql_thread___auditlog_filename;
16301629
extern __thread int mysql_thread___auditlog_filesize;
1631-
extern __thread char * mysql_thread___auditlog_file_rotation_mode;
16321630

16331631
/* variables used by the monitoring module */
16341632
extern __thread int mysql_thread___monitor_enabled;

lib/MySQL_Logger.cpp

Lines changed: 24 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,6 @@ using json = nlohmann::json;
2727

2828
extern MySQL_Logger *GloMyLogger;
2929

30-
// Rotation mode is now read from thread variables instead of static globals
31-
32-
// Helper functions to safely get rotation mode from thread variables
33-
static std::string get_events_rotation_mode() {
34-
return (mysql_thread___eventslog_file_rotation_mode &&
35-
strcmp(mysql_thread___eventslog_file_rotation_mode, "external") == 0) ?
36-
"external" : "internal";
37-
}
38-
39-
static std::string get_audit_rotation_mode() {
40-
return (mysql_thread___auditlog_file_rotation_mode &&
41-
strcmp(mysql_thread___auditlog_file_rotation_mode, "external") == 0) ?
42-
"external" : "internal";
43-
}
4430

4531
using metric_name = std::string;
4632
using metric_help = std::string;
@@ -1266,13 +1252,15 @@ void MySQL_Logger::audit_close_log_unlocked() {
12661252
void MySQL_Logger::events_flush_log_unlocked() {
12671253
if (events.enabled==false) return;
12681254

1269-
if (get_events_rotation_mode() == "external") {
1270-
// External rotation mode - just flush the current file
1255+
// Special handling for stdout/stderr - just flush without rotation
1256+
if (events.base_filename &&
1257+
(strcmp(events.base_filename, "/dev/stdout") == 0 ||
1258+
strcmp(events.base_filename, "/dev/stderr") == 0)) {
12711259
if (events.logfile) {
12721260
events.logfile->flush();
12731261
}
12741262
} else {
1275-
// Internal rotation mode - create numbered files (original behavior)
1263+
// Normal files - use numbered rotation (original behavior)
12761264
events_close_log_unlocked();
12771265
events_open_log_unlocked();
12781266
}
@@ -1281,13 +1269,15 @@ void MySQL_Logger::events_flush_log_unlocked() {
12811269
void MySQL_Logger::audit_flush_log_unlocked() {
12821270
if (audit.enabled==false) return;
12831271

1284-
if (get_audit_rotation_mode() == "external") {
1285-
// External rotation mode - just flush the current file
1272+
// Special handling for stdout/stderr - just flush without rotation
1273+
if (audit.base_filename &&
1274+
(strcmp(audit.base_filename, "/dev/stdout") == 0 ||
1275+
strcmp(audit.base_filename, "/dev/stderr") == 0)) {
12861276
if (audit.logfile) {
12871277
audit.logfile->flush();
12881278
}
12891279
} else {
1290-
// Internal rotation mode - create numbered files (original behavior)
1280+
// Normal files - use numbered rotation (original behavior)
12911281
audit_close_log_unlocked();
12921282
audit_open_log_unlocked();
12931283
}
@@ -1296,17 +1286,14 @@ void MySQL_Logger::audit_flush_log_unlocked() {
12961286
void MySQL_Logger::events_open_log_unlocked() {
12971287
char *filen=NULL;
12981288

1299-
if (get_events_rotation_mode() == "external") {
1300-
// External rotation mode - use basename file (no numbering)
1301-
if (events.base_filename[0]=='/') { // absolute path
1302-
filen=(char *)malloc(strlen(events.base_filename)+1);
1303-
strcpy(filen, events.base_filename);
1304-
} else { // relative path
1305-
filen=(char *)malloc(strlen(events.datadir)+strlen(events.base_filename)+2);
1306-
sprintf(filen,"%s/%s",events.datadir,events.base_filename);
1307-
}
1289+
// Special handling for stdout/stderr - use filename as-is without numbering
1290+
if (events.base_filename &&
1291+
(strcmp(events.base_filename, "/dev/stdout") == 0 ||
1292+
strcmp(events.base_filename, "/dev/stderr") == 0)) {
1293+
filen=(char *)malloc(strlen(events.base_filename)+1);
1294+
strcpy(filen, events.base_filename);
13081295
} else {
1309-
// Internal rotation mode - use numbered files (original behavior)
1296+
// Normal files - use numbered files (original behavior)
13101297
events.log_file_id=events_find_next_id();
13111298
if (events.log_file_id!=0) {
13121299
events.log_file_id=events_find_next_id()+1;
@@ -1359,17 +1346,14 @@ void MySQL_Logger::events_open_log_unlocked() {
13591346
void MySQL_Logger::audit_open_log_unlocked() {
13601347
char *filen=NULL;
13611348

1362-
if (get_audit_rotation_mode() == "external") {
1363-
// External rotation mode - use basename file (no numbering)
1364-
if (audit.base_filename[0]=='/') { // absolute path
1365-
filen=(char *)malloc(strlen(audit.base_filename)+1);
1366-
strcpy(filen, audit.base_filename);
1367-
} else { // relative path
1368-
filen=(char *)malloc(strlen(audit.datadir)+strlen(audit.base_filename)+2);
1369-
sprintf(filen,"%s/%s",audit.datadir,audit.base_filename);
1370-
}
1349+
// Special handling for stdout/stderr - use filename as-is without numbering
1350+
if (audit.base_filename &&
1351+
(strcmp(audit.base_filename, "/dev/stdout") == 0 ||
1352+
strcmp(audit.base_filename, "/dev/stderr") == 0)) {
1353+
filen=(char *)malloc(strlen(audit.base_filename)+1);
1354+
strcpy(filen, audit.base_filename);
13711355
} else {
1372-
// Internal rotation mode - use numbered files (original behavior)
1356+
// Normal files - use numbered files (original behavior)
13731357
audit.log_file_id=audit_find_next_id();
13741358
if (audit.log_file_id!=0) {
13751359
audit.log_file_id=audit_find_next_id()+1;
@@ -2121,29 +2105,3 @@ void MySQL_Logger::p_update_metrics() {
21212105
gauges[ml_g::circular_buffer_events_size]->Set(MyLogCB->size());
21222106
}
21232107

2124-
// Rotation mode configuration functions (now using thread variables)
2125-
void MySQL_Logger::set_eventslog_rotation_mode(const std::string& mode) {
2126-
if (mode == "internal" || mode == "external") {
2127-
if (mysql_thread___eventslog_file_rotation_mode) {
2128-
free(mysql_thread___eventslog_file_rotation_mode);
2129-
}
2130-
mysql_thread___eventslog_file_rotation_mode = strdup(mode.c_str());
2131-
}
2132-
}
2133-
2134-
void MySQL_Logger::set_auditlog_rotation_mode(const std::string& mode) {
2135-
if (mode == "internal" || mode == "external") {
2136-
if (mysql_thread___auditlog_file_rotation_mode) {
2137-
free(mysql_thread___auditlog_file_rotation_mode);
2138-
}
2139-
mysql_thread___auditlog_file_rotation_mode = strdup(mode.c_str());
2140-
}
2141-
}
2142-
2143-
std::string MySQL_Logger::get_eventslog_rotation_mode() const {
2144-
return get_events_rotation_mode();
2145-
}
2146-
2147-
std::string MySQL_Logger::get_auditlog_rotation_mode() const {
2148-
return get_audit_rotation_mode();
2149-
}

lib/MySQL_Thread.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,6 @@ extern "C" {
197197

198198
__thread unsigned int __thread_MySQL_Thread_Variables_version;
199199

200-
// Thread variables for rotation mode functionality
201-
__thread char * mysql_thread___eventslog_file_rotation_mode;
202-
__thread char * mysql_thread___auditlog_file_rotation_mode;
203-
204200
volatile static unsigned int __global_MySQL_Thread_Variables_version;
205201

206202

@@ -1089,10 +1085,8 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() {
10891085
variables.eventslog_default_log=0;
10901086
variables.eventslog_format=1;
10911087
variables.eventslog_stmt_parameters=0;
1092-
variables.eventslog_file_rotation_mode=strdup((char *)"internal");
10931088
variables.auditlog_filename=strdup((char *)"");
10941089
variables.auditlog_filesize=100*1024*1024;
1095-
variables.auditlog_file_rotation_mode=strdup((char *)"internal");
10961090
//variables.server_capabilities=CLIENT_FOUND_ROWS | CLIENT_PROTOCOL_41 | CLIENT_IGNORE_SIGPIPE | CLIENT_TRANSACTIONS | CLIENT_SECURE_CONNECTION | CLIENT_CONNECT_WITH_DB;
10971091
// major upgrade in 2.0.0
10981092
variables.server_capabilities = CLIENT_MYSQL | CLIENT_FOUND_ROWS | CLIENT_PROTOCOL_41 | CLIENT_IGNORE_SIGPIPE | CLIENT_TRANSACTIONS | CLIENT_SECURE_CONNECTION | CLIENT_CONNECT_WITH_DB | CLIENT_PLUGIN_AUTH;;
@@ -1372,9 +1366,7 @@ char * MySQL_Threads_Handler::get_variable_string(char *name) {
13721366
}
13731367
if (!strcmp(name,"server_version")) return strdup(variables.server_version);
13741368
if (!strcmp(name,"eventslog_filename")) return strdup(variables.eventslog_filename);
1375-
if (!strcmp(name,"eventslog_file_rotation_mode")) return strdup(variables.eventslog_file_rotation_mode);
13761369
if (!strcmp(name,"auditlog_filename")) return strdup(variables.auditlog_filename);
1377-
if (!strcmp(name,"auditlog_file_rotation_mode")) return strdup(variables.auditlog_file_rotation_mode);
13781370
if (!strcmp(name,"interfaces")) return strdup(variables.interfaces);
13791371
if (!strcmp(name,"keep_multiplexing_variables")) return strdup(variables.keep_multiplexing_variables);
13801372
if (!strcmp(name,"default_authentication_plugin")) return strdup(variables.default_authentication_plugin);
@@ -1530,9 +1522,7 @@ char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public f
15301522
if (!strcasecmp(name,"firewall_whitelist_errormsg")) return strdup(variables.firewall_whitelist_errormsg);
15311523
if (!strcasecmp(name,"server_version")) return strdup(variables.server_version);
15321524
if (!strcasecmp(name,"auditlog_filename")) return strdup(variables.auditlog_filename);
1533-
//if (!strcasecmp(name,"auditlog_file_rotation_mode")) return strdup(variables.auditlog_file_rotation_mode); // TODO: Temporarily disabled
15341525
if (!strcasecmp(name,"eventslog_filename")) return strdup(variables.eventslog_filename);
1535-
//if (!strcasecmp(name,"eventslog_file_rotation_mode")) return strdup(variables.eventslog_file_rotation_mode); // TODO: Temporarily disabled
15361526
if (!strcasecmp(name,"default_schema")) return strdup(variables.default_schema);
15371527
if (!strcasecmp(name,"keep_multiplexing_variables")) return strdup(variables.keep_multiplexing_variables);
15381528
if (!strcasecmp(name,"default_authentication_plugin")) return strdup(variables.default_authentication_plugin);
@@ -2022,18 +2012,6 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi
20222012
return true;
20232013
}
20242014
}
2025-
/* // TODO: Temporarily disabled for debugging
2026-
if (!strcasecmp(name,"auditlog_file_rotation_mode")) {
2027-
if (!strcasecmp(value,"internal") || !strcasecmp(value,"external")) {
2028-
free(variables.auditlog_file_rotation_mode);
2029-
variables.auditlog_file_rotation_mode=strdup(value);
2030-
return true;
2031-
} else {
2032-
proxy_error("Invalid value '%s' for auditlog_file_rotation_mode. Valid values are 'internal' or 'external'\n", value);
2033-
return false;
2034-
}
2035-
}
2036-
*/
20372015
if (!strcasecmp(name,"eventslog_filename")) {
20382016
if (value[strlen(value) - 1] == '/') {
20392017
proxy_error("%s is an invalid value for eventslog_filename, please specify a filename not just the path\n", value);
@@ -2059,18 +2037,6 @@ bool MySQL_Threads_Handler::set_variable(char *name, const char *value) { // thi
20592037
return true;
20602038
}
20612039
}
2062-
/* // TODO: Temporarily disabled for debugging
2063-
if (!strcasecmp(name,"eventslog_file_rotation_mode")) {
2064-
if (!strcasecmp(value,"internal") || !strcasecmp(value,"external")) {
2065-
free(variables.eventslog_file_rotation_mode);
2066-
variables.eventslog_file_rotation_mode=strdup(value);
2067-
return true;
2068-
} else {
2069-
proxy_error("Invalid value '%s' for eventslog_file_rotation_mode. Valid values are 'internal' or 'external'\n", value);
2070-
return false;
2071-
}
2072-
}
2073-
*/
20742040
if (!strcasecmp(name,"server_capabilities")) {
20752041
// replaced atoi() with strtoul() to have a 32 bit result
20762042
uint32_t intv = strtoul(value, NULL, 10);
@@ -2945,9 +2911,7 @@ MySQL_Thread::~MySQL_Thread() {
29452911
}
29462912

29472913
if (mysql_thread___eventslog_filename) { free(mysql_thread___eventslog_filename); mysql_thread___eventslog_filename=NULL; }
2948-
if (mysql_thread___eventslog_file_rotation_mode) { free(mysql_thread___eventslog_file_rotation_mode); mysql_thread___eventslog_file_rotation_mode=NULL; }
29492914
if (mysql_thread___auditlog_filename) { free(mysql_thread___auditlog_filename); mysql_thread___auditlog_filename=NULL; }
2950-
if (mysql_thread___auditlog_file_rotation_mode) { free(mysql_thread___auditlog_file_rotation_mode); mysql_thread___auditlog_file_rotation_mode=NULL; }
29512915
if (mysql_thread___ssl_p2s_ca) { free(mysql_thread___ssl_p2s_ca); mysql_thread___ssl_p2s_ca=NULL; }
29522916
if (mysql_thread___ssl_p2s_capath) { free(mysql_thread___ssl_p2s_capath); mysql_thread___ssl_p2s_capath=NULL; }
29532917
if (mysql_thread___ssl_p2s_cert) { free(mysql_thread___ssl_p2s_cert); mysql_thread___ssl_p2s_cert=NULL; }
@@ -4235,10 +4199,8 @@ void MySQL_Thread::refresh_variables() {
42354199
REFRESH_VARIABLE_INT(eventslog_format);
42364200
REFRESH_VARIABLE_INT(eventslog_stmt_parameters);
42374201
REFRESH_VARIABLE_CHAR(eventslog_filename);
4238-
REFRESH_VARIABLE_CHAR(eventslog_file_rotation_mode);
42394202
REFRESH_VARIABLE_INT(auditlog_filesize);
42404203
REFRESH_VARIABLE_CHAR(auditlog_filename);
4241-
REFRESH_VARIABLE_CHAR(auditlog_file_rotation_mode);
42424204
GloMyLogger->events_set_base_filename(); // both filename and filesize are set here
42434205
GloMyLogger->audit_set_base_filename(); // both filename and filesize are set here
42444206
REFRESH_VARIABLE_CHAR(default_schema);
@@ -4325,9 +4287,7 @@ MySQL_Thread::MySQL_Thread() {
43254287
mysql_thread___ldap_user_variable=NULL;
43264288
mysql_thread___add_ldap_user_comment=NULL;
43274289
mysql_thread___eventslog_filename=NULL;
4328-
mysql_thread___eventslog_file_rotation_mode=NULL;
43294290
mysql_thread___auditlog_filename=NULL;
4330-
mysql_thread___auditlog_file_rotation_mode=NULL;
43314291

43324292
// SSL proxy to server
43334293
mysql_thread___ssl_p2s_ca=NULL;

0 commit comments

Comments
 (0)