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!
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!