PHP code example of nanayawkumi / nyk-logger

1. Go to this page and download the library: Download nanayawkumi/nyk-logger 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/ */

    

nanayawkumi / nyk-logger example snippets


'log' => [
    'enabled' => true,
    'levels'  => ['error', 'critical', 'alert', 'emergency'],
],

'exceptions' => [
    'enabled' => true,
    // Listing 500 also matches ANY server error (status >= 500).
    'http_statuses' => [500, 403],
    // ...or match specific throwable types regardless of status.
    'types' => [
        \Illuminate\Auth\Access\AuthorizationException::class, // 403
    ],
],

use Nanayawkumi\NykLogger\Facades\NykLogger;

try {
    $this->chargeCard();
} catch (\Throwable $e) {
    NykLogger::report($e);                       // report a throwable
    NykLogger::report($e, 'critical', ['order' => $id]);
}

NykLogger::alert('Nightly reconciliation mismatch', 'critical', [
    'expected' => $expected,
    'actual'   => $actual,
]);

use Nanayawkumi\NykLogger\Events\AlertSending;

Event::listen(AlertSending::class, function (AlertSending $e) {
    if (str_contains($e->payload->message, 'expected noise')) {
        return false; // cancel delivery
    }
});

use Nanayawkumi\NykLogger\Events\AlertSent;

Event::listen(AlertSent::class, function (AlertSent $e) {
    MyIncidentTracker::open($e->payload->toArray());
});

use Nanayawkumi\NykLogger\Facades\NykLogger;

NykLogger::fingerprintUsing(function (string $message, ?\Throwable $e, string $level) {
    // Return a string to group on, or null to fall back to the default.
    return $e instanceof \App\Exceptions\PaymentException ? 'payments' : null;
});
bash
php artisan vendor:publish --tag=nyk-logger-config
php artisan vendor:publish --tag=nyk-logger-views
bash
php artisan vendor:publish --tag=nyk-logger-config
bash
php artisan nyk-logger:test
bash
php artisan vendor:publish --tag=nyk-logger-views
# edit resources/views/vendor/nyk-logger/error-email.blade.php