PHP code example of parli / json-logger

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

    

parli / json-logger example snippets


$writer = new \SomePsr3Logger();
$logger = new \Parli\JsonLogger\JsonLogger($writer);
// ...
$logger->error('Error message {info}', [
    'info' => $someMoreInfo,
    'exception' => $someThrowable,
]);

try {
    // ...
} catch (Throwable $e) {
    $logger->error('Caught exception in worker with input {input}', [
        'input' => $input,
        'exception' => $e,
    ]);
}

// Do NOT do this:
try {
    // ...
} catch (Throwable $e) {
    $logger->error('Caught exception in worker with input {input} - {message}: {trace}', [
        'input' => $input,
        'message' => $e->getMessage(),
        'trace' => $e->getTraceAsString(),
        'exception' => $e,
    ]);
}