Đầu tiên check file config/logging.php
'channels' => [ 'stack' => [ 'driver' => 'stack', 'channels' => ['single'], 'ignore_exceptions' => false, ], 'single' => [ 'driver' => 'single', 'path' => storage_path('logs/laravel.log'), 'level' => 'debug', ], 'daily' => [ 'driver' => 'daily', 'path' => storage_path('logs/laravel.log'), 'level' => 'debug', 'days' => 14, ], 'slack' => [ 'driver' => 'slack', 'url' => env('LOG_SLACK_WEBHOOK_URL'), 'username' => 'Laravel Log', 'emoji' => ':boom:', 'level' => 'critical', ], 'papertrail' => [ 'driver' => 'monolog', 'level' => 'debug', 'handler' => SyslogUdpHandler::class, 'handler_with' => [ 'host' => env('PAPERTRAIL_URL'), 'port' => env('PAPERTRAIL_PORT'), ], ], 'stderr' => [ 'driver' => 'monolog', 'handler' => StreamHandler::class, 'formatter' => env('LOG_STDERR_FORMATTER'), 'with' => [ 'stream' => 'php://stderr', ], ], 'syslog' => [ 'driver' => 'syslog', 'level' => 'debug', ], 'errorlog' => [ 'driver' => 'errorlog', 'level' => 'debug', ], 'null' => [ 'driver' => 'monolog', 'handler' => NullHandler::class, ], 'emergency' => [ 'path' => storage_path('logs/laravel.log'), ], 'http' => [ 'driver' => 'daily', 'path' => storage_path('logs/http.log'), 'level' => 'debug', ], 'crawl' => [ 'driver' => 'daily', 'path' => storage_path('logs/crawl.log'), 'level' => 'debug', ] ],
Đây là danh sách các channels ta có thể sử dụng. Ví dụ
- http & crawl là 2 channels mình tạo riêng cho việc log http requests & crawl request
Riêng channel stack là một channel đặc biệt cho phép gửi log đến cùng lúc nhiều channel khác.
'channels' => ['single']
Ở ví dụ này thì chỉ gởi đến channel single
Bên cạnh đó drivers là … driver sẽ được sử dụng cho việc log của channel đó
- single : Chỉ ghi log vào single file
- daily : Tương tự trên nhưng theo chu kì mỗi ngày 1 file
- errorlog
- syslog
Chi tiết hơn
Name | Description |
---|---|
stack | A wrapper to facilitate creating “multi-channel” channels |
single | A single file or path based logger channel (StreamHandler ) |
daily | A RotatingFileHandler based Monolog driver which rotates daily |
slack | A SlackWebhookHandler based Monolog driver |
papertrail | A SyslogUdpHandler based Monolog driver |
syslog | A SyslogHandler based Monolog driver |
errorlog | A ErrorLogHandler based Monolog driver |
monolog | A Monolog factory driver that may use any supported Monolog handler |
custom | A driver that calls a specified factory to create a channel |
Rồi . Vậy để sử dụng log channel thì sao
Log::stack(['http'])->info('Request URI: '.urldecode($uri).' with key: '.$key);
Leave a Reply