Re: [PHP-DEV] journald support for Linux systems that use systemd

2015-01-08 Thread Markus Fischer


On 08.01.15 02:14, Johannes Schlüter wrote:
 On Wed, 2015-01-07 at 17:01 -0500, Mark Montague wrote:
 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.
 
 I believe the sd_journal_* functions could go in a PECL version, for the
 logging I'd love if logging could be cleanup in a way that we have a
 good internal API for internal use as well as integrates with userlevel
 expectations (- PSR 3 Log)

That would have been my reaction too, but looking at the diff it plays
on the same level as the syslog logging, i.e. it's integral in the
system in parts where a PECL extensions couldn't reach ...

- Markus

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] journald support for Linux systems that use systemd

2015-01-08 Thread Adam Harvey
On 8 January 2015 at 01:39, Markus Fischer mar...@fischer.name wrote:
 On 08.01.15 02:14, Johannes Schlüter wrote:
 On Wed, 2015-01-07 at 17:01 -0500, Mark Montague wrote:
 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.

 I believe the sd_journal_* functions could go in a PECL version, for the
 logging I'd love if logging could be cleanup in a way that we have a
 good internal API for internal use as well as integrates with userlevel
 expectations (- PSR 3 Log)

 That would have been my reaction too, but looking at the diff it plays
 on the same level as the syslog logging, i.e. it's integral in the
 system in parts where a PECL extensions couldn't reach ...

I think that's Johannes's point, though: if we can extend our internal
logging API to support these special case log file names in a central
place and allow extensions to register new ones, then journald support
could be implemented as an extension and we wouldn't have to touch
those bits of code.

I'd probably be -1 on the patch as it stands (this doesn't need to be
in php-src right now; syslog has the advantage of being a standard
cross-platform interface, which this isn't), but +1 on doing the work
to support that.

Adam

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] journald support for Linux systems that use systemd

2015-01-07 Thread Johannes Schlüter
Hi,

On Wed, 2015-01-07 at 17:01 -0500, Mark Montague wrote:
 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.

I believe the sd_journal_* functions could go in a PECL version, for the
logging I'd love if logging could be cleanup in a way that we have a
good internal API for internal use as well as integrates with userlevel
expectations (- PSR 3 Log)

johannes



-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] journald support for Linux systems that use systemd

2015-01-07 Thread Mark Montague


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