Logging/Saving all DB queries in log file

Submitted by mousavian - 10 years ago

You can find it here as well: https://github.com/mousavian/laravel-4-custom-db-log or you can just simply do: 1. create logger.php in your "app" folder 2. edit "app\start\global.php" file (or local.php), and add this: 3. all logs will be at "app\storage\logs\query.log"

#app\start\global.php
require_once app_path('logger.php');

#app\logger.php
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
if( Config::get('app.debug') === true ){    	
	DB::listen(function($sql, $bindings, $time){
    	$logFile = storage_path('logs/query.log');
		$monolog = new Logger('log');
		$monolog->pushHandler(new StreamHandler($logFile), Logger::INFO);
		$monolog->info($sql, compact('bindings', 'time'));
	});
}