401clicks/laravel-logger
Composer 安装命令:
composer require 401clicks/laravel-logger
包简介
Laravel logging driver for 401 Clicks - Simple log aggregation and monitoring
README 文档
README
Simple log aggregation for Laravel applications. Send your logs to 401 Clicks with just a few environment variables.
Installation
composer require 401Clicks/laravel-logger
Quick Start
Add these to your .env file:
LOG_CHANNEL=stack LOG_STACK=single,clicks CLICKS_API_TOKEN=your-api-token-here
That's it! Your logs will now be sent to 401 Clicks.
Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
CLICKS_API_TOKEN |
Your API token from project settings | required |
CLICKS_LOG_URL |
API endpoint (for self-hosted) | https://logs.401clicks.com/api/v1/logs |
CLICKS_LOG_LEVEL |
Minimum log level to send | debug |
CLICKS_BATCH_SIZE |
Number of logs to batch | 10 |
CLICKS_FLUSH_INTERVAL |
Max seconds between flushes | 5 |
CLICKS_MASKING_ENABLED |
Enable/disable data masking | true |
CLICKS_MASKING_STYLE |
Masking style: full, partial, or hash |
full |
Publishing Config
To customize the configuration:
php artisan vendor:publish --tag=clicks-logger-config
Manual Channel Configuration
If you prefer to configure the channel manually in config/logging.php:
'channels' => [ // ... other channels 'clicks' => [ 'driver' => 'clicks', 'url' => env('CLICKS_LOG_URL', 'https://logs.401clicks.com/api/v1/logs'), 'token' => env('CLICKS_API_TOKEN'), 'level' => env('CLICKS_LOG_LEVEL', 'debug'), ], ],
Usage
Once configured, just use Laravel's standard logging:
use Illuminate\Support\Facades\Log; Log::info('User logged in', ['user_id' => $user->id]); Log::error('Payment failed', ['order_id' => $order->id, 'error' => $e->getMessage()]);
Using with Stack Channel
The recommended setup uses Laravel's stack channel to log locally AND send to 401 Clicks:
LOG_CHANNEL=stack LOG_STACK=single,clicks
This way you keep local logs while also sending them to 401 Clicks.
Logging to Clicks Only
To only send logs to 401 Clicks:
LOG_CHANNEL=clicks
Sensitive Data Masking
The logger automatically masks sensitive data before it leaves your application. This is the most secure approach as PII and credentials never reach any external service.
Default Behavior
By default, masking is enabled and will detect and mask:
- Credit card numbers (Visa, MasterCard, Amex, Discover, JCB)
- Social Security Numbers (XXX-XX-XXXX format)
- API keys (sk_, pk_, Bearer tokens)
- Passwords in key-value contexts
- Phone numbers (US formats)
Configuration
Configure masking via environment variables or the config file:
# Disable masking entirely (not recommended) CLICKS_MASKING_ENABLED=false # Change masking style: full, partial, or hash CLICKS_MASKING_STYLE=full
Available masking styles:
| Style | Example Input | Example Output |
|---|---|---|
full (default) |
4111111111111111 |
[CREDIT_CARD] |
partial |
4111111111111111 |
****1111 |
hash |
4111111111111111 |
[a3f8b2c1] |
Custom Patterns
Add custom patterns in your config/clicks-logger.php:
'masking' => [ 'custom_patterns' => [ [ 'name' => 'Customer IDs', 'pattern' => '/CUST-[A-Z0-9]{8}/i', 'replacement' => '[CUSTOMER_ID]', ], [ 'name' => 'Internal Order Numbers', 'pattern' => '/ORD-\d{10}/', 'replacement' => '[ORDER_ID]', ], ], ],
Enabling Additional Patterns
To mask email addresses or IP addresses, update the patterns array:
'masking' => [ 'patterns' => [ 'credit_cards', 'ssn', 'api_keys', 'passwords', 'phone_numbers', 'emails', // Now enabled 'ip_addresses', // Now enabled ], ],
Server-Side Fallback
401 Clicks also provides server-side masking for logs sent via cURL or other methods that don't use this package. Configure server-side masking in your project settings at 401clicks.com.
How It Works
- Logs are batched (default: 10 logs or 5 seconds)
- Sensitive data is masked before batching (client-side)
- Batches are sent via HTTP POST to the 401 Clicks API
- Failed sends are logged to stderr (won't break your app)
- Remaining logs are flushed on shutdown
Getting Your API Token
- Go to 401clicks.com
- Navigate to your project settings
- Create a new API token
- Copy the token to your
.envfile
Requirements
- PHP 8.1+
- Laravel 10, 11, or 12
- Guzzle HTTP client
License
MIT License
401clicks/laravel-logger 适用场景与选型建议
401clicks/laravel-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 523 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logging」 「monitoring」 「laravel」 「Log aggregation」 「401clicks」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 401clicks/laravel-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 401clicks/laravel-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 401clicks/laravel-logger 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony bundle for chameleon-system/sanitycheck
A Zend Framework module that sets up Monolog for logging in applications.
SoftWax Health Check Bundle for Symfony framework
1Pilot client for Symfony
Statsd (Object Oriented) client library for PHP
Asynchronous Sentry for Symfony - Fire and forget
统计信息
- 总下载量: 523
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 36
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-27