Microlog - Static wrapper around Monolog
Logging is a part of all applications. Having to inject in a logging service requires a dependency that has nothing to do with the code that you are writing. Microlog was created to remove this requirement.
Microlog allows you create log entries in different contexts from any part of your application. Microlog is built with never throwing exceptions in mind. An exception caused by logging causes the normal flow of your application to fail, and logging shouldn't do that.
To install microlog:
$ composer require linio/microlog
<?php
declare(strict_types=1);
use Linio\Component\Microlog\Log;
use Monolog\Handler\StreamHandler;
// Register a logger for a channel
$defaultLogger = new StreamHandler();
Log::setLoggerForChannel($defaultLogger, Log::DEFAULT_CHANNEL);
// Log an emergency
Log::emergency('This is a test emergency');
// Log an alert
Log::alert('This is a test alert');
// Log a critical error
Log::critical('This is a test critical error');
// Log an error
Log::error('This is a test error');
// Log a warning
Log::warning('This is a test warning');
// Log a notice
Log::notice('This is a test notice');
// Log a bit of information
Log::info('This is test information');
// Log debug information
Log::debug('This is test debug information');
// Log at an arbitrary level
Log::log('emergency', 'This is a test entry at an arbitrary level of emergency');Channels allow you to configure different handlers for different types of messages.
By default, all logs will be created in the default logging channel Log::DEFAULT_CHANNEL (default). If you wish to specify a different channel when logging, the second parameter to all non-arbitrary level log methods.
<?php
declare(strict_types=1);
use Linio\Component\Microlog\Log;
use Monolog\Handler\StreamHandler;
$defaultLogger = new NullLogger();
Log::setLoggerForChannel($defaultLogger, 'emergency');
Log::emergency('This is an emergency in the emergency channel', 'emergency');Feel free to send your contributions as a PR. Make sure you update/write new tests to support your contribution. Please follow PSR-2.
The development container uses PHP 8.5.12, the latest patched version listed in the PHP security advisory. Docker and Docker Compose are required. The provided Netskope CA bundle is mounted read-only for Composer's TLS connections; set NETSKOPE_CA_BUNDLE if it is stored elsewhere.
docker compose build
docker compose run --rm php php --version
docker compose run --rm php composer install
docker compose run --rm php composer testRun other Composer commands in the same container, for example:
docker compose run --rm php composer require vendor/packageThe package requires PHP 8.2.35, 8.3.36, 8.4.27, or 8.5.12 (or a later patch release in those branches), so Composer will not install it on an official PHP release that predates the security fixes.