# laravel 記錄和調試 https://hackmd.io/@javck/ByJgF8HRP/%2F_IQ5jsuKSniV4uyYAbAZPQ ## 使用參數記錄 Log::info()或info()帶有附加參數的更短消息,以獲取有關所發生事件的更多上下文。 ``` Log::info('User failed to login.', ['id' => $user->id]); ``` ## 更方便的DD dd($result)您可以將->dd()作為方法直接放在 Eloquent 句子或任何 Collection 的末尾,而不是這樣做 ``` // Instead of $users = User::where('name', 'Taylor')->get(); dd($users); // Do this $users = User::where('name', 'Taylor')->get()->dd(); ``` ## 使用上下文記錄 Laravel 8.49 新功能:Log::withContext()將幫助您區分不同請求之間的日誌消息。 如果您創建一個中間件並設置此上下文,則所有日誌消息都將包含該上下文,您將能夠更輕鬆地搜索它們。 ``` public function handle(Request $request, Closure $next) { $requestId = Str::uuid(); Log::withContext(['request-id' => $requestId]); $response = $next($request); $response->header('request-id', $requestId); return $response; } ``` ###### tags: `Laravel`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up