日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

laravel翻看php日志,关于Laravel的日志用法

發(fā)布時間:2025/3/19 php 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 laravel翻看php日志,关于Laravel的日志用法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

這篇文章主要介紹了Laravel日志用法,結合實例形式較為詳細的分析了Laravel日志的功能、定義、使用方法與相關注意事項,需要的朋友可以參考下

本文實例講述了Laravel日志用法。分享給大家供大家參考,具體如下:

這里使用的Laravel版本仍是5.2

日志是非常重要的。本地開發(fā)可以開啟調試模式,但是上線的項目查看日志是非常簡潔有效的調試手段。Laravel集成了Monolog日志庫以便提供多種功能強大的日志處理器。

Laravel支持日志方法single, daily, syslog 和 errorlog。例如,如果你想要日志文件按日生成而不是生成單個文件,應該在配置文件config/app.php中設置log值如下:

'log' => 'daily'

系統(tǒng)默認配置為single

#config/app.php:111

'log' => env('APP_LOG', 'single'),

下面我們看下Laravel是如何配置日志的。

#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',

];

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

}

}

如果自定義Monolog配置,走if條件,默認走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') #存儲級別

);

}

這里useFiles方法是注冊signle文件日志處理程序,并設置存儲文件以及存儲的級別。

下面是初始化日志時的4種日志處理注冊方式。

public function useFiles($path, $level = 'debug') #單一文件

public function useDailyFiles($path, $days = 0, $level = 'debug') #每日生成

public function useSyslog($name = 'laravel', $level = 'debug') #系統(tǒng)日志的方式

public function useErrorLog($level = 'debug', $messageType = ErrorLogHandler::OPERATING_SYSTEM) #等同于php的error_log方式

日志初始化信息基本上就是上面這些。

你可以使用Log門面編寫日志信息到日志中:

八種日志級別:emergency, alert, critical, error,warning, notice, info 和 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);

以上就是本文的全部內容,希望對大家的學習有所幫助,更多相關內容請關注PHP中文網(wǎng)!

相關推薦:

總結

以上是生活随笔為你收集整理的laravel翻看php日志,关于Laravel的日志用法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。