kba-team / cakephp2-graylog
Graylog engine for CakePHP 2
Package info
github.com/the-kbA-team/cakephp2-graylog
Type:cakephp-plugin
pkg:composer/kba-team/cakephp2-graylog
Requires
- php: ^8.1
- ext-json: *
- composer/installers: ^1.12
- graylog2/gelf-php: ^1.6
- kba-team/cakephp: ^2.11
- kba-team/graylog-utilities: ^2.0
- kba-team/php-backtrace: ^1.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^9.6.39
Suggests
None
Provides
None
Conflicts
Replaces
None
README
Graylog log engine for CakePHP 2.x
Usage
composer require kba-team/cakephp2-graylog
The package must be published to Packagist before this command works. To
migrate from kba-team/cakephp-graylog, remove the old dependency and require
this package in the same Composer update. Both packages install the Graylog
plugin and must not be installed together. The plugin configuration below is
unchanged; PHP 8.1 or later is required.
<?php CakePlugin::load('Graylog'); CakeLog::config('graylog', [ 'engine' => 'Graylog.Graylog', 'types' => ['warning', 'error', 'critical', 'alert', 'emergency'], //PSR log levels 'host' => 'graylog.example.com', 'port' => 12201, 'facility' => 'MyAppName', 'append_backtrace' => true, //append a complete backtrace to the message body 'append' => [ //append the contents of $_POST JSON encoded to the message body 'POST' => static function () { if (!empty($_POST)) { $obfuscator = new \kbATeam\GraylogUtilities\Obfuscator(); //Replace the value of all keys named 'password' with 'xxx'. $obfuscator->addKey('password'); $obfuscator->setObfuscationString('xxx'); //JSON encode the POST variable for readability. return json_encode( $obfuscator->obfuscate($_POST), JSON_PRETTY_PRINT ); } return null; } ], 'additional' => [ //Add field 'current_user' to the GELF message. 'current_user' => static function () { return 'system'; } ] ]);
Possible configuration parameters are:
schemeCurrently TCP or UDP connections to Graylog are supported. Default:udphostThe hostname of the Graylog server. Default:127.0.0.1portThe port, the Graylog server listens to. Default:12201urlA connection URL in format<scheme>://<host>:<port>. This will overwrite any other settings.ignore_transport_errorsIgnore transport errors Default:truechunk_sizeThe size of the UDP packages. Default:\Gelf\Transport\UdpTransport::CHUNK_SIZE_LANssl_optionsAn instance of\Gelf\Transport\SslOptionsdefining SSL settings for TCP connections. Default:nullfacilityThe logging facility. Default:CakePHP.append_backtraceAppend a backtrace to the message body? Default:falseappendArray of anonymous functions. Their return strings get appended to the message body.additionalArray of anonymous functions. Their return values get added as additional fields to the GELF message.typesArray of log types, that will be sent to Graylog. See\Psr\Log\LogLevelfor all possible values. Default: all of them.
Development
The package supports PHP ^8.1 and tests PHP 8.1 and 8.5 with both default
and lowest dependency versions. PHP 8.0 is no longer supported. Docker and
network access are required.
make help
make validate PHP_VERSION=8.1
make check PHP_VERSION=8.1
make check PHP_VERSION=8.1 DEPENDENCIES_LOWEST=1
make check PHP_VERSION=8.5
make check PHP_VERSION=8.5 DEPENDENCIES_LOWEST=1
check installs dependencies, runs lint, PHPUnit with Clover coverage and
PHPStan, then audits the same dependency snapshot. test and check write
clover.xml. install and audit resolve their own snapshots.
These commands refuse to overwrite an existing composer.lock and remove
their temporary lockfile. QA commands require flock and reject concurrent
runs in the same checkout. make clean removes generated vendor/, coverage and
PHPUnit cache files. Set COMPOSER_IMAGE to select the Composer image, and set proxy
variables and CA_CERT_FILE if your network requires them.
Use an issue branch named <issue-number>-<title-slug> and open a pull request
against the relevant release branch. The main branch requires a pull request,
passing checks, an up-to-date branch and linear history; use squash merge.
The CakePHP 5 release line is maintained in
the-kbA-team/cakephp-graylog.
Force pushes are blocked outside branch names matching [0-9]*-*; this
pattern is broader than the issue-branch naming convention.
Further reading
- About CakePHP 2.x Logging
- About Graylog 3.x in general
- About Graylog Extended Log Format (GELF)