spiral/logger
Spiral Logger provides a LogFactory and global log listeners for building and wiring PSR-3 compatible loggers in Spiral apps. Lightweight package with strong static analysis, tests, and CI support.
Start by installing via Composer (composer require spiral/logger) and familiarizing with the LogFactory class—the core service responsible for creating and configuring logger instances. The package provides a minimal PSR-3 compliant logging interface with added extensibility via global listeners and structured formatting.
For first-time use, inject LogFactory into your service or bootstrapper, then call $factory->create('channel') to get a logger instance. If a channel logger fails to resolve (e.g., due to misconfiguration), the package now falls back to the manually assigned logger (if one exists) instead of throwing an exception. Check src/LogFactory.php and src/Logger.php for details on channel configuration and fallback behavior.
auth, http, batch) to group logs logically. Each channel can be independently configured via the factory or config. If a channel logger fails to resolve, the package now gracefully falls back to a manually assigned logger (e.g., the default channel or a fallback instance).LogFactory::addGlobalListener(). Listeners must implement Spiral\Logger\ListenerInterface. Note that listeners are applied globally, so ensure they handle fallback scenarios if needed.$logger->info('User logged in', ['user_id' => $id])). The package ensures these are carried through the listener chain, even during fallback resolution.LogFactory::setFallbackLogger() or LogFactory::setDefaultLogger(). This logger will be used if channel-specific loggers cannot be resolved.config/logger.php), enabling DI and config overrides. Fallback behavior is particularly useful in dynamic environments where channel configurations may fail.create(), existing instances won’t inherit it. Always configure listeners before fetching loggers. Fallback loggers are also subject to this timing constraint.spiral/framework), avoid expecting new features—only bug fixes. Prefer using spiral/framework if full logger integration (e.g., with HTTP or CLI stacks) is needed.LogFactory::setHandler() (e.g., new StreamHandler('php://stderr')) or use framework defaults. Fallback loggers should also be explicitly configured with handlers.NullHandler or custom listener that appends messages to an array, then assert against it. This avoids side effects while validating logging behavior, including fallback scenarios.How can I help you explore Laravel packages today?