Home  >  Article  >  PHP Framework  >  Two ways to record logs in Laravel

Two ways to record logs in Laravel

藏色散人
藏色散人forward
2020-06-30 11:29:566500browse

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');

For example:

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

Laravel method

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

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!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete