tfo/advanced-log
最新稳定版本:v1.9.4
Composer 安装命令:
composer require tfo/advanced-log
包简介
Advanced logging system for Laravel with Slack, Sentry and DataDog integration
README 文档
README
Advanced Logger for Laravel
Advanced logging system for Laravel applications with integrated support for Slack, Sentry, and DataDog (Soon).
Features
- 🚀 Simple and intuitive API
- 📱 Real-time Slack notifications
- 🔍 Sentry error tracking integration
- 📊 DataDog metrics support
- 🎨 Customizable message formatting
- ⚡ Multiple notification channels
- 🔒 Secure credentials handling
- 🛠 Simplified configuration
Log Destinations
Logs are sent to:
- Local file (storage/logs/laravel.log)
- Slack (via webhook)
- Sentry (if configured)
- DataDog (if configured) SOON
Requirements
- PHP ^8.1
- Laravel ^10.0|^11.0
Installation
You can install the package via composer:
composer require tfo/advanced-log
Configuration
- Publish the configuration file:
php artisan advanced-log:install
The installer will:
Publish configurations Copy loggers to app/Loggers Install ServiceProvider Add .env variables Publish test routes
- Add these variables to your
.envfile:
# Slack Configuration LOGGER_SLACK_WEBHOOK_URL=your-webhook-url LOGGER_SLACK_CHANNEL=#your-channel LOGGER_SLACK_USERNAME=LoggerBot # Sentry Configuration LOGGER_SENTRY_DSN=your-sentry-dsn # DataDog Configuration LOGGER_DATADOG_API_KEY=your-api-key LOGGER_DATADOG_APP_KEY=your-app-key LOGGER_DATADOG_SERVICE=your-service-name # Enable/Disable Services LOGGER_ENABLE_SLACK=true LOGGER_ENABLE_SENTRY=true LOGGER_ENABLE_DATADOG=true
Usage
Log Types and Usage
Test Log Levels Standard Laravel log levels. Use to test basic logging functionality.
Performance Log Monitor execution times and bottlenecks. Use for:
- Long-running processes
- Database queries
- API calls
- Critical user flows
Audit Log Track data changes. Use for:
- User modifications
- Permission changes
- Critical record updates
- Configuration changes
Security Log Monitor security events. Use for:
- Login attempts
- Permission changes
- Suspicious activities
- Access violations
API Log Track API interactions. Use for:
- External service calls
- Endpoint monitoring
- Integration debugging
- API performance
Database Log Monitor database operations. Use for:
- Critical data changes
- Schema updates
- Bulk operations
- Data integrity checks
Job Log Track background tasks. Use for:
- Queue processing
- Scheduled tasks
- Long-running jobs
- Failed job analysis
Cache Log Monitor cache operations. Use for:
- Cache hits/misses
- Cache invalidation
- Memory usage
- Performance optimization
Request Log Track HTTP requests. Use for:
- Important endpoints
- User interactions
- Error tracking
- Performance monitoring
Payment Log Monitor financial transactions. Use for:
- Payment processing
- Refunds
- Subscription changes
- Payment errors
Notification Log Track communication events. Use for:
- Email sending
- SMS delivery
- Push notifications
- Communication errors
File Log Monitor file operations. Use for:
- File uploads
- Downloads
- Storage operations
- File processing
Auth Log Track authentication events. Use for:
- Login/logout
- Password resets
- 2FA events
- Session management
Export Log Monitor data exports. Use for:
- Report generation
- Bulk downloads
- Data migrations
- Export errors
Basic Logging
use Illuminate\Support\Facades\Log; Log::emergency('Emergency log test', ['context' => 'test']); Log::alert('Alert log test', ['context' => 'test']); Log::critical('Critical log test', ['context' => 'test']); Log::error('Error log test', ['context' => 'test']); Log::warning('Warning log test', ['context' => 'test']); Log::notice('Notice log test', ['context' => 'test']); Log::info('Info log test', ['context' => 'test']); Log::debug('Debug log test', ['context' => 'test']);
Advanced Logging
use Tfo\AdvancedLog\Support\ALog;
Performance Logging
$startTime = microtime(true); // Your code here $duration = (microtime(true) - $startTime) * 1000; ALog::performance('Process Order', $duration, [ 'order_id' => 123 ]);
Audit Logging
ALog::audit('update', 'User', 1, [ 'name' => ['old' => 'John', 'new' => 'Johnny'], 'email' => ['old' => 'john@example.com', 'new' => 'johnny@example.com'] ]);
Security Logging
ALog::security('Login Failed', [ 'email' => 'user@example.com', 'attempts' => 3 ]);
API Logging
$response = response()->json(['status' => 'success']); ALog::api('/api/users', 'GET', $response, 150.5);
Database Logging
ALog::database('create', 'users', 1, [ 'data' => ['name' => 'John', 'email' => 'john@example.com'] ]);
Job Logging
ALog::job('SendWelcomeEmail', 'completed', [ 'user_id' => 1, 'duration' => 1500 ]);
Cache Logging
ALog::cache('hit', 'user:123', [ 'ttl' => 3600 ]);
Request Logging
ALog::request('API Request', [ 'endpoint' => '/api/users', 'params' => ['page' => 1] ]);
Payment Logging
ALog::payment('success', 99.99, 'stripe', [ 'transaction_id' => 'tx_123' ]);
Notification Logging
ALog::notification('email', 'user@example.com', 'welcome', [ 'template' => 'welcome-email' ]);
File Logging
ALog::file('upload', 'images/profile.jpg', [ 'size' => '2.5MB', 'type' => 'image/jpeg' ]);
Auth Logging
ALog::auth('login_success', [ 'remember' => true, 'device' => 'iPhone 13' ]);
Export Logging
ALog::export('users', 1000, [ 'format' => 'csv', 'filters' => ['status' => 'active'] ]);
Channels
Slack
Messages are sent to Slack with:
- Emojis indicating log level
- Color-coded messages
- Structured context fields
- Custom channel support
Sentry
Errors are tracked in Sentry with:
- Full stack traces
- Environment information
- User context
- Custom tags and breadcrumbs
DataDog
Metrics are sent to DataDog with:
- Custom metrics
- Tagging
- Event aggregation
- Performance tracking
Testing
composer test
Changelog
See CHANGELOG.md for more information about recent changes.
Contributing
See CONTRIBUTING.md for details.
Security
If you discover any security-related issues, please email thallesfreitas@yahoo.com.br instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 38
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-23