PHP code example of kba-team / cakephp-graylog

1. Go to this page and download the library: Download kba-team/cakephp-graylog library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kba-team / cakephp-graylog example snippets



\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');
        }
    ]
]);