interitty / monolog
Extension of the standard Seldaek/Monolog with additional features specific to Interitty projects.
v1.0.0
2026-04-30 14:55 UTC
Requires
- php: ~8.5
- dg/composer-cleaner: ~2.2
- monolog/monolog: ~3.10
Requires (Dev)
- interitty/code-checker: ~1.0
- interitty/di: ~1.0
- interitty/phpunit: ~2.0
- nette/application: ~3.2
- nette/bootstrap: ~3.2
- nette/caching: ~3.4
This package is auto-updated.
Last update: 2026-04-30 12:56:29 UTC
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');
}
}