czim / laravel-context-log-library
Library for context logging for Laravel
Installs: 7 633
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^8.1
- czim/laravel-json-context-logging: >=3.0
- illuminate/support: >=10
- psr/log: >=3
Requires (Dev)
- mockery/mockery: ^1.5
- orchestra/testbench: ^8
- phpunit/phpunit: ^10.0
README
Context Logging library for Laravel
Helper library for standard setup of czim/laravel-json-context-logging.
This helps you to quickly create context channels for logging. It is not a requirement for using JSON context logging.
Version Compatibility
Installation
No installation required; however, classes must be bound manually in your service provider.
<?php use Czim\LaravelContextLogging\Config\StandardJsonContextConfigSource; use Czim\LaravelContextLogging\Contracts\ContextLoggerFactoryInterface; use Czim\LaravelContextLogging\Contracts\DebugEventLogPrepperInterface; use Czim\LaravelContextLogging\Factories\ContextLoggerFactory; class AppServiceProvider extends \Illuminate\Support\ServiceProvider { // ... public function register(): void { $this->app->singleton( DebugEventLogPrepperInterface::class, \Your\JsonContextEventLogPrepper::class ); $this->app->singleton( ContextLoggerFactoryInterface::class, function (): void { $factory = new ContextLoggerFactory(); $factory->setConfigs($this->makeLogContextConfigArray()); return $factory; } ); } protected function makeLogContextConfigArray(): array { return $this->app->make(StandardJsonContextConfigSource::class) ->enableContextLogging() ->makeConfigArray(); } }
You will also have to set up your own event, which may extend Czim\LaravelContextLogging\Events\AbstractDebugEvent
.
The listener for that event should use the ContextLoggerFactoryInterface
to make a logger,
and the DebugEventLogPrepperInterface
to render the event into loggable data to be logged by it.
Credits
License
The MIT License (MIT). Please see License File for more information.