vpa / psr-logger
Implementations of PSR-3 Logger Interface for Developer Console and CLI console
0.1.1
2022-08-18 22:29 UTC
Requires
- php: >=8.0
- psr/log: ^3.0
- squizlabs/php_codesniffer: ^3.7
- vpa/di: ^0.1.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4.8
This package is auto-updated.
Last update: 2024-11-15 23:23:12 UTC
README
Installation
composer require vpa/psr-logger
Example
This logger can be used with Container (PSR-11). Example:
use VPA\DI\Container;
require_once(__DIR__ . '/../vendor/autoload.php');
// We want use for logs JS Developer Console if we run the script in browser and CLI Console - if run in CLI mode
$classLogger = php_sapi_name()=='cli' ? 'VPA\Logger\ConsoleLogger' : 'VPA\Logger\JSConsoleLogger';
$di = new Container();
$di->registerContainers([
'VPA\Logger'=>$classLogger,
]);
$logger = $di->get('VPA\Logger');
$logger->emergency("emergency message {date}",['date'=>date('d.m.Y H:i:s')]);
$logger->alert("alert message {date}",['date'=>date('d.m.Y H:i:s')]);
$logger->critical("critical message {date}",['date'=>date('d.m.Y H:i:s')]);
$logger->error("error message {date}",['date'=>date('d.m.Y H:i:s')]);
$logger->warning("warning message {date}",['date'=>date('d.m.Y H:i:s')]);
$logger->notice("notice message {date}",['date'=>date('d.m.Y H:i:s')]);
$logger->info("info message {date}",['date'=>date('d.m.Y H:i:s')]);
$logger->debug("debug message {date}",['date'=>date('d.m.Y H:i:s')]);
or if don`t use DI:
require_once(__DIR__ . '/../vendor/autoload.php');
$logger = new \VPA\Logger\ConsoleLogger(); // For ConsoleLogger
$logger->emergency("emergency message {date}",['date'=>date('d.m.Y H:i:s')]);
$logger->alert("alert message {date}",['date'=>date('d.m.Y H:i:s')]);
$logger->critical("critical message {date}",['date'=>date('d.m.Y H:i:s')]);
$logger->error("error message {date}",['date'=>date('d.m.Y H:i:s')]);
$logger->warning("warning message {date}",['date'=>date('d.m.Y H:i:s')]);
$logger->notice("notice message {date}",['date'=>date('d.m.Y H:i:s')]);
$logger->info("info message {date}",['date'=>date('d.m.Y H:i:s')]);
$logger->debug("debug message {date}",['date'=>date('d.m.Y H:i:s')]);
Result for ConsoleLogger