Open twn39 opened 9 years ago
<?php namespace App\Http\Controllers;
use Monolog\Handler\MongoDBHandler;
class HomeController extends Controller {
/*
|--------------------------------------------------------------------------
| Home Controller
|--------------------------------------------------------------------------
|
| This controller renders your application's "dashboard" for users that
| are authenticated. Of course, you are free to change or remove the
| controller as you wish. It is just here to get your app started!
|
*/
private $log;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
$this->log = \Log::getMonolog();
$logHandler = new MongoDBHandler(new \MongoClient(), 'laravel', 'logs');
$this->log->pushHandler($logHandler);
}
/**
* Show the application dashboard to the user.
*
* @return Response
*/
public function index()
{
$this->log->addInfo('mongodb log test');
return view('home');
}
}
将日志存储到mongodb中,可用于日志分析。