Bug #4858 mysql_safe logs to syslog instead of stderr
Submitted: 2 Aug 2004 19:13 Modified: 9 Jul 2007 22:02
Reporter: Christian Hammers (Silver Quality Contributor) (OCA) Email Updates:
Status: Closed Impact on me:
Category:MySQL Server Severity:S4 (Feature request)
Version:4.0.20 OS:Linux (Debian GNU/Linux)
Assigned to: Timothy Smith CPU Architecture:Any
Tags: Contribution

[2 Aug 2004 19:13] Christian Hammers
Currently mysqld_safe pipes error messages from mysqld to stdout/stderr
which are piped to /var/log/mysql.err (or whereever) and then.. well..
either not rotated at all or rotated away since there is no possiblity
to do a "flush logs" for this error log.

My Debian packages have solved this problem by replacing the mysql error log
with a pipe to /usr/bin/logger which pipes it to the syslog.

The Debian packages are available at ftp://ftp.debian.org/pool/main/m/mysql-dfsg/.
The patch is attached. It also has another nice modification: the init script calles /etc/mysql/debian-start at startup which issues a "mysqlcheck -A --fast --silent" in the background and informs root per mail on errors.

How to repeat:
Check your error log, it is either rotated away or grows endlessly.

Suggested fix:
Hm, no patch upload possible? I will send them via mail...
[2 Aug 2004 19:14] Christian Hammers
The /etc/mysql/debian-start shell script.

Attachment: patch.debian-start.diff (text/x-patch), 1.04 KiB.

[2 Aug 2004 19:14] Christian Hammers
The /etc/init.d/mysql-server start script.

Attachment: patch.mysql-server.init.diff (text/x-patch), 3.08 KiB.

[2 Aug 2004 19:15] Christian Hammers
The syslogging /usr/bin/mysqld_safe script.

Attachment: patch.mysqld_safe.diff (text/x-patch), 4.56 KiB.

[11 Feb 2005 3:04] Arjen Lentz
The submitted patch sounds like a good solution, provided "logger" is available on all platforms. Logger appears to be a standard thing, part of IEEE Std 1003.2 (``POSIX.2'').
[25 Dec 2005 12:38] Valeriy Kravchuk
Thank you for a useful feature request. I believe, this feature should be implemented, as option, along with "classical" logging to .err file.
[27 Jul 2006 5:15] Timothy Smith
Hi, Christian,

Please look at bug #6061.  I am marking this one as a duplicate of bug 6061 because the motivation for your changes is the same as that bug.

It was fixed in 5.1 only, because:
- The current behavior has been like this forever.
- The fix changes behavior, and it's not a "hard" crashing / error bug.

Also, it's possible to copy the 5.1 mysqld_safe to a 5.0 or 4.1 installation.

However, the fix for bug #6061 does not log to syslog.  It simply makes mysqld_safe agree with mysqld on how the error log is handled.  It makes FLUSH LOGS flush the error log as well.  So this feature request is not 100% a duplicate of bug 6061, and there may be cause to implement syslog logging still.

Can you please let me know if the fix for 6061 addresses your main concerns?


[27 Jul 2006 22:07] Christian Hammers
Hello Tim

> It was fixed in 5.1 only, because:
> - The current behavior has been like this forever.
It has been *broken* forever, mysqld's error messages are going to void as it writes to a deleted file descriptor after the first logrotate!

> - The fix changes behavior, and it's not a "hard" crashing / error bug.
When browsing the changelog for 5.0.25 it seems to me that there are other
non grave bugs patched, too and the change of "behaviour" in that now syslog is used would be a quite desired one.

But anyway, if your release managers say no to 5.0 please reopen this one at 
least for 5.1 as my main desire was to get syslogging enabled as /var/log/mysql.err is mostly just another unattended logfile as most admins
only automatically check what they can get via remote syslog. It's IMHO simply
a "must have" for a unix server. You can make it configurable if windows
makes problems.


[28 Jul 2006 4:26] Timothy Smith

Thanks for the feedback.  I'll open this back up, and see if I can get it into 5.1.

[24 Jan 2007 13:54] john danilson
We use a log consolidation product, splunk (http://www.splunk.com/) and would like all the enabled mysql logs (error, slow query, and mysql log) to go to syslog so that they can be consolidated by this product. I would like to see some my.cnf option added that would allow automatic direction of the logs to syslog and optionally to the standard location.
[30 May 2007 23:08] Timothy Smith
Patch queued to the 5.1-maint team tree; will be merged to top 5.1 repo soon.
[6 Jun 2007 16:54] Bugs System
Pushed into 5.1.20-beta
[18 Jun 2007 17:03] Timothy Smith

Info from the BK comments; let me know if more is needed:

Overhaul the logging design, to allow logging mysqld messages to syslog.

Add two new options:  --syslog and --skip-syslog.  --syslog is the default, unless --log-error is also specified.

If --log-error is specified (for mysqld_safe, mysqld, server, etc. - any group which mysqld_safe checks for arguments), then syslog is turned off.  This is because mysqld will get the --log-error argument and log to a file anyways, which will be confusing to the user.  If the user requests both --syslog and --log-error, a warning is printed (to mysqld_safe's stderr and to syslog), and we then behave as if --skip-syslog had been specified.

Also, logging messages have been normalized somewhat: mysqld_safe now always prefixes messages with '<TIMESTAMP> mysqld_safe '.  All messages go to the the console (stdout or stderr, depending on if it's a notice or an error) and to (the error log OR syslog).

Also, a few cleanups while I'm here.
[9 Jul 2007 22:02] Paul DuBois
Noted in 5.1.20 changelog.

Incompatible change: mysqld_safe now supports error logging to 
syslog on systems that support the logger command. The new --syslog
and --skip-syslog options can be used in conjunction with the
--log-error option to control logging behavior, as described in
http://dev.mysql.com/doc/refman/5.1/en/mysqld-safe.html. The default 
is to use syslog, which differs from the previous default behavior
of writing an error log file. To maintain the older behavior, use
the --log-error option.