About Laravel log usage
This article mainly introduces the usage of Laravel logs, and analyzes the functions, definitions, usage methods and related precautions of Laravel logs in detail in the form of examples. Friends in need can refer to the following
Examples of this article Laravel log usage. Share it with everyone for your reference, the details are as follows:
The Laravel version used here is still 5.2
The log is very important. Debug mode can be turned on for local development, but viewing logs for online projects is a very simple and effective way to debug. Laravel integrates the Monolog logging library to provide a variety of powerful log processors.
Laravel supports log methods single, daily, syslog and errorlog. For example, if you want log files 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:
'log' => 'daily'
The system default configuration is single
#config/app.php:111 'log' => env('APP_LOG', 'single'),
Let’s take a look at how Laravel configures logs.
#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 $app) { $log = $this->registerLogger($app); // If a custom Monolog configurator has been registered for the application // we will call that, passing Monolog along. Otherwise, we will 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 you customize the Monolog configuration, use the if condition, and the default is 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 storage file and storage level.
The following are four log processing registration methods when initializing logs.
public function useFiles($path, $level = 'debug') #单一文件 public function useDailyFiles($path, $days = 0, $level = 'debug') #每日生成 public function useSyslog($name = 'laravel', $level = 'debug') #系统日志的方式 public function useErrorLog($level = 'debug', $messageType = ErrorLogHandler::OPERATING_SYSTEM) #等同于php的error_log方式
The log initialization information is basically the above.
You can use the Log facade to write log information into 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::debug($error);
The above is the entire content of this article. I hope it will be helpful to everyone’s study. Please pay attention to more related content. PHP Chinese website!
Related recommendations:
About the use of cookies in Laravel5
Learn several usages of laravel’s model events
The above is the detailed content of About Laravel log usage. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Laravel - Artisan Commands - Laravel 5.7 comes with new way of treating and testing new commands. It includes a new feature of testing artisan commands and the demonstration is mentioned below ?

Laravel - Pagination Customizations - Laravel includes a feature of pagination which helps a user or a developer to include a pagination feature. Laravel paginator is integrated with the query builder and Eloquent ORM. The paginate method automatical

Method for obtaining the return code when Laravel email sending fails. When using Laravel to develop applications, you often encounter situations where you need to send verification codes. And in reality...

Laravel schedule task run unresponsive troubleshooting When using Laravel's schedule task scheduling, many developers will encounter this problem: schedule:run...

The method of handling Laravel's email failure to send verification code is to use Laravel...

How to implement the table function of custom click to add data in dcatadmin (laravel-admin) When using dcat...

Laravel - Dump Server - Laravel dump server comes with the version of Laravel 5.7. The previous versions do not include any dump server. Dump server will be a development dependency in laravel/laravel composer file.

The impact of sharing of Redis connections in Laravel framework and select methods When using Laravel framework and Redis, developers may encounter a problem: through configuration...
