yuriitatur / laravel-logger-boost
A simple package for boosting your logging experience in Laravel
Package info
bitbucket.org/yurii_tatur/laravel-logger-boost
pkg:composer/yuriitatur/laravel-logger-boost
Requires
- monolog/monolog: ^3.9.0
Requires (Dev)
- dg/bypass-finals: ^1.9
- laravel/framework: ^v13.3.0
- orchestra/testbench: ^v11.0.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-02 12:44:31 UTC
README
Laravel logger boost
Add useful processors to your app.
Installation
composer require yuriitatur/laravel-logger-boost
Testing
composer test
Usage
Disclaimer
This package is designed to work with a Laravel framework, but it can be used with/without any framework as the set of useful Monolog processors.
Laravel
Add BoostLogger to your channel config in config/logging.php
'channels' => [
'single' => [
'driver' => 'single',
'tap' => [\YuriiTatur\LaravelLoggerBoost\BoostLogger::class],
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
],
],
Or you can add even more context with AddMoreContext
'channels' => [
'single' => [
'driver' => 'single',
'tap' => [
\YuriiTatur\LaravelLoggerBoost\BoostLogger::class,
\YuriiTatur\LaravelLoggerBoost\AddMoreContext::class
],
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
],
],
This will add multiple extra fields like hostname, is_cli, route or user. Thus, returning all that data in each
record is overhead. So make use of a stack driver with bubble option
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => [ // this is our main channels
'single-error', // single-error channel will not bubble message to single
'single',
],
'ignore_exceptions' => false,
],
'single' => [ // all debug+ messages goes with only BoostLogger
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'formatter' => JsonFormatter::class,
'tap' => [
BoostLogger::class,
BufferRecords::class . ':10', // optionally enable record buffering, with specified buffer size
],
],
'single-error' => [ // if something happens, use AddMoreContext and bubble => false
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'error',
'bubble' => false, // if this is true, the message will be duplicated
'formatter' => JsonFormatter::class,
'tap' => [
BoostLogger::class,
AddMoreContext::class,
],
],
}
Eloquent
You can also add log key to your eloquent models, to keep track of all that happened to them with one key.
First, add log_key column to your table;
# in your migration
Schema::table('my_models', function (Blueprint $table) {
$table->string('log_key')->nullable()->unique();
});
The reason, why it's not in a separate thing called AddLogKeyColumn class/method is because, requirements to
this column may vary. Create your own how you like it.
Next, add LogKeyAwareTrait trait in your model. You can use overtakeLogs and applyLogKey methods now.
# in your model
class Product extends Model
{
use LogKeyAwareTrait;
}
# in your service
public function createProduct($params)
{
$product = new Product($params);
$product->applyLogKey(); # creating event is a good place to put this
$product->save();
}
public function updateProduct($id, $params)
{
$product = Product::findOrFail($id);
$product->overtakeLogs(); # this will take log key from the model and apply to your logger
$product->update($params);
}
Queue Jobs
This package automatically registers new LoggerAwareWorkerDecorator queue worker.
That now resets all processors between each job, this is done specifically to reload log keys, so each
job can be traced using its own id. The log key is reset even if your default channel does not use BoostLogger.
Log records about jobs (Running job, Job finished, Job failed) contain the resolved job name
(e.g. App\Jobs\SendInvite), not the generic Illuminate\Queue\CallQueuedHandler@call.
Open transactions. After every worker loop the package rolls back any database transaction left open by a job
and logs a warning. Keep this in mind in tests: running queue:work inside a test that uses RefreshDatabase
rolls back the test transaction too. Process jobs with app('queue.worker')->runNextJob(...) there, or set
logging.boost.register_event_logs to false.
License
This code is under MIT license, read more in the LICENSE file.