定制 mepsd/laravel-google-chat-logger 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mepsd/laravel-google-chat-logger

Composer 安装命令:

composer require mepsd/laravel-google-chat-logger

包简介

Send Laravel application logs to Google Chat with rich formatting, emoji support, and context data

README 文档

README

Latest Version on Packagist Total Downloads License

Send your Laravel application logs directly to Google Chat with rich formatting, emoji support, threading, and automatic retries.

Features 🌟

  • 🎯 Easy Integration: Works with Laravel's built-in logging system
  • 🧵 Message Threading: Group related logs into threads
  • 🎨 Rich Formatting: Messages are beautifully formatted in Google Chat
  • 🔄 Automatic Retries: Built-in retry mechanism for failed messages
  • 🎯 Level-based Emojis: Different emojis for different log levels
  • 🌍 Environment Aware: Includes environment information in logs
  • Performance: Configurable timeouts and retry settings
  • 🚨 Exception Handling: Detailed exception formatting with stack traces

Requirements 📋

  • PHP 8.1 or higher
  • Laravel 10.x or 11.x
  • Google Chat space with webhook access

Installation 💿

  1. Install the package via composer:
composer require mepsd/laravel-google-chat-logger
  1. Add these variables to your .env file:
LOG_CHANNEL=google_chat
GOOGLE_CHAT_WEBHOOK_URL=your-webhook-url
  1. Add this to your config/logging.php channels array:
'channels' => [
    'google_chat' => [
        'driver' => 'custom',
        'via' => Mepsd\LaravelGoogleChatLogger\GoogleChatLogger::class,
        'url' => env('GOOGLE_CHAT_WEBHOOK_URL'),
        'level' => env('LOG_LEVEL', 'debug'),
        'retries' => 2,        // Number of retry attempts
        'timeout' => 5,        // Request timeout in seconds
    ],
],

Usage 📝

Basic Logging

// Simple info message
Log::info('User registered successfully', ['user_id' => 1]);

// Error with exception
try {
    // Some code
} catch (Exception $e) {
    Log::error('Process failed', [
        'exception' => $e,
        'user_id' => 1
    ]);
}

Message Threading

Group related logs into threads:

// Order Processing Thread
$threadKey = 'order-' . $orderId;

Log::info('Order received', [
    'thread_key' => $threadKey,
    'order_id' => $orderId,
    'amount' => 99.99
]);

Log::info('Processing payment', [
    'thread_key' => $threadKey,
    'payment_method' => 'credit_card'
]);

Log::info('Order completed', [
    'thread_key' => $threadKey,
    'status' => 'completed'
]);

// User Activity Thread
$userThread = 'user-' . $userId;

Log::info('User logged in', [
    'thread_key' => $userThread,
    'ip' => $request->ip()
]);

Log::warning('Failed login attempt', [
    'thread_key' => $userThread,
    'attempts' => 3
]);

Exception Handling

Exceptions are automatically formatted with details:

try {
    // Your code
} catch (Exception $e) {
    Log::error('Process failed', [
        'thread_key' => 'process-123',
        'exception' => $e,
        'additional_data' => $data
    ]);
}

Log Levels and Emojis

Each log level has its own emoji:

  • 🚨 EMERGENCY - System is unusable
  • ⚠️ ALERT - Action must be taken immediately
  • 🔥 CRITICAL - Critical conditions
  • ❌ ERROR - Error conditions
  • ⚠️ WARNING - Warning conditions
  • 📝 NOTICE - Normal but significant conditions
  • ℹ️ INFO - Informational messages
  • 🐛 DEBUG - Debug-level messages

Message Format

Messages in Google Chat will look like:

[local] ℹ️ *INFO*

Your message here

Context: { "user_id": 123, "action": "login" }


## Configuration Options

Full configuration options:

```php
'google_chat' => [
    'driver' => 'custom',
    'via' => Mepsd\LaravelGoogleChatLogger\GoogleChatLogger::class,
    'url' => env('GOOGLE_CHAT_WEBHOOK_URL'),
    'level' => env('LOG_LEVEL', 'debug'),
    'retries' => 2,              // Number of retry attempts
    'timeout' => 5,              // Request timeout in seconds
],

Setting Up Google Chat Webhook 🔗

  1. Open your Google Chat space
  2. Click the space name to open the dropdown menu
  3. Select "Manage webhooks"
  4. Click "Add webhook"
  5. Name your webhook (e.g., "Laravel Logs")
  6. Copy the webhook URL
  7. Add the URL to your .env file

Best Practices 🎯

  1. Use meaningful thread keys:
'user-{id}'        // For user activities
'order-{id}'       // For order processing
'deploy-{date}'    // For deployments
'job-{id}'         // For background jobs
  1. Group related logs:
$threadKey = 'payment-' . $paymentId;
Log::info('Starting payment', ['thread_key' => $threadKey]);
Log::info('Processing', ['thread_key' => $threadKey]);
Log::info('Completed', ['thread_key' => $threadKey]);
  1. Include context data:
Log::info('User action', [
    'thread_key' => 'user-123',
    'action' => 'profile_update',
    'changes' => ['name' => 'New Name'],
    'ip' => $request->ip()
]);

Testing 🧪

composer test

Security 🔒

If you discover any security-related issues, please use the issue tracker.

Credits 👏

License 📄

The MIT License (MIT). Please see License File for more information.

mepsd/laravel-google-chat-logger 适用场景与选型建议

mepsd/laravel-google-chat-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 31 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 02 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「logging」 「monolog」 「notifications」 「logger」 「laravel」 「webhook」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mepsd/laravel-google-chat-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mepsd/laravel-google-chat-logger 我们能提供哪些服务?
定制开发 / 二次开发

基于 mepsd/laravel-google-chat-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 31
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-15