Create Log File On External Server-Laravel

- 1 answer

Folks, I've Googled, but nothing came out handy.

I want to create custom Log file using Laravel(5.1), why I want, I've multiple locations where same code will be executed, so it'll be pretty hard to visit each location and view Log file. Currently, writing stuff to default Laravel.log file, working fine, but want to create some custom abc.log file to handle all custom logs.




Laravel uses the Monolog package to handle logging. You can add handlers to the Monolog instance to do all sorts of interesting things with your log messages.

In the documentation on Logging, instructions are given on how to access the underlying Monolog instance. Once you do that, you can:

  • add "Handlers" to the logger which can send messages to other logging systems, write them to the file system, send emails/SMS messages, ...

  • add "Formatters" to the logger which will reformat the message however you like (HTML, text, or a format for a particular message recipient like Gelf or Loggly)

  • add "Processors" which will add additional information to the messages, such as IP addresses, system stats, etc.

I have (in the past) implemented the GelfHandler to push messages to a Graylog server. It's pretty easy to set up. There's a good explanation over on Laracasts.