Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Emir Karsiyakali:
Quick Tip - Logging Mastery with Laravel
Jul 02, 2018 @ 18:54:11

In this new post to his site Emir Karsiyakali shares a quick tip for the Laravel users out there to improve your logging output and make following requests easier.

Putting unique id to requests one of my silver bullet while designing RESTful APIs. It provides an extremely easy way to follow each request’s lifecycle while debugging. In this guide I’ll show you how you can add it to your log files on Laravel 5.6.

Under the hood, Laravel utilizes the Monolog library, which provides support for a variety of powerful log handlers. Laravel makes it a cinch to configure these handlers, allowing you to mix and match them to customize your application’s log handling.

He starts with adding the "tap" value to the logger configuration and pointing it to a newly created LocalLogger class. He shows the implementation of this logger class including a custom log formatter that will modify the log string to add the unique ID after the "datetime" value. He also includes some usage examples in your Laravel code, putting the Log::info line into a LogRequestResponse middleware to be executed on each request.

tagged: laravel tutorial log unique id monolog

Link: https://emirkarsiyakali.com/quick-tip-logging-mastery-with-laravel-7282988032a7


Trending Topics: