Creating a Custom Log in Laravel

Logging to custom log files could be really helpful in certain scenarios. Some of them being:

  1. Parsing logs for sending data to the analytics systems or to the customer servicing systems.
  2. Feeding failure data for reprocessing by the CRON based Jobs.

Creating a custom log in Laravel 9 is straightforward.

Add the following to the config/logging.php file

	'custom'  =>  [
		'driver'  =>  'single',
		'path'  =>  storage_path('logs/custom.log'),
		'level'  =>  'alert',
	],

Any logging that you’d now do on alert level would be visible in the custom.log file.