Home > PHP Framework > Laravel > An extension package is highly recommended: Laravel Log Enhancer

An extension package is highly recommended: Laravel Log Enhancer

藏色散人
Release: 2021-07-17 09:04:34
forward
1384 people have browsed it

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'],
],
Copy after login

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}
Copy after login

The following are the configuration options for enhanced logging (including information about the default configuration options):

<?php

return [
    &#39;log_request_details&#39; => 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']
];
Copy after login

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
Copy after login

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
Copy after login

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/).

Related recommendations: The latest five Laravel video tutorials

The above is the detailed content of An extension package is highly recommended: Laravel Log Enhancer. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template