interitty/monolog
最新稳定版本:v1.0.0
Composer 安装命令:
composer require interitty/monolog
包简介
Extension of the standard Seldaek/Monolog with additional features specific to Interitty projects.
关键字:
README 文档
README
Extension of the standard Seldaek/Monolog with additional features specific to Interitty projects.
Requirements
- PHP >= 8.5
Installation
The best way to install interitty/monolog is using Composer:
composer require interitty/monolog
Then register the extension in the Nette config file:
# app/config/config.neon
extensions:
monolog: Interitty\Monolog\Nette\DI\MonologExtension
Configuration
services:
handlerServiceName:
factory: Monolog\Handler\StreamHandler(%appDir%/../log/application.log, Monolog\Logger::DEBUG)
autowired: false # Autowiring registers the handler into all channels
monolog:
channels:
default:
handlers:
- Monolog\Handler\RotatingFileHandler(%appDir%/../log/application.log, 30, Monolog\Logger::DEBUG)
# you can use the same configuration as in the services section (with class, arguments, setup, etc.)
file:
class: Monolog\Handler\StreamHandler
arguments: [%appDir%/../log/application.log, Monolog\Logger::DEBUG]
setup:
- setFormatter(Monolog\Formatter\LineFormatter())
- @handlerServiceName # or reference an existing service
processors:
memory: Monolog\Processor\MemoryUsageProcessor()
For all available Handlers, Formatters, and Processors, as well as other configuration options, see the official Monolog documentation.
Logging
Log a message with an injected logger (only the default channel is autowired)
use Psr\Log\LoggerInterface;
class ExampleService
{
/** @var LoggerInterface */
protected LoggerInterface $logger;
/**
* Constructor
*
* @param LoggerInterface $logger
* @return void
*/
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
/**
* Something processor
*
* @return void
*/
public function processSomething(): void
{
$this->logger->info('Log that application did something');
}
}
Logger Locator
To work with multiple channels,
use the LoggerLocator, which provides access to them by name.
use Interitty\Monolog\LoggerLocator;
class ExampleService
{
/** @var LoggerLocator */
protected LoggerLocator $loggerLocator;
/**
* Constructor
*
* @param LoggerLocator $loggerLocator
* @return void
*/
public function __construct(LoggerLocator $loggerLocator)
{
$this->loggerLocator = $loggerLocator;
}
/**
* Something processor
*
* @return void
*/
public function processSomething(): void
{
$this->loggerLocator->getLogger('default')->info('Log that application did something');
$this->loggerLocator->getLogger('specialLogger')->info('Log something very special');
}
}
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-30