volkv/loggio

0.0.16 2024-06-12 07:37 UTC

This package is auto-updated.

Last update: 2024-09-12 08:06:33 UTC


README

Loggio - 是一个简单的 Laravel 事件记录器(event:count),支持向 Telegram 发送每日报告

安装

composer require volkv/loggio "*"
php artisan migrate

您可以选择使用以下命令发布配置文件

php artisan vendor:publish --provider="Volkv\Loggio\LoggioServiceProvider"

配置

  • 将 Telegram 凭据添加到您的 .env
LOGGIO_TELEGRAM_BOT_TOKEN=
LOGGIO_TELEGRAM_CHAT_ID=
  • 将 cron 作业添加到 app/Console/Kernel.php 调度器中,并使用首选的 ->dailyAt() 选项
use Volkv\Loggio\Jobs\LoggioNotify;

$schedule->job(new LoggioNotify)->environments(['production'])->dailyAt('6:30');

请注意,您将获得自通知作业以来前一天的数据统计,与两天前相比

使用方法

use Volkv\Loggio\Loggio;

// Supported methods
Loggio::increment('your event');
Loggio::setCount('your event', 10);
Loggio::addCount('your event', 2);

// E.g. you may log API requests count
$response = $this->client->get($endpoint);
Loggio::increment('API Calls');
       
// You may also wrap the `LoggioNotify` job with your job to fill some daily data right before notification is sent
class MyNotifyJob
{
    use Dispatchable;

    public function handle()
    {
        $commentsCount = Comment::where('created_at', now()->subDay()->format('Y-m-d'))->count();
        Loggio::setCountYesterday("New comments", $commentsCount);

        LoggioNotify::dispatch();
    }
}

您将收到以下格式的 Telegram 通知

laravel-app@local: 

your event 1: 0️⃣ 🔴 -10
your event 2: 10 🟢 +6
your event 3: 10 🟠 0

已测试 MySQL 和 PostgreSQL