[MDEV-26625] Config option for all non-error logs to be written to STDOUT Created: 2021-09-16  Updated: 2022-03-09

Status: Open
Project: MariaDB Server
Component/s: None
Fix Version/s: None

Type: Task Priority: Minor
Reporter: Richard Bensley (Inactive) Assignee: Unassigned
Resolution: Unresolved Votes: 5
Labels: None


 Description   

The scenario

When run in a container, the MariaDB error log defaults to STDERR, which can be easily read and processed by an external service.

Other logs such as the audit log, can write to a file or syslog, but syslog requires an extra service container.

Tailing a log file requires an extra container, or a sidecar container, to be run per-instance of MariaDB just to tail and forward the log data.

If the remaining logs could all write to STDOUT, we would no longer have to worry about log storage and rotation on a container and matching volume, while exporting all log streaming and processing into a separate, often centralised, service.

Manually Re-directing to STDOUT/STDERR
The simplest solution is to set the log file paths up as symlinks to /dev/stdout, or even the host processes relevant file descriptor in /proc/self/fd/1.
But because the MariaDB container runs as a non-root user, MariaDB doesn't have permission to write to a symlink created by root.

2021-09-16 12:47:47 0 [ERROR] mysqld: File '/tmp/out.log' not found (Errcode: 13 "Permission denied")
2021-09-16 12:47:47 0 [ERROR] Could not use /tmp/out.log for logging (error 13). Turning logging off for the whole duration of the MariaDB server process. To turn it on again: fix the cause, shutdown the MariaDB server and restart it.

In a Dockerfile spec, you can switch to the mysql user, and create the symlink, in your MariaDB config, and point any log file to /tmp/out.log:

FROM mariadb:latest
ADD my.cnf /etc/my.cnf
USER mysql
RUN ln -sf /dev/stdout /tmp/out.log

This might break behaviour in other areas, as you would then need to specify to connect to a container as root:

docker exec -it db1 --user root bash

Solution
Allow other logs (audit, sql error, slow, general, more?) to be written to stdout.
Maybe when not specifying a path, similar to how log_error is configured.



 Comments   
Comment by Richard Bensley (Inactive) [ 2022-03-09 ]

It's also worth noting you cannot directly specify a file descriptor like '/dev/stdout' without getting an error:

2022-03-09 12:56:22 0 [Warning] mariadbd: SERVER AUDIT plugin can't create file '/dev/stdout'.
2022-03-09 12:56:22 0 [ERROR] mariadbd: File '/dev/stdout' not found (Errcode: 13 "Permission denied")
2022-03-09 12:56:22 0 [ERROR] Could not use /dev/stdout for logging (error 13). Turning logging off for the whole duration of the MariaDB server process. To turn it on again: fix the cause, shutdown the MariaDB server and restart it.

If, for example, slow query log and audit log were enabled, but no path is specified, the output just defaults to the server processes stdout.

Generated at Thu Feb 08 09:46:43 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.