Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 log data to another file

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.

like image 430
el valuta Avatar asked Aug 11 '16 20:08

el valuta


People also ask

How do I put logs in Laravel?

Laravel logging is based on "channels". Each channel represents a specific way of writing log information. For example, the single channel writes log files to a single log file, while the slack channel sends log messages to Slack. Log messages may be written to multiple channels based on their severity.

Where are Laravel logs stored?

By default, Laravel is configured to create a single log file for your application, and this file is stored in app/storage/logs/laravel. log .

What is log :: info in Laravel?

The Laravel logging facilities provide a simple layer on top of the powerful Monolog library. By default, Laravel is configured to create daily log files for your application which are stored in the storage/logs directory. You may write information to the log like so: Log::info('This is some useful information. ');

How do I enable errors in Laravel?

Through your config/app. php , set 'debug' => env('APP_DEBUG', false), to true . Or in a better way, check out your . env file and make sure to set the debug element to true.


1 Answers

Here is example:

Log::useFiles(base_path() . '/path/to/custom/file.log', 'info');
Log::info('Do log this another PATH');

Another way

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.

Regarding Laravel 5:

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);
    });
like image 190
Rashedul Islam Sagor Avatar answered Oct 06 '22 00:10

Rashedul Islam Sagor