【问题标题】:How can I put Log in controller in laravel project?如何将 Log in 控制器放入 laravel 项目?
【发布时间】:2020-05-01 18:51:36
【问题描述】:

我正在寻找一种将日志放入 Laravel 控制器功能的方法。 我应该把日志功能放在哪里?我在哪里可以找到日志? {Project_name}/storage/logs/laravel.log 中有任何日志 我想记录一下请求值是否都正确。

.env 的设置好像是 APP_DEBUG=true

namespace App\Http\Controllers;

use App\Article;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class StackOvefFloeController extends Controller
{

    public function store(ScheduleRequest $request)
    {
        $schedules = DB::table('schedules')->get();

        $request->date;
        $request->hours;
        //Where Should I put Log functions? Where Can I find the log?

        Log::info('start hpirs'. $request->hours);
        dd($request->start_hours);
        error_log('start hpirs'. $request->start_hours);

        return view('debug', ['schedules' => $schedules]);
    }
<div class = "test">
    <form method="POST" action="{{ route('debug.store') }}">
      @csrf
        <input type="checkbox" class="date"" name="available_date" value="2015-05-22">
        <input class="checkbox" type="checkbox" name="hours" value="8">8
        <button type ="submit">SEND</button></form>
</div>

【问题讨论】:

  • 没关系,如果您在控制器中设置Log::info('start hpirs: '. $request-&gt;hours);,日志将在{Project_name}/storage/logs/laravel.log 文件中
  • 我注意到该页面没有链接到“调试”。单击“发送”按钮后,我的浏览器重新加载了该页面。我的意思是,它似乎没有调用存储功能.

标签: php laravel


【解决方案1】:

这种方式正确:Log::info('message');

您可以每天使用此代码设置 .env 文件中的日志文件:APP_LOG=daily

【讨论】:

    猜你喜欢
    • 2018-03-02
    • 1970-01-01
    • 1970-01-01
    • 2014-09-28
    • 1970-01-01
    • 2017-04-06
    • 1970-01-01
    • 2018-03-27
    相关资源
    最近更新 更多