Skip to content

Conversation

takaidohigasi
Copy link
Contributor

@takaidohigasi takaidohigasi commented Jul 11, 2025

WHAT

  • enable to set event log output to /dev/stdout and /dev/stderr

WHY

#5038

Tests

mysql_variables=
{
...
        eventslog_filename      = "/dev/stderr"
        auditlog_filename         = "/dev/stderr"
        # logging as json format
        eventslog_format           = 2
        auditlog_format         = 2
}

mysql_query_rules:
(
        {
                rule_id=1
                active=1
                match_pattern=".*"
                log=1
        }
)
  • we can start proxysql server without error, and log works.
vagrant@ubuntu:~$ sudo /usr/bin/proxysql -f --reload -c /etc/proxysql.cnf --idle-threads
...
2025-07-14 06:39:27 [INFO] For information about products and services visit: https://proxysql.com/
2025-07-14 06:39:27 [INFO] For online documentation visit: https://proxysql.com/documentation/
2025-07-14 06:39:27 [INFO] For support visit: https://proxysql.com/services/support/
2025-07-14 06:39:27 [INFO] For consultancy visit: https://proxysql.com/services/consulting/
2025-07-14 06:39:27 [INFO] Started Monitor scheduler thread for PgSQL servers
2025-07-14 06:39:28 [INFO] Latest ProxySQL version available: 3.0.1-420-g2c26a42

{"client_addr":"127.0.0.1:40544","event":"MySQL_Client_Connect_OK","proxy_addr":"0.0.0.0:6033","schemaname":"information_schema","ssl":true,"thread_id":1,"time":"2025-07-14 06:39:52.038","timestamp":1752475192038,"username":"root"}
{"client":"127.0.0.1:40544","digest":"0x7AFCE30A2413DF1B","duration_us":1259,"endtime":"2025-07-14 06:39:52.040464","endtime_timestamp_us":1752475192040464,"errno":0,"event":"COM_QUERY","hostgroup_id":0,"query":"select 1 from dual","rows_affected":0,"rows_sent":1,"schemaname":"information_schema","server":"127.0.0.1:3306","starttime":"2025-07-14 06:39:52.039205","starttime_timestamp_us":1752475192039205,"thread_id":1,"username":"root"}
{"client_addr":"127.0.0.1:40544","event":"MySQL_Client_Quit","proxy_addr":"0.0.0.0:6033","schemaname":"information_schema","ssl":true,"thread_id":1,"time":"2025-07-14 06:39:52.041","timestamp":1752475192041,"username":"root"}
{"client_addr":"127.0.0.1:40544","creation_time":"2025-07-14 06:39:52.028","duration":"13.020ms","event":"MySQL_Client_Close","extra_info":"MySQL_Thread.cpp:4018:process_all_sessions()","proxy_addr":"0.0.0.0:6033","schemaname":"information_schema","ssl":true,"thread_id":1,"time":"2025-07-14 06:39:52.041","timestamp":1752475192041,"username":"root"}
vagrant@ubuntu:~/proxysql$ mysql -u root -P 6033 -h 127.0.0.1 -p -e "select 1 from dual;"
Enter password:
+---+
| 1 |
+---+
| 1 |
+---+
  • log rotate:
vagrant@ubuntu:~/proxysql$ mysql -u admin -P 6032 -h 127.0.0.1 -p -e "PROXYSQL FLUSH LOGS;"
Enter password:

: proxysql log. not errored.
2025-07-14 06:45:23 [INFO] Received PROXYSQL FLUSH LOGS command
2025-07-14 06:45:23 [INFO] ProxySQL version d693e6e2d4da2d7c1b474df47510c8796be3d576

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @takaidohigasi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant enhancement by allowing ProxySQL's event and audit logs to be directed to standard output and standard error. This is achieved by modifying the log handling mechanism to recognize and correctly process /dev/stdout and /dev/stderr as special device files, bypassing traditional log rotation for these streams. Comprehensive new tests have been added to ensure the robustness and correctness of this new functionality.

Highlights

  • Log Output Redirection: Implemented the ability to configure eventslog_filename and auditlog_filename to direct log output to standard streams (/dev/stdout and /dev/stderr).
  • Log Rotation Logic: Modified the log opening routines to prevent log file rotation (e.g., appending .00000001) when the target filename is /dev/stdout or /dev/stderr, ensuring logs are written directly to the specified stream.
  • New Test Coverage: Added a new test suite (test_logger_special_devices-t.cpp) to validate the correct behavior of setting event and audit logs to standard output/error, including testing FLUSH LOGS and switching back to regular files.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@renecannao
Copy link
Contributor

Can one of the admins verify this patch?

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enables logging to stdout and stderr by treating /dev/stdout and /dev/stderr as special log files that do not get rotated. The changes look good and include a new test file to cover the functionality. There are opportunities to improve the efficiency and maintainability of the code by reducing redundant calls and using safer string manipulation functions.

Comment on lines +1269 to +1274
events.log_file_id=events_find_next_id();
if (events.log_file_id!=0) {
events.log_file_id=events_find_next_id()+1;
} else {
events.log_file_id++;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The events_find_next_id() function is called multiple times, which is inefficient and could lead to incorrect behavior if the directory contents change between calls. To avoid this, call the function once and store the result.

Suggested change
events.log_file_id=events_find_next_id();
if (events.log_file_id!=0) {
events.log_file_id=events_find_next_id()+1;
} else {
events.log_file_id++;
}
events.log_file_id=events_find_next_id();
events.log_file_id++;

Comment on lines +1329 to +1334
audit.log_file_id=audit_find_next_id();
if (audit.log_file_id!=0) {
audit.log_file_id=audit_find_next_id()+1;
} else {
audit.log_file_id++;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The audit_find_next_id() function is called multiple times, which is inefficient and could lead to incorrect behavior if the directory contents change between calls. To avoid this, call the function once and store the result.

Suggested change
audit.log_file_id=audit_find_next_id();
if (audit.log_file_id!=0) {
audit.log_file_id=audit_find_next_id()+1;
} else {
audit.log_file_id++;
}
audit.log_file_id=audit_find_next_id();
audit.log_file_id++;

Comment on lines +1280 to +1281
filen=(char *)malloc(strlen(events.base_filename)+1);
strcpy(filen, events.base_filename);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider using strdup instead of malloc and strcpy for a more concise and safer way to allocate memory and copy the string.

Suggested change
filen=(char *)malloc(strlen(events.base_filename)+1);
strcpy(filen, events.base_filename);
filen=strdup(events.base_filename);

Comment on lines +1340 to +1341
filen=(char *)malloc(strlen(audit.base_filename)+1);
strcpy(filen, audit.base_filename);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider using strdup instead of malloc and strcpy for a more concise and safer way to allocate memory and copy the string.

Suggested change
filen=(char *)malloc(strlen(audit.base_filename)+1);
strcpy(filen, audit.base_filename);
filen=strdup(audit.base_filename);

@takaidohigasi
Copy link
Contributor Author

@gemini-code-assist you have added review for almost the problem for existing code. would you please focus on the change it self? for example, diff of indent change is not treated as change.

Copy link

Thank you for your feedback, @takaidohigasi. I understand your concern and appreciate you bringing it to my attention.

My primary objective is to provide a thorough review focused on the changes introduced in the pull request. I adhere strictly to the guidelines that require me to limit all suggestions and comments to only the portions of code that are modified within the diff hunks. This ensures that my feedback is directly relevant to the changes you've made.

I will continue to prioritize the functional correctness, efficiency, and maintainability of the new or modified code, ensuring that my comments are actionable and focused on the intent of your changes. My analysis is strictly confined to the lines presented in the diff to provide targeted and relevant feedback.

@takaidohigasi takaidohigasi marked this pull request as ready for review July 11, 2025 10:14
@takaidohigasi takaidohigasi marked this pull request as draft July 12, 2025 21:51
@takaidohigasi takaidohigasi reopened this Jul 14, 2025
@takaidohigasi takaidohigasi force-pushed the enable-set-to-eventlog-output-to-stdout-and-stderr branch 2 times, most recently from fef9692 to fd04840 Compare July 14, 2025 06:36
@takaidohigasi takaidohigasi marked this pull request as ready for review July 14, 2025 06:47
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
35.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@takaidohigasi
Copy link
Contributor Author

sorry I tried to add new variables eventslog_file_rotation_mode

eventslog_file_rotation_mode = "external"

but it failed, so reverted to the original change. sorry for bothering you.

@takaidohigasi
Copy link
Contributor Author

if there is any suggestion, please tell me 🙏

@noizu noizu added the status/triage Mark issue for team triage label Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/triage Mark issue for team triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants