Reputation: 317
Is there any way to log data into another file in laravel 5? Not to standard one? For examle i'd like to use something like this:
Log::info("Some log data", '/path/to/custom/file.log');
Or at least is there a possibility to divide log files basing on the log type.
Log::info("Some log data");
Log::error("Another log data");
So that info and error logs will go to different log files.
Thanks for the help.
Upvotes: 8
Views: 5515
Reputation: 2059
Log::useFiles(base_path() . '/path/to/custom/file.log', 'info');
Log::info('Do log this another PATH');
date_default_timezone_set('Asia/Dhaka');
$data = date('Y-m-d');
$time = date('h-A');
Log::useFiles(base_path() . '/log/'.$data.'/'.$time.'-'info.log', 'info');
Log::info('Do log this another PATH');
on this example every date create a folder with saperate log with hourly.
You can also change single log path & name.
Add below line of code to : bootstrap>>app.php
very bottom above of return $app
;
# SINGLE LOG
$app->configureMonologUsing(function($monolog) use ($app) {
$handler = new Monolog\Handler\StreamHandler($app->storagePath().'/logs/YOUR_SINGLE_LOG_NAME.log');
$handler->setFormatter(new \Monolog\Formatter\LineFormatter(null, null, true, true));
$monolog->pushHandler($handler);
});
Upvotes: 12
Reputation: 7152
See https://laravel.com/docs/5.2/errors#configuration specifically Custom Monolog Configuration section.
Follow those directions to override default configuration then following these directions to configure Monolog handlers.
Should be something like:
$app->configureMonologUsing(function($monolog) {
$monolog->pushHandler(new StreamHandler(__DIR__.'/my_app.log', Logger::DEBUG));
});
Should get you in the right direction.
Upvotes: 2