This package provides a simple way to log model changes in your Laravel application.
You can install the package via composer:
composer require inktrapdesign/model-logger
You need to the BetterStack Source to your environment file. This is the source that will be used to identify the log entries in BetterStack.
LOGGER_CHANNEL=default
LOGGER_SOURCE=1234567890
To enable logging for a model, add the ModelLogger
trait to the model
use InktrapDesign\ModelLogger\ModelLogger;
class User extends Model
{
use ModelLogger;
}
To enable general logging to BetterStack, you first need to create a new channel in the config/logging.php
file.
'betterstack' =>
[
'driver' => 'monolog',
'level' => env('LOG_LEVEL', 'debug'),
'handler' => \Logtail\Monolog\LogtailHandler::class,
'with' => [
'sourceToken' => env('LOGGER_SOURCE')
],
'processors' => [PsrLogMessageProcessor::class],
],
You then want to add this channel to the stack, also in the config/logging.php
file.
'stack' =>
[
'driver' => 'stack',
'channels' => ['single', 'betterstack'],
'ignore_exceptions' => false,
],