I'd like to start an RFC (see the draft proposal at the end of this
message) for adding
journald support to PHP on Linux systems that use systemd. This message
is to
measure reaction to the intended proposal prior to requesting RFC karma.
Proof of concept implementation against PHP master branch:
https://github.com/markmont/php-src/commit/051775f01d9d1414b7cf45d35983abd958195a0c
Proof of concept implementation against PHP-5.6.5 branch:
https://github.com/markmont/php-src/commit/7572e35fa0ae1066e4dba2797a28f9dfbb548c1a
Thanks for any feedback!
--
Mark Montague
m...@catseye.org
== PHP RFC: journald support ==
* Version: 1.0
* Date: 2015-01-07
* Author: Mark Montague, m...@catseye.org
* Status: Draft
* First Published at: http://wiki.php.net/rfc/journald_support
= Introduction =
Add optional support to PHP for
[[http://www.freedesktop.org/software/systemd/man/systemd-journald.service.html|journald]]
as a standard extension. On web servers which use journald, this would permit
* structured system log messages via the Journal API
* journald to be used as an alternative to syslog for non-structured logging,
if desired
This proposal was motivated by the desire to retain structure when logging
Content Security Policy reports; see the example in the documentation for
the proposed sd_journal_send() function below. Other functionality such as
error_log support is included in the proposal in order to provide complete
support for journald logging in PHP.
= Proposal =
This proposal is to add support for journald (a part of systemd) to PHP in
in order to allow both PHP as well as PHP scripts to log directly to journald
rather than logging via syslog. The primary advantage of this is to permit
structured logging; a secondary advantage is that non-structured logs
(including messages logged via the error_log() function) can contain
additional information, including script file, script line number, and
PHP function or class name.
Base PHP support
=== error_log() ===
When the php.ini resource error_log is set to the special value journald,
error_log() output will be sent directly to journald via the Journal API.
A priority, syslog facility, and a syslog tag will automatically be added
based on the values of the php.ini resources journald.priority,
journald.syslog_facility, and journald.syslog_identifier unless
journald.suppress_syslog_fields is set to a non-zero value in which case
journald defaults will be used.
The PHP script file name, line number, and function or class name will
automatically be added unless the php.ini resource journald.suppress_location
is set to a non-zero value.
Example:
code
$ php -d error_log=journald -r 'error_log(Hello, world!);'
/code
Result:
code
# journalctl -a -l -n 1 -o verbose
-- Logs begin at Wed 2014-09-17 02:51:22 UTC, end at Thu 2014-12-04 14:58:14 UTC
Thu 2014-12-04 14:58:14.280324 UTC [s=7a262009cac947bd85e44417c1fd5059;i=31870;b
_UID=1000
_GID=1000
_CAP_EFFECTIVE=0
_AUDIT_LOGINUID=1000
_SYSTEMD_OWNER_UID=1000
_SYSTEMD_SLICE=user-1000.slice
_SELINUX_CONTEXT=staff_u:staff_r:staff_t:s0
_BOOT_ID=36f1fee4683d460fba350a50136f1f32
_MACHINE_ID=e66253b193b3405d9e82008bd6e05c5c
_HOSTNAME=www.example.com
PRIORITY=5
SYSLOG_IDENTIFIER=php
_TRANSPORT=journal
_COMM=php
_AUDIT_SESSION=24849
_SYSTEMD_CGROUP=/user.slice/user-1000.slice/session-24849.scope
_SYSTEMD_SESSION=24849
_SYSTEMD_UNIT=session-24849.scope
MESSAGE=Hello, world!
SYSLOG_FACILITY=19
CODE_FILE=Command line code
CODE_LINE=1
CODE_FUNC=error_log
_PID=5761
_EXE=/usr/bin/php
_CMDLINE=php -d error_log=journald -r error_log(Hello, world!);
_SOURCE_REALTIME_TIMESTAMP=1417705094280324
#
/code
Note that the function name reported above is error_log() because
error_log() was called directly by the main script. If error_log() had
been called from within a function or class method, the name of the
calling function or method would be reported instead.
=== mail() ===
When the php.ini resource error_log is set to the special value journald,
log messages generated by the mail() function will be sent directly to
journald via the Journal API.
A priority, syslog facility, and a syslog tag will automatically be added
based on the values of the php.ini resources journald.priority,
journald.syslog_facility, and journald.syslog_identifier unless
journald.suppress_syslog_fields is set to a non-zero value in which case
journald defaults will be used.
The PHP script file name, line number, and function or class name will
automatically be added unless the php.ini resource journald.suppress_location
is set to a non-zero value.
=== PHP-FPM SAPI ===
When the php-fpm.conf resource error_log is set to the special value
journald, all log messages generated by the php-fpm daemon will be
logged directly to journald via the Journal API.
The php-fpm.conf resources syslog.facility