Back

laraverl custom logs


tzookb posted 3 years ago

Tried to find some docs but nothing.

I want to create several log files, for example: click log, views log etc.

How can I create several log files by different name.

and second question can I log my own line, like a big json row, instead of the ordinary log-warning/error/... structure?

rizqidjamaluddin replied 3 years ago

Laravel ships with Monolog as far as I can remember, go ahead and check that out. Monolog is really flexible and gives you a ton of control.

If you want to use Monolog's advanced features, I assume you can just do it out of the box as advertised:

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$view_log = new Logger('View Logs');
$view_log->pushHandler(new StreamHandler('path/to/log.log', Logger::INFO));

$view_log->addInfo("User $user clicked");

Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us