Laravel Log Enhancer is an expansion package for Laravel 5.6 that can add additional data to the Laravel log. Thanks to the logging updates in Laravel 5.6, this package takes advantage of these features to extend logging and add data such as request headers, memory usage, session information, and other data.
You can add LogEnhancer
to your log channel by modifying the tap
attribute in config/logging.php
:
'production_stack' => [ 'driver' => 'stack', 'tap' => [Freshbitsweb\LaravelLogEnhancer\LogEnhancer::class], 'channels' => ['daily', 'slack'], ],
After configuring the log channel, the following is an example of a log containing the default additional information:
[2018-03-30 05:07:23] local.INFO: Testing log {"inputs":[],"session":{"_token":"bZXCPViCzmaULIO6GsdLBbveC1yd3BbyH31zfT8c","_previous":{"url":"http://log-enhancer-demo.test"},"_flash":{"old":[],"new":[]}},"url":"/","ip":"127.0.0.1","http_method":"GET","server":"","referrer":null}
The following are the configuration options for enhanced logging (including information about the default configuration options):
<?php return [ 'log_request_details' => true, 'log_input_data' => true, 'log_request_headers' => false, 'log_session_data' => true, 'log_memory_usage' => false, 'log_git_data' => false, // 你可以明确不记录到日志中的用户输入信息 'ignore_input_fields' => ['password', 'confirm_password'] ];
Pay special attention to the ignore_input_fields
option to avoid recording customer sensitive information in the log! ! ! For example, user password or credit card account number.
You need to run the interactive mode command artisan vendor:publish
to activate the custom configuration above:
php artisan vendor:publish --tag=laravel-log-enhancer-config
In a project based on Laravel 5.6, you can use Use composer to install this extension package using the following command:
composer require freshbitsweb/laravel-log-enhancer
Due to Laravel's automatic package discovery mechanism, you only need to install this package and configure it according to your program needs.
Learn more
For details, please check the official GitHub repository of this package (https://github.com/freshbitsweb/laravel-log-enhancer). It should be noted that this extension depends on the new logging system of Laravel 5.6, so you can only use it in that version or newer.
It appeared first on Laravel News (https://laravel-news.com/).