YoungInnovations' Blog

An insight into our technology, inspiration, perspective and culture.

Follow publication

Logging with loggly in Laravel

Ashok Adhikari
YoungInnovations' Blog
2 min readJun 25, 2016

--

To develop healthy application, maintaining log is very important. It is important for :

  • detailing every activities performed in the application;
  • listing of errors and enabling proper troubleshooting;
  • tracking users’ behavior towards the application and more

By default, Laravel uses the PHP monolog logging library for logging and saves the logs in a file inside application’s local directory (storage/logs). But in production environment, it may create problem by gradually taking up storage space.

Hence, using cloud logging platform such as Loggly would be wise as well as simple with Laravel.

Steps to use Loggly

Step I: Create a free account in Loggly and generate a token for php logs.

Customer tokens section in loggly

Step II: Define application log type as custom in config/app.php file in your application. (I used laravel 5.2) ,

‘log’ => env(‘APP_LOG’, ‘custom’),

Step III: To override the default ConfigureLogging class, create a new ConfigureLogging class with different namespace. Then add configureCustomHandler method.

Custom ConfigureLogging class

Step IV: Update Kernel.php file inside app/Http folder. Override $bootstrappers variable of HttpKernel class by replacing default ConfigureLogging class path with the new ConfigureLogging class path.

Step V: Finally, add the following code in bootstrap/app.php file :

Now, you are ready to save your application’s log in Loggly. You can use LoggerInterface to log the activities. For example, I wrote the following functions (in the picture) inside HomeController but you can write them inside any class.

Logging in HomeCntrolle
Saved log in loggly

Also, you can configure for Logentries by using LogentriesHandler and token from logentries instead of LogglyHandler and loggly token.

If you want to look into the source code, follow the link below:
https://github.com/younginnovations/loggign-loggly-laravel

Happy logging :)

--

--

Published in YoungInnovations' Blog

An insight into our technology, inspiration, perspective and culture.

Responses (2)

Write a response