nechaienko / laravel-mongodb-logging
Logging to Mongodb using Laravel logging
Installs: 2 927
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 0
Forks: 3
Open Issues: 0
Requires
- php: >=7.1
- illuminate/support: ~5.6
- jenssegers/mongodb: ~3.4
This package is auto-updated.
Last update: 2024-04-28 23:15:56 UTC
README
This package gives opportunity logging to mongodb with custom Laravel logging
Package jenssegers/laravel-mongodb is required
Installation
composer require nechaienko/laravel-mongodb-logging
Configuration
Add configurations to file ..\your_project\config\logging.php
'mogodb-channel' => [
'driver' => 'custom',
'via' => \Nechaienko\MongodbLogging\LogToMongoDb::class,
'level' => 'info',
'connection' => 'mongodb',
'collection' => 'logs',
],
Customization
Additional fields
'mogodb-channel' => [
...
'additional_fields' => [
'environment' => config('app.env'),
...
],
],
Fields formatting
You can override model from package and change fields format with Laravel mutators
- Create your model and override needed method
namespace App\Services\Logging;
use Nechaienko\MongodbLogging\MongoDbModel as ParentMongoDbModel;
class MongoDbModel extends ParentMongoDbModel
{
public function setDatetimeAttribute($value)
{
...
$this->attributes['datetime'] = $resultValue;
}
}
- Add your model to confs
'mogodb-channel' => [
...
'custom_model' => \App\Services\Logging\MongoDbModel::class,
],
Set default fields
You can define fields to set by overriding constant FIELDS_TO_SET
namespace App\Services\Logging;
use Nechaienko\MongodbLogging\MongoDbModel as ParentMongoDbModel;
class MongoDbModel extends ParentMongoDbModel
{
public const FIELDS_TO_SET = [
'message',
'level_name',
'datetime',
'extra',
];
}
Usage
use Illuminate\Support\Facades\Log;
...
Log::channel('mogodb-channel')->info('message');