How to Log object?

后端 未结 5 2113
渐次进展
渐次进展 2021-02-01 13:21

I can see that Log facade is very useful. In the docs of laravel:

The logger provides the eight logging levels defined in RFC 5424: emergency, alert, cr

5条回答
  •  遇见更好的自我
    2021-02-01 13:53

    No.

    The first parameter must be a string (or a string object representation). If you wish to pass any other type of (raw) data or objects, you can always JSON encode them, and push them in the context settings, like so:

     $user->toJson()]);
    

    Or:

    id}";
        }
    }
    
    // [...]
    $user = User::find($user_id);
    
    \Log::error("Something happened to User {$user}.", ['object' => $user->toJson()]);
    

    You can find more information about the method signatures here.

提交回复
热议问题