amphp/log
Amp’s minimal PSR-3 compatible logging library with a simple Logger interface and built-in handlers. Designed for async apps, it integrates cleanly with the amphp ecosystem while remaining lightweight and easy to extend with custom log targets and formatters.
composer require amphp/log.use Amp\ByteStream\OutputStream;
use Amp\Log\ConsoleFormatter;
use Amp\Log\StreamHandler;
use Amp\Logging\Logger;
$output = new OutputStream(STDOUT);
$handler = new StreamHandler($output, new ConsoleFormatter());
$logger = new Logger('app', [$handler]);
$logger->info('Processing request', ['userId' => $userId, 'ip' => $ip]);
aerys or custom AMPHP HTTP server to avoid blocking responses during I/O-bound operations.MultiHandler to route logs to multiple targets (e.g., stdout + file + HTTP sink):
$handler = new MultiHandler([
new StreamHandler($output, new ConsoleFormatter()),
new StreamHandler($fileStream, new JsonFormatter()),
]);
ContextLogger:
$logger = new ContextLogger($baseLogger, ['requestId' => $requestId]);
$logger->info('Handling request'); // auto-includes requestId
AsyncHandler (from amphp/log v2+), which batches and flushes off-loop:
$handler = new AsyncHandler(new StreamHandler($stream));
$logger = new Logger('app', [$handler]);
Amp\Http\Server via middleware that injects request context, or Amp\Artax for client request logging.echo/var_dump in async code — always use the logger instead; it avoids I/O contention and context loss.JsonFormatter does not escape context values by default — wrap with Json::encode() or use JsonHandler if available in your version to prevent malformed logs.AsyncHandler, always await $handler->close() in shutdown to flush pending logs — otherwise last logs vanish.Handler and implement handle(LogRecord $record): void. Keep it fast — handlers run in the coroutine context; offload heavy I/O (e.g., network) to AsyncHandler.Amp\Logging; v2 (if used) uses Amp\Log namespace — ensure consistency across your stack.How can I help you explore Laravel packages today?