Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Invokable Logger

Invokable Logger Laravel Package

smartassert/invokable-logger

A lightweight, invokable PSR-3 logger for PHP and Laravel. Wrap any logging callable so it can be used as a logger or invoked directly, keeping code decoupled and easy to test. Ideal for small services, jobs, and closures that need simple logging without a full framework stack.

Deep Wiki
Context7

smartassert/invokable-logger is a PSR-3 logger whose core behaviour is exposed through a single __invoke() method, so you can log by treating the logger as a function: $logger('info', 'message', $context). It wraps any standard PSR-3 logger, keeping existing handlers and formatters intact while making call sites shorter and more consistent. Because it implements LoggerInterface, it drops into existing logging stacks without further changes.

  • Invokable API — log with $logger($level, $message, $context) instead of named methods.
  • PSR-3 compatible — implements LoggerInterface for drop-in interoperability.
  • Decorator-friendly — wraps and delegates to any PSR-3 logger.
  • Structured context — attach context arrays to each entry.
  • Minimal footprint — no heavy dependencies.
Frequently asked questions about Invokable Logger
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.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
laravel2580/idehelpers
delatbabel/viewpages
anavel/gettext
muhamadrezaar/highcharts
delatbabel/keylists
frankkessler/salesforce-laravel-oauth2-rest
anavel/foundation
wdmtech/enviricons
eii/laravel-captcha
muka/shape-reader
tdt/json
refinery29/php-cs-fixer-config
hotmeteor/eco-env
mvaliolahi/hydrate
wearede/tbcpay-php
parsnick/steak
thibaud-dauce/mattermost-php
multilinguals/apollo-client
antaresbr/collection
kr0lik/phpstan-rules