- What is smartassert/invokable-logger used for?
- It provides an invokable wrapper around a PSR-3 logger so you can pass logging as a callable instead of injecting a concrete logger everywhere. You invoke the wrapper directly to record a message with a level and context. This helps keep classes decoupled from specific logging implementations. It is useful in dependency-injection-heavy codebases where a callable is expected.
- How do I install smartassert/invokable-logger in a Laravel app?
- Install it with Composer using composer require smartassert/invokable-logger. Then wrap a PSR-3-compatible logger instance, such as one from Laravel's logging stack, in the invokable adapter. No Laravel-specific configuration is described in the package overview, so you normally wire it manually or through your own service provider.
- Does smartassert/invokable-logger work with Laravel's Log facade or logging system?
- Yes, as long as you wrap a PSR-3-compatible logger. Laravel's logging system exposes PSR-3 logger instances, so you can pass one into the adapter and invoke it where a callable is needed. You still configure channels and handlers through Laravel's normal logging configuration. The package is an adapter, not a replacement for Laravel's logging stack.
- Do I need Monolog or another PSR-3 implementation to use this package?
- Yes, the package wraps a PSR-3 logger, so you need an underlying implementation such as Monolog or Laravel's PSR-3-compatible logger. The adapter itself does not replace the logging backend. It simply exposes that logger as an invokable callable. Check that your installed logger satisfies psr/log.
- How do I use an invokable logger where Laravel expects a callable?
- Instantiate the adapter with your PSR-3 logger, then pass the adapter instance wherever a callable is accepted. When the callable is invoked, the adapter logs the message with the supplied level and context. This avoids writing a one-off closure around the logger in each class. It also keeps the callable type consistent across your application.
- Can smartassert/invokable-logger help with dependency injection in Laravel?
- Yes, it is designed as a small dependency-injection-friendly adapter. You can bind the invokable wrapper in Laravel's service container and inject it into classes that need to log through a callable. Because the wrapper depends on PSR-3 rather than a concrete logger, you can swap the underlying logger in tests or different environments. This keeps your application code decoupled from logging details.
- How do I test code that depends on smartassert/invokable-logger?
- Because the dependency is callable, you can pass a simple test double or closure that records invocations instead of writing real logs. Alternatively, wrap a fake PSR-3 logger and assert the level, message, and context passed through the adapter. This lets you verify logging behavior without touching real log files or external handlers. Keep assertions focused on the contract your code relies on.
- Is smartassert/invokable-logger safe to use in production?
- It is a thin adapter around an existing PSR-3 logger, so production behavior is largely determined by the underlying logger you wrap. The wrapper adds minimal indirection and does not change how your logging backend handles messages. As with any small package, review its code, version constraints, and test coverage before deploying. Ensure your Laravel logging channels are configured for production.
- What are alternatives to smartassert/invokable-logger?
- You can use a plain closure around a PSR-3 logger, inject a PSR-3 LoggerInterface directly, or write a tiny custom invokable adapter. Laravel's own logging helpers and Monolog are common choices for the logging backend itself. This package is mainly useful when you specifically want a reusable callable logger without repeating closure code. Evaluate based on whether you need the callable abstraction.
- Which Laravel versions and PHP versions does smartassert/invokable-logger support?
- The package is framework-agnostic PHP and wraps PSR-3, so it is not tied to a specific Laravel release. In practice it should work with Laravel versions that run on a compatible PHP version and provide a PSR-3 logger. Check the package's composer.json on Packagist for its exact PHP and psr/log constraints. Also confirm the repository is actively maintained before adopting it.