alpha-dev-team / logger
Logger via db records, telegram and files. Based on Laravel logger.
Requires
- php: ^8.1
- laravel/framework: ^10.0
Requires (Dev)
- orchestra/testbench: 8.*
README
Requirements
- PHP v8.1+
Description
Logger via db records, telegram and files. Based on standard Laravel logger. It also utilizes the Monolog library. Plus, Alpha-Dev-Logger comes with a simple administration panel for reading, change status and delete log records.
Installation
First step is install Alpha-Dev-Logger via the Composer command
composer require alpha-dev-team/logger
Next important step is published configuration file logger-alpha.php
php artisan vendor:publish --tag=logger-config --force
Also need run migration for new logs table:
php artisan migrate
Configuration
General
Since Alpha-Dev-Logger based on standard Laravel logger, some configurations need to be made in logging.php in channels array. For convenience, all needed changes in logging.php contain in logger-alpha.php in channels array.
DB
Set in logging.php in channels (You can find it in logger-alpha.php in channels array):
'db' => [ 'driver' => 'custom', 'via' => \AlphaDevTeam\Logger\Logging\AlphaDevDBLogger::class, 'level' => env('LOG_LEVEL', 'debug'), ],
Telegram
If You want to get log errors to Telegram channel set in logging.php in channels (You can find it in logger-alpha.php in channels array):
'telegram' => [ 'driver' => 'custom', 'via' => \AlphaDevTeam\Logger\Logging\AlphaDevTelegramLogger::class, 'level' => env('LOG_LEVEL', 'debug'), ],
For using Telegram notifications it is necessary to determine and set telegram api bot and telegram channel name in Your .env file:
LOG_TELEGRAM_BOT_API=999999999:AAAAAAAsAAA9AaAAAaaaAaAaAaAAA99aAaa LOG_TELEGRAM_CHANNEL=telegram_channel
Also, You can make some changes for Telegram message view in logger-alpha.php.
Daily Files
If You want save log errors in files in json format, set in logging.php in channels (You can find it in logger-alpha.php in channels array):
'daily' => [ 'driver' => 'daily', 'path' => storage_path('logs/daily/laravel.log'), 'tap' => [\AlphaDevTeam\Logger\Logging\AlphaDevLogJson::class], 'level' => env('LOG_LEVEL', 'debug'), 'days' => 14, ],
Parameter days in daily array sets the retention period for files. You can set another.
General
Finally, make sure, that current log channel is stack in .env file.
LOG_CHANNEL=stack
And the last. Add to logging.php to array channels.stack.channels channels, that You will use:
'stack' => [ 'driver' => 'stack', 'channels' => ['daily', 'db', 'telegram'], 'ignore_exceptions' => false, ],
Panel
Alpha-Dev-Logger comes with a simple administration panel for reading, change status and delete log records. You can make some changes for panel rotes in logger-alpha.php.
Fresh Logs
For refresh logs db retrieved special command RefreshLogsTable. You can configure edge date time for soft delete records and edge date time for totally delete records in logger-alpha.php in db.remove_in_months
Also, You can add this command to Task Scheduling in App\Console\Kernel to schedule method. For example every month:
$schedule->command('refresh-logs:run')->monthly();