Home > PHP Framework > Laravel > body text

Two ways to record logs in Laravel

藏色散人
Release: 2020-06-30 11:30:41
forward
6600 people have browsed it

The following tutorial column of Laravel will introduce to you two ways of recording logs in Laravel. I hope it will be helpful to friends in need!

Two ways to record logs in Laravel

Use the basic usage of Monolog

Official examples to generate log objects and perform Operation

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

// create a log channel
$log = new Logger('name');
$log->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));

// add records to the log
$log->warning('Foo');
$log->error('Bar');
Copy after login

For example:

$log = new Logger('register');
$log->pushHandler(new StreamHandler(storage_path('logs/reg.log'),Logger::INFO) );
$log->addInfo('用户注册信息:'.$input);
Copy after login

Laravel method

Log::useFiles(storage_path().'/logs/laravel.log')->info('用户注册原始数据:',$input);
Copy after login

The above is the detailed content of Two ways to record logs in Laravel. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!