Logger
Centralized logging functionality with Rollbar integration for error tracking and monitoring.
Repository: rollbar/rollbar-php
Environment Configuration
LOG_API=ROLLBAR
LOG_API_TOKEN=your_rollbar_access_token
LOG_PATH=/logs
Rollbar API Key Setup
To obtain a Rollbar API key:
Go to Rollbar.com and create an account
Create a new project or select an existing one
Navigate to Settings → Project Access Tokens
Copy the post_server_item token
Add it to your
.env
file asLOG_API_TOKEN
API
Logger::log(string $message, string $level = 'info', array $data = [])
Supported Log Levels
debug
- Detailed debug informationinfo
- General information messagesnotice
- Normal but significant eventswarning
- Warning messageserror
- Error conditionscritical
- Critical conditionsalert
- Action must be taken immediatelyemergency
- System is unusable
Features
Automatic user context: Includes session user data when available
Level validation: Invalid levels default to 'info'
Rollbar integration: Seamless error tracking and monitoring
Environment-based: Only logs to Rollbar when
LOG_API=ROLLBAR
Usage Examples
// Basic logging
Logger::log('User login successful');
// With specific level
Logger::log('Database connection failed', 'error');
// With additional context data
Logger::log('Payment processed', 'info', [
'amount' => 99.99,
'currency' => 'USD',
'transaction_id' => 'txn_123'
]);
// Critical system error
Logger::log('System out of memory', 'critical', [
'memory_usage' => memory_get_usage(),
'memory_limit' => ini_get('memory_limit')
]);
User Context
When a user session exists ($_SESSION['user']
), the logger automatically includes:
[
'person' => [
'id' => $_SESSION['user']['id'],
'email' => $_SESSION['user']['email']
]
]
This enables user-specific error tracking in Rollbar.
Last updated