Laravel log messages/errors on daily basis and type wise

Viewed 721

Is there any solution in Laravel to log all the messages type wise and on daily basis?

Something like below:

  • laravel-2017-08-09-info.log
  • laravel-2017-08-09-error.log
  • laravel-2017-08-09-critical.log
  • laravel-2017-08-10-info.log
  • laravel-2017-08-10-error.log

The daily Laravel log creates only 1 file but not type wise. There are other solutions available in stack overflow but they create type wise files but not on daily basis.

1 Answers

Turns out, there was no out of box support from Laravel and this kind of plugin was yet to develop (at least this is what I could find out).

It may be against the rule to give references of own publications/materials, in that case apologies in advance but I have created my own small work and pushed to my GIT hub repository. You can check that out and let me know if any issues in the code.

EDIT:

To those, who does not want to integrate a module can quickly look into following steps:

  1. Open your config/logging.php and add custom index which indicates a custom driver and handler class.
  2. Set LOG_CHANNEL in env file as custom.
  3. Create App\Logging directory and add Logger and Handler files which will invoke custom handler function whenever you use Log class of Laravel.
  4. Run command composer dump-autoload

For more information, you can look into the GIT hub repository I have provided above and log issues/enhancements over there.

Related