While I was working on a Laravel project, I wanted to log RazorPay events to a separate file. This is because I wanted to keep the main log file clean and organized, and separate the RazorPay events from other log messages. So in this little snippet article, I'll show you how to create a custom log file in Laravel.
Open the config/logging.php file and add a new channel to the channels array. Here's an example:
Here, we've added a new channel called razorpay to the channels array. The driver is set to single, which means that only one log file will be created. The path is set to storage_path('logs/razorpay.log'), which means that the log file will be stored in the storage/logs directory.
Create a new file called razorpay.log in the storage/logs directory. This file will be used to log RazorPay events.
Make sure you set the correct permissions for the file. You can use the following command to set the permissions:
Now that we have created the log file and set the permissions, we can start logging events to it. For example, let's log a message to the razorpay channel:
In this example, we're using the Log facade to log a message to the razorpay channel. We can adjust the log level (info, debug, error, etc.) as per our requirements.
In this snippet article, we learned how to create a custom log file in Laravel, and how to log events to it. This can be useful when you want to keep the main log file clean and organized, and separate the events from other log messages.
Remember to regularly monitor and manage your log files to ensure they are not growing too large and affecting the performance of your application.
Keep coding, keep exploring, and keep inspiring. 🐼