-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Make log files support utf8, /usr/bin/mariadbd-multi, MDEV-37630 #4295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
debian12: host:~# /usr/bin/mariadbd-multi start 2 Wide character in print at /usr/bin/mariadbd-multi line 711. host:~# locale LANG=zh_CN.UTF-8 LANGUAGE= LC_CTYPE="zh_CN.UTF-8" LC_NUMERIC="zh_CN.UTF-8" LC_TIME="zh_CN.UTF-8" LC_COLLATE="zh_CN.UTF-8" LC_MONETARY="zh_CN.UTF-8" LC_MESSAGES="zh_CN.UTF-8" LC_PAPER="zh_CN.UTF-8" LC_NAME="zh_CN.UTF-8" LC_ADDRESS="zh_CN.UTF-8" LC_TELEPHONE="zh_CN.UTF-8" LC_MEASUREMENT="zh_CN.UTF-8" LC_IDENTIFICATION="zh_CN.UTF-8" LC_ALL=
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a UTF-8 encoding issue in the MariaDB multi-instance daemon script that was causing "Wide character in print" warnings when running in UTF-8 locales. The change adds proper UTF-8 encoding support to log file operations.
- Adds UTF-8 encoding support to log file handles in the mysqld_multi.sh script
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change commit message so that it conforms to MariaDB guidelines, something like:
MDEV-37630 - logfile cannot output utf8
mariadb-multi emits "Wide character in print..." warning when LC_TIME is
set to use UTF-8 character set. It occurs when writing log entry
timestamp that contains non-ASCII day of week and month name, while log
file is open in ASCII text mode.
Fixed by changing timestamp format to contain only ASCII characters.
open (LOGFILE, ">>$opt_log") | ||
or die "FATAL: w2log: Couldn't open log file: $opt_log\n"; | ||
binmode(LOGFILE, ":encoding(UTF-8)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem to be enough. If locale is set to something non-utf8, perl binmode
will screw up the string:
LC_TIME="zh_CN.GB18030" perl -e 'use POSIX qw(strftime); open (LOGFILE, ">>log"); binmode(LOGFILE, ":encoding(UTF-8)"); print LOGFILE strftime "%a %b %e %H:%M:%S %Y\n", localtime; close(LOGFILE);'
iconv -f gb18030 -t utf8 < log
This simplest solution would be to change date format such that it doesn't contain non-ASCII characters, e.g %Y-%m-%d %H:%M:%S
. Another option is to preserve date format, but use something else instead of strftime()
like Time::Piece
or DateTime
.
debian12:
host:~# /usr/bin/mariadbd-multi start 2
Wide character in print at /usr/bin/mariadbd-multi line 711.
host:~# locale
LANG=zh_CN.UTF-8
LANGUAGE=
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=
Description
TODO: fill description here
Release Notes
TODO: What should the release notes say about this change?
Include any changed system variables, status variables or behaviour. Optionally list any https://mariadb.com/kb/ pages that need changing.
How can this PR be tested?
TODO: modify the automated test suite to verify that the PR causes MariaDB to behave as intended.
Consult the documentation on "Writing good test cases".
If the changes are not amenable to automated testing, please explain why not and carefully describe how to test manually.
Basing the PR against the correct MariaDB version
main
branch.PR quality check