1. Go to this page and download the library: Download timdev/timdev-log 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/ */
timdev / timdev-log example snippets
use Psr\Http\Message\ServerRequestInterface as SRI;
use TimDev\Log\Middleware\LogRequestAttributes;
$middleware = new LogRequestAttributes(
// A StackLogger instance
$logger,
// map of context-key => request-attribute name | callable
[
// Extract 'user_id' attribute from request, and set the 'uid'
// context value on the logger.
'uid' => 'user_id',
// The above is a shortcut for:
'uid2' => fn(SRI $req) => $req->getAttribute('user_id'),
// If you want other data from the request, you can use the same pattern
// to get it. For example:
'ref' => fn(SRI $req) => $req->getHeader('Referer')[0] ?? null
];
);
use Psr\Http\Message\ServerRequestInterface as SRI;
use TimDev\Log\Middleware\DevelopmentRedirect;
// Seconds to delay before refreshing. Default is zero.
$delaySeconds = 2;
$middleware = new DevelopmentRedirect($delaySeconds);
// ErrorHandler is the outermost middleware.
$app->pipe(ErrorHandler::class);
// If we're adding it, the DR middlware is the second outer-most.
if (getenv('APP_ENV') === 'development'){
$app->pipe(new DevelopmentRedirect(1));
}
// ... all the rest of my middlewares.
$logger = $container->get(\TimDev\Log\Logger::class);
// It's a PSR3 logger!
$logger->info('I can do PSR3 things ...');
// It's a StackLogger!
$childLogger = $logger->withContext(['some' => 'context']);
$childLogger->debug('foo');
// You can throw exceptions at it!
$ex = new \LogicException('Ya dun goofed!');
$logger->exception($ex);
// etc