josrom/laravel-logger is a Laravel package for channellog: custom logger to laravel.
It currently has 0 GitHub stars and 3.113 downloads on Packagist (latest version 13.0.0).
Install it with composer require josrom/laravel-logger.
Discover more Laravel packages by josrom
or browse all Laravel packages to compare alternatives.
Last updated
ChannelLog lets you log to separate files per channel, each with its own minimum level, so you are not stuck with a single catch-all log.
For older Laravel versions, check the supported versions table below.
Require the package with Composer:
composer require josrom/laravel-logger
Register the service provider and the facade alias in your config/app.php file:
'providers' => [
// Other Service Providers
Laravel\ChannelLog\ChannelLogServiceProvider::class,
],
'aliases' => [
// Other Aliases
'ChannelLog' => Laravel\ChannelLog\ChannelLog::class,
],
Then publish the config file:
php artisan vendor:publish --provider="Laravel\ChannelLog\ChannelLogServiceProvider"
This creates config/laravel-logger.php.
Each key under channels defines a log channel: where it writes to, and its minimum level.
// config/laravel-logger.php
return [
'channels' => [
'event' => [
'path' => 'logs/laravel-event.log',
'level' => \Monolog\Level::Info,
],
'error' => [
'path' => 'logs/laravel-error.log',
'level' => \Monolog\Level::Error,
],
'info' => [
'path' => 'logs/laravel-info.log',
'level' => \Monolog\Level::Info,
'extras' => ['internet-provider'],
],
],
];
path is relative to the storage directory.level accepts any Monolog\Level case (Debug, Info, Notice, Warning, Error, Critical, Alert, Emergency).extras is optional, see Extras.Use the ChannelLog facade to write to a specific channel. The method name sets the log level:
use ChannelLog;
ChannelLog::info('event', 'A user logged in.');
ChannelLog::error('error', 'Something went wrong.', ['user_id' => $user->id]);
To write at the level already configured for a channel, use write():
ChannelLog::write('event', 'A user logged in.');
Arrays, and anything implementing Illuminate\Contracts\Support\Arrayable or Illuminate\Contracts\Support\Jsonable (such as Eloquent models and collections), are formatted automatically before being written:
ChannelLog::info('event', $user);
ChannelLog::info('event', ['user_id' => $user->id, 'action' => 'login']);
Extras add extra context to a channel's log entries.
internet-provider: looks up the requesting IP's internet provider through ipinfo.io and appends it as an additional log line.The package uses Pest with Orchestra Testbench.
composer test
Check the code style with PHP CS Fixer:
composer format
Both run automatically on every push and pull request through GitHub Actions.
| Package version | Laravel version | |------------------------|------------------------| | 13. | 13. | | 12.* | 12.* | | 11.* | 11.* | | 10.* | 10.* | | 9.* | 9.* | | 8.* | 8.* | | 7.* | 7.* | | 6.* | 6.* | | 0.1.* / 5.* | 5.* |