The examples in this article describe the Laravel log usage. Share to everyone for your reference, specific as follows:
The Laravel version used here is still 5.2.
The log is very important. Local development can open debug mode, but the on-line Project view log is very simple and effective debugging means. Laravel integrates the Monolog log library to provide a wide range of powerful log processors.
Laravel support Log Methods single, daily, Syslog and errorlog. For example, if you want the log file to be generated on a daily basis instead of generating a single file, you should set the log value in the configuration file config/app.php as follows:
System default configuration is single
#config/app.php:111
' log ' => env (' App_log ', ' single '),
Let's look at how Laravel configures the log.
#vendor/laravel/framework/src/illuminate/foundation/http/kernel.php:36 protected $bootstrappers = [' illuminate\ Foundation\bootstrap\detectenvironment ', ' illuminate\foundation\bootstrap\loadconfiguration ', ' Illuminate\ Foundation\bootstrap\configurelogging ', ' illuminate\foundation\bootstrap\handleexceptions ', ' Illuminate\ Foundation\bootstrap\registerfacades ', ' illuminate\foundation\bootstrap\registerproviders ', ' Illuminate\
Foundation\bootstrap\bootproviders ',];
<?php namespace Illuminate\foundation\bootstrap;
Use Illuminate\log\writer;
Use Monolog\logger as Monolog;
Use illuminate\contracts\foundation\application;
Class Configurelogging {/** * Bootstrap the given application. * * @param \illuminate\contracts\foundation\application $app * @return void */Public Function bootstrap (application $a
PP) {$log = $this->registerlogger ($app); If a custom Monolog configurator has been registered for the application//We'll call that, passing MOnolog along.
Otherwise, we'll grab the//the configurations for the "log system" and use it for configuration. if ($app->hasmonologconfigurator ()) {Call_user_func ($app->getmonologconfigurator (), $log->getmonolog (
)
);
else {$this->configurehandlers ($app, $log);
}
}
If custom monolog configuration, go if condition, default walk else
protected function Configurehandlers (application $app, Writer $log)
{
$method = ' Configure '. Ucfirst ($app [' Config ' [' App.log ']]. ' Handler ';
$this->{$method} ($app, $log);
/**
* Configure the Monolog handlers for the application.
* *
@param \illuminate\contracts\foundation\application $app
* @param \illuminate\log\writer $log
* return void
*
/protected function Configuresinglehandler (application $app, Writer $log)
{
$log- >usefiles (
$app->storagepath (). ' /logs/laravel.log ', #存储文件
$app->make (' config ')->get (' App.log_level ', ' Debug ') #存储级别
);
}
The Usefiles method here is to register the Signle file log handler and set the level of storage files and storage.
The following are 4 types of log processing registrations when the log is initialized.
The Public Function usefiles ($path, $level = ' Debug ') #单一文件 the public
function Usedailyfiles ($path, $days = 0, $level = ' Debu G ') #每日生成 public
function usesyslog ($name = ' Laravel ', $level = ' Debug ') #系统日志的方式 the public
function Useerrorlog ($le Vel = ' Debug ', $messageType = Errorloghandler::operating_system) #等同于php的error_log方式
Log initialization information is basically the top of these.
You can use log façade to write logging information to the log:
Eight log levels: Emergency, alert, critical, error,warning, notice, info, and Debug.
Log::emergency ($error);
Log::alert ($error);
Log::critical ($error);
Log::error ($error);
Log::warning ($error);
Log::notice ($error);
Log::info ($error);
Log::d ebug ($error);
More interested in laravel related content readers can view the site topics: "Laravel Framework Introduction and Advanced Course", "PHP Excellent Development Framework Summary", "Smarty Template Primer Tutorial", "PHP date and Time usage summary", "PHP object-oriented Program Design Introductory Course ", PHP string (String) Usage summary," PHP+MYSQL Database operation Introduction Tutorial "and" PHP common database Operation Skills Summary "
I hope this article will help you with your PHP programming based on the Laravel framework.