amirhb/laravel-mongodb-log

Mongodb Logging for Laravel

1.2 2019-05-21 12:42 UTC

This package is auto-updated.

Last update: 2020-05-21 14:46:30 UTC


README

Mongodb Logging-Channel For Laravel Framework

This package is developed as a mongodb logging-channel for Laravel 5.6 and above.

Installation

You could use Composer to install the package and all needed dependencies.

composer require amirhb/laravel-mongodb-log

Configuration

Updating Database Configuration file

You should update your config/database.php file to add a mongodb connection.

'mongodb' => [
            'driver'   => 'mongodb',
            'host'     => env('MONGODB_HOST', 'localhost'),
            'port'     => env('MONGODB_PORT', 27017),
            'database' => env('MONGODB_DATABASE', 'logs'),
            ],

And also update your config/logging.php to add your custom log-channel.

'channels' => [
    'custom' => [
        'driver' => 'custom',
        'via' => Amirhb\LaravelMongodbLog\LogHandler::class,
    ],
],

There is a config file to publish which you can use to set database connection and a collection name for your mongodb logs. First publish the config file:

php artisan vendor:publish --provider="Amirhb\LaravelMongodbLog\LogServiceProvider" --tag="config"

Then updating the config file with your desired settings:


<?php
return [
    'connection' => env('MONGODB_CONNECTION' ,'mongodb'),
    'collection' => env('MONGODB_LOG_COLLECTION' ,'logs'),
];

Usage

As mentioned above, the package is a logging channel so you can do logging as before like in the Laravel documentation described.

Logs are saved as Jenssegers\Mongodb\Eloquent\Model instances. You can query them easily. For more information check the Laravel MongoDB Documentation.

Unit Testing

to be added ...