kba-team / cakephp-graylog
Graylog engine for CakePHP
Installs: 25 557
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 5
Open Issues: 1
Type:cakephp-plugin
Requires
- php: ^8.1
- ext-json: *
- cakephp/cakephp: ~5.0
- graylog2/gelf-php: ^2.0
- kba-team/graylog-utilities: ^2.0.1
- kba-team/php-backtrace: ^1.0
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-10-22 07:32:05 UTC
README
Graylog log engine for CakePHP 3.x
Usage
composer require kba-team/cakephp-graylog
<?php \Cake\Core\Configure::write('Log.graylog', [ 'className' => \kbATeam\CakePhpGraylog\Log\Engine\GraylogLog::class, 'levels' => [\Psr\Log\LogLevel::EMERGENCY, \Psr\Log\LogLevel::ALERT, \Psr\Log\LogLevel::CRITICAL], 'host' => 'graylog.example.com', 'port' => 12201, 'scheme' => 'udp', 'facility' => 'MyAppName', 'append_backtrace' => true, '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 AuthComponent::user('username'); } ] ]);
Possible configuration parameters are:
scheme
Currently TCP or UDP connections to Graylog are supported. Default:udp
host
The hostname of the Graylog server. Default:127.0.0.1
port
The port, the Graylog server listens to. Default:12201
url
A connection URL in format<scheme>://<host>:<port>
. This will overwrite any other settings.ignore_transport_errors
Ignore transport errors Default:true
chunk_size
The size of the UDP packages. Default:\Gelf\Transport\UdpTransport::CHUNK_SIZE_LAN
ssl_options
An instance of\Gelf\Transport\SslOptions
defining SSL settings for TCP connections. Default:null
facility
The logging facility. Default:CakePHP
.append_backtrace
Append a backtrace to the message? Default:true
append
Array of anonymous functions (actually anything thatis_callable()
). Their return strings get appended to the message body.additional
Array of anonymous functions (actually anything thatis_callable()
). Their return values get added as additional fields to the GELF message.levels
Array of log level, that will be sent to Graylog. See\Psr\Log\LogLevel
for all possible values. Default: all of them.
Further reading
- About CakePHP 3.x Logging
- About Graylog 3.x in general
- About Graylog Extended Log Format (GELF)