1. Go to this page and download the library: Download nostadt/psr3-log-context 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/ */
class User implements \Nostadt\Psr3LogContext\LogContextConvertibleInterface
{
public int $id;
public bool $activated;
public string $name;
public function asLogContext(): \Nostadt\Psr3LogContext\LogContext
{
return new \Nostadt\Psr3LogContext\LogContext(
new \Nostadt\Psr3LogContext\ValueObject\LogData('user_id', (string)$this->id),
new \Nostadt\Psr3LogContext\ValueObject\LogData('user_activated', $this->activated ? 'true' : 'false'),
new \Nostadt\Psr3LogContext\ValueObject\LogData('user_name', $this->name),
);
}
}
$user = new User();
$user->id = 1;
$user->activated = true;
$user->name = 'John Doe';
$logger->warning('My Message', $user->asLogContext()->toArray());
$logContext = new \Nostadt\Psr3LogContext\LogContext(
new \Nostadt\Psr3LogContext\ValueObject\LogData('user_uid', '1'),
new \Nostadt\Psr3LogContext\ValueObject\LogData('user_activated', 'true'),
new \Nostadt\Psr3LogContext\ValueObject\LogData('user_name', 'John Doe'),
);
$logger->warning('My Message', $logContext->toArray());
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.