1.php 安装mongodb 扩展
2.在laravel根目录,执行composer require mongodb/mongodb
3.在logging.php 配置mongodb驱动
'mongodb' => [
'driver' => 'monolog',
'handler' => Monolog\Handler\MongoDBHandler::class,
'formatter' => 'default',
'handler_with' => [
'mongodb' => new Client("mongodb://localhost:27017"),
'database' => "mongolog",
'collection' => "logs",
],
],
4.测试
执行php artisan tinker
输入:Log::warning("mongolog test");
查看mongodb 数据库结果:
use mongolog;
db.logs.find()
[
{
"_id": {"$oid": "5f2789d82e933325a57cf5d2"},
"channel": "local",
"context": {
"exception": {
"class": "Symfony\\Component\\Console\\Exception\\CommandNotFoundException",
"message": "Command \"think\" is not defined.",
"code": 0,
"file": "/home/gordon/workspace/php/blog/vendor/symfony/console/Application.php:644",
"trace": "#0 /home/gordon/workspace/php/blog/vendor/symfony/console/Application.php(228): Symfony\\Component\\Console\\Application->find('think')\n#1 /home/gordon/workspace/php/blog/vendor/symfony/console/Application.php(140): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#2 /home/gordon/workspace/php/blog/vendor/laravel/framework/src/Illuminate/Console/Application.php(93): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#3 /home/gordon/workspace/php/blog/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#4 /home/gordon/workspace/php/blog/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#5 {main}"
}
},
"datetime": {"$date": "2020-08-03T03:51:52.847Z"},
"extra": [],
"level": 400,
"level_name": "ERROR",
"message": "Command \"think\" is not defined."
},
{
"_id": {"$oid": "5f2789f2f4f0b727732172d2"},
"channel": "local",
"context": [],
"datetime": {"$date": "2020-08-03T03:52:18.395Z"},
"extra": [],
"level": 300,
"level_name": "WARNING",
"message": "12312"
}
]
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。