基于docker-webman-mangolog实现将日志写入mongodb
This commit is contained in:
parent
c5150821b9
commit
e008a8900d
10
.gitignore
vendored
10
.gitignore
vendored
@ -1,7 +1,3 @@
|
||||
/.idea
|
||||
/.vscode
|
||||
/vendor
|
||||
*.log
|
||||
.env
|
||||
/tests/tmp
|
||||
/tests/.phpunit.result.cache
|
||||
!.gitignore
|
||||
.idea
|
||||
.vscode
|
7
api/.gitignore
vendored
Normal file
7
api/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
/.idea
|
||||
/.vscode
|
||||
/vendor
|
||||
*.log
|
||||
.env
|
||||
/tests/tmp
|
||||
/tests/.phpunit.result.cache
|
26
api/app/controller/TestController.php
Normal file
26
api/app/controller/TestController.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use Wandoubaba\Res;
|
||||
use support\Request;
|
||||
use support\Container;
|
||||
use support\Db;
|
||||
use support\Log;
|
||||
|
||||
class TestController
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$res = Container::make(Res::class);
|
||||
// Log::channel('default')->info(__CLASS__ . DIRECTORY_SEPARATOR . __FUNCTION__, $_SERVER);
|
||||
$logs = Db::connection('mongolog')->collection('request')->get();
|
||||
// foreach ($logs as $log) {
|
||||
// $log->delete();
|
||||
// }
|
||||
// $logs->delete();
|
||||
$res->setData($logs);
|
||||
return json($res);
|
||||
}
|
||||
|
||||
}
|
23
api/app/middleware/AccessControl.php
Normal file
23
api/app/middleware/AccessControl.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace app\middleware;
|
||||
|
||||
use Webman\MiddlewareInterface;
|
||||
use Webman\Http\Response;
|
||||
use Webman\Http\Request;
|
||||
|
||||
class AccessControl implements MiddlewareInterface
|
||||
{
|
||||
public function process(Request $request, callable $handler): Response
|
||||
{
|
||||
$response = $request->method() == 'OPTIONS' ? response('') : $handler($request);
|
||||
$response->withHeaders([
|
||||
'Access-Control-Allow-Credentials' => 'true',
|
||||
'Access-Control-Allow-Origin' => $request->header('Origin', '*'),
|
||||
'Access-Control-Allow-Methods' => '*',
|
||||
'Access-Control-Allow-Headers' => '*,ACCESSTOKEN',
|
||||
]);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
68
api/app/middleware/RequestLog.php
Normal file
68
api/app/middleware/RequestLog.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
namespace app\middleware;
|
||||
|
||||
use support\Log;
|
||||
use Webman\MiddlewareInterface;
|
||||
use Webman\Http\Response;
|
||||
use Webman\Http\Request;
|
||||
|
||||
class RequestLog implements MiddlewareInterface
|
||||
{
|
||||
/**
|
||||
* 需要中间件拦截的控制器清单,全部小写
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $controllerScope = [
|
||||
'app\controller\indexcontroller',
|
||||
'app\controller\testcontroller',
|
||||
];
|
||||
|
||||
/**
|
||||
* 在拦截的控制器中不需要被拦截的例外方法,如用户登录
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $actionWhiteList = [
|
||||
'app\controller\testcontroller\index', // oss里的download不校验
|
||||
];
|
||||
|
||||
public function process(Request $request, callable $next) : Response
|
||||
{
|
||||
$controller = strtolower($request->controller);
|
||||
$action = strtolower($request->action);
|
||||
$path = "{$controller}\\{$action}"; // 完整的控制器\方法字符串
|
||||
// 白名单方法的请求不拦截
|
||||
if (in_array($path, $this->actionWhiteList)) {
|
||||
return $next($request);
|
||||
}
|
||||
// 只拦截指定控制器的请求
|
||||
if (!in_array($controller, $this->controllerScope)) {
|
||||
return $next($request);
|
||||
}
|
||||
$info = [
|
||||
'session_id' => $request->sessionId(),
|
||||
'protocol_version' => $request->protocolVersion(),
|
||||
'method' => $request->method(),
|
||||
'ip' => $request->getRemoteIp(),
|
||||
'real_ip' => $request->getRealIp(),
|
||||
'host' => $request->host(),
|
||||
'path' => $request->path(),
|
||||
'uri' => $request->uri(),
|
||||
'url' => $request->url(),
|
||||
'full_url' => $request->fullUrl(),
|
||||
'query_string' => $request->queryString(),
|
||||
'get_params' => $request->get(),
|
||||
'post_params' => $request->post(),
|
||||
'local_ip' => $request->getLocalIp(),
|
||||
'local_port' => $request->getLocalPort(),
|
||||
'is_ajax' => $request->isAjax(),
|
||||
'is_pjax' => $request->isPjax(),
|
||||
'expects_json' => $request->expectsJson(),
|
||||
'accept_json' => $request->acceptJson(),
|
||||
];
|
||||
Log::channel('request')->info('', $info);
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
0
build/.gitignore → api/build/.gitignore
vendored
0
build/.gitignore → api/build/.gitignore
vendored
@ -26,7 +26,7 @@
|
||||
"require": {
|
||||
"php": ">=7.2",
|
||||
"workerman/webman-framework": "^1.5.0",
|
||||
"monolog/monolog": "^2.0",
|
||||
"monolog/monolog": "^3.0",
|
||||
"vlucas/phpdotenv": "^5.5",
|
||||
"illuminate/database": "^10.0",
|
||||
"illuminate/pagination": "^10.0",
|
||||
@ -34,7 +34,8 @@
|
||||
"symfony/var-dumper": "^6.0",
|
||||
"illuminate/redis": "^10.0",
|
||||
"wandoubaba/res": "^1.0",
|
||||
"webman/console": "^1.2"
|
||||
"webman/console": "^1.2",
|
||||
"mongodb/laravel-mongodb": "^4.1"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-event": "For better performance. "
|
348
composer.lock → api/composer.lock
generated
348
composer.lock → api/composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "40e690c07a34d05e3eb1432d45aa0852",
|
||||
"content-hash": "b60184ef23f8e71843aa7695eed31518",
|
||||
"packages": [
|
||||
{
|
||||
"name": "brick/math",
|
||||
@ -933,6 +933,65 @@
|
||||
},
|
||||
"time": "2023-12-25T01:11:56+00:00"
|
||||
},
|
||||
{
|
||||
"name": "jean85/pretty-package-versions",
|
||||
"version": "2.0.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Jean85/pretty-package-versions.git",
|
||||
"reference": "ae547e455a3d8babd07b96966b17d7fd21d9c6af"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Jean85/pretty-package-versions/zipball/ae547e455a3d8babd07b96966b17d7fd21d9c6af",
|
||||
"reference": "ae547e455a3d8babd07b96966b17d7fd21d9c6af",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"composer-runtime-api": "^2.0.0",
|
||||
"php": "^7.1|^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "^2.17",
|
||||
"jean85/composer-provided-replaced-stub-package": "^1.0",
|
||||
"phpstan/phpstan": "^0.12.66",
|
||||
"phpunit/phpunit": "^7.5|^8.5|^9.4",
|
||||
"vimeo/psalm": "^4.3"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Jean85\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Alessandro Lai",
|
||||
"email": "alessandro.lai85@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "A library to get pretty versions strings of installed dependencies",
|
||||
"keywords": [
|
||||
"composer",
|
||||
"package",
|
||||
"release",
|
||||
"versions"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/Jean85/pretty-package-versions/issues",
|
||||
"source": "https://github.com/Jean85/pretty-package-versions/tree/2.0.5"
|
||||
},
|
||||
"time": "2021-10-08T21:21:46+00:00"
|
||||
},
|
||||
{
|
||||
"name": "laravel/serializable-closure",
|
||||
"version": "v1.3.3",
|
||||
@ -994,43 +1053,210 @@
|
||||
"time": "2023-11-08T14:08:06+00:00"
|
||||
},
|
||||
{
|
||||
"name": "monolog/monolog",
|
||||
"version": "2.9.2",
|
||||
"name": "mongodb/laravel-mongodb",
|
||||
"version": "4.1.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Seldaek/monolog.git",
|
||||
"reference": "437cb3628f4cf6042cc10ae97fc2b8472e48ca1f"
|
||||
"url": "https://github.com/mongodb/laravel-mongodb.git",
|
||||
"reference": "5c16d0ec3aee352987ae9f8fe70914357d23badc"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/437cb3628f4cf6042cc10ae97fc2b8472e48ca1f",
|
||||
"reference": "437cb3628f4cf6042cc10ae97fc2b8472e48ca1f",
|
||||
"url": "https://api.github.com/repos/mongodb/laravel-mongodb/zipball/5c16d0ec3aee352987ae9f8fe70914357d23badc",
|
||||
"reference": "5c16d0ec3aee352987ae9f8fe70914357d23badc",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2",
|
||||
"psr/log": "^1.0.1 || ^2.0 || ^3.0"
|
||||
"ext-mongodb": "^1.15",
|
||||
"illuminate/container": "^10.0",
|
||||
"illuminate/database": "^10.30",
|
||||
"illuminate/events": "^10.0",
|
||||
"illuminate/support": "^10.0",
|
||||
"mongodb/mongodb": "^1.15",
|
||||
"php": "^8.1"
|
||||
},
|
||||
"provide": {
|
||||
"psr/log-implementation": "1.0.0 || 2.0.0 || 3.0.0"
|
||||
"replace": {
|
||||
"jenssegers/mongodb": "self.version"
|
||||
},
|
||||
"require-dev": {
|
||||
"aws/aws-sdk-php": "^2.4.9 || ^3.0",
|
||||
"doctrine/coding-standard": "12.0.x-dev",
|
||||
"mockery/mockery": "^1.4.4",
|
||||
"orchestra/testbench": "^8.0",
|
||||
"phpstan/phpstan": "^1.10",
|
||||
"phpunit/phpunit": "^10.3",
|
||||
"spatie/laravel-query-builder": "^5.6"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"MongoDB\\Laravel\\MongoDBServiceProvider",
|
||||
"MongoDB\\Laravel\\MongoDBQueueServiceProvider"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"MongoDB\\Laravel\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Andreas Braun",
|
||||
"email": "andreas.braun@mongodb.com",
|
||||
"role": "Leader"
|
||||
},
|
||||
{
|
||||
"name": "Jérôme Tamarelle",
|
||||
"email": "jerome.tamarelle@mongodb.com",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Jeremy Mikola",
|
||||
"email": "jmikola@gmail.com",
|
||||
"role": "Maintainer"
|
||||
},
|
||||
{
|
||||
"name": "Jens Segers",
|
||||
"homepage": "https://jenssegers.com",
|
||||
"role": "Creator"
|
||||
}
|
||||
],
|
||||
"description": "A MongoDB based Eloquent model and Query builder for Laravel",
|
||||
"homepage": "https://github.com/mongodb/laravel-mongodb",
|
||||
"keywords": [
|
||||
"database",
|
||||
"eloquent",
|
||||
"laravel",
|
||||
"model",
|
||||
"mongo",
|
||||
"mongodb"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://www.mongodb.com/support",
|
||||
"security": "https://www.mongodb.com/security",
|
||||
"source": "https://github.com/mongodb/laravel-mongodb/tree/4.1.1"
|
||||
},
|
||||
"time": "2024-01-17T10:04:05+00:00"
|
||||
},
|
||||
{
|
||||
"name": "mongodb/mongodb",
|
||||
"version": "1.17.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mongodb/mongo-php-library.git",
|
||||
"reference": "9d9c917cf7ff275ed6bd63c596efeb6e49fd0e53"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/mongodb/mongo-php-library/zipball/9d9c917cf7ff275ed6bd63c596efeb6e49fd0e53",
|
||||
"reference": "9d9c917cf7ff275ed6bd63c596efeb6e49fd0e53",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-hash": "*",
|
||||
"ext-json": "*",
|
||||
"ext-mongodb": "^1.17.0",
|
||||
"jean85/pretty-package-versions": "^2.0.1",
|
||||
"php": "^7.4 || ^8.0",
|
||||
"psr/log": "^1.1.4|^2|^3",
|
||||
"symfony/polyfill-php80": "^1.27",
|
||||
"symfony/polyfill-php81": "^1.27"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/coding-standard": "^12.0",
|
||||
"rector/rector": "^0.18",
|
||||
"squizlabs/php_codesniffer": "^3.7",
|
||||
"symfony/phpunit-bridge": "^5.2",
|
||||
"vimeo/psalm": "^5.13"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.17.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/functions.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"MongoDB\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"Apache-2.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Andreas Braun",
|
||||
"email": "andreas.braun@mongodb.com"
|
||||
},
|
||||
{
|
||||
"name": "Jeremy Mikola",
|
||||
"email": "jmikola@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Jérôme Tamarelle",
|
||||
"email": "jerome.tamarelle@mongodb.com"
|
||||
}
|
||||
],
|
||||
"description": "MongoDB driver library",
|
||||
"homepage": "https://jira.mongodb.org/browse/PHPLIB",
|
||||
"keywords": [
|
||||
"database",
|
||||
"driver",
|
||||
"mongodb",
|
||||
"persistence"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/mongodb/mongo-php-library/issues",
|
||||
"source": "https://github.com/mongodb/mongo-php-library/tree/1.17.0"
|
||||
},
|
||||
"time": "2023-11-15T09:21:50+00:00"
|
||||
},
|
||||
{
|
||||
"name": "monolog/monolog",
|
||||
"version": "3.5.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Seldaek/monolog.git",
|
||||
"reference": "c915e2634718dbc8a4a15c61b0e62e7a44e14448"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/c915e2634718dbc8a4a15c61b0e62e7a44e14448",
|
||||
"reference": "c915e2634718dbc8a4a15c61b0e62e7a44e14448",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.1",
|
||||
"psr/log": "^2.0 || ^3.0"
|
||||
},
|
||||
"provide": {
|
||||
"psr/log-implementation": "3.0.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"aws/aws-sdk-php": "^3.0",
|
||||
"doctrine/couchdb": "~1.0@dev",
|
||||
"elasticsearch/elasticsearch": "^7 || ^8",
|
||||
"ext-json": "*",
|
||||
"graylog2/gelf-php": "^1.4.2 || ^2@dev",
|
||||
"guzzlehttp/guzzle": "^7.4",
|
||||
"graylog2/gelf-php": "^1.4.2 || ^2.0",
|
||||
"guzzlehttp/guzzle": "^7.4.5",
|
||||
"guzzlehttp/psr7": "^2.2",
|
||||
"mongodb/mongodb": "^1.8",
|
||||
"php-amqplib/php-amqplib": "~2.4 || ^3",
|
||||
"phpspec/prophecy": "^1.15",
|
||||
"phpstan/phpstan": "^0.12.91",
|
||||
"phpunit/phpunit": "^8.5.14",
|
||||
"predis/predis": "^1.1 || ^2.0",
|
||||
"rollbar/rollbar": "^1.3 || ^2 || ^3",
|
||||
"phpstan/phpstan": "^1.9",
|
||||
"phpstan/phpstan-deprecation-rules": "^1.0",
|
||||
"phpstan/phpstan-strict-rules": "^1.4",
|
||||
"phpunit/phpunit": "^10.1",
|
||||
"predis/predis": "^1.1 || ^2",
|
||||
"ruflin/elastica": "^7",
|
||||
"swiftmailer/swiftmailer": "^5.3|^6.0",
|
||||
"symfony/mailer": "^5.4 || ^6",
|
||||
"symfony/mime": "^5.4 || ^6"
|
||||
},
|
||||
@ -1053,7 +1279,7 @@
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "2.x-dev"
|
||||
"dev-main": "3.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
@ -1081,7 +1307,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/Seldaek/monolog/issues",
|
||||
"source": "https://github.com/Seldaek/monolog/tree/2.9.2"
|
||||
"source": "https://github.com/Seldaek/monolog/tree/3.5.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@ -1093,7 +1319,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2023-10-27T15:25:26+00:00"
|
||||
"time": "2023-10-27T15:32:31+00:00"
|
||||
},
|
||||
{
|
||||
"name": "nesbot/carbon",
|
||||
@ -2231,6 +2457,82 @@
|
||||
],
|
||||
"time": "2023-01-26T09:26:14+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-php81",
|
||||
"version": "v1.29.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-php81.git",
|
||||
"reference": "c565ad1e63f30e7477fc40738343c62b40bc672d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/c565ad1e63f30e7477fc40738343c62b40bc672d",
|
||||
"reference": "c565ad1e63f30e7477fc40738343c62b40bc672d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"name": "symfony/polyfill",
|
||||
"url": "https://github.com/symfony/polyfill"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Php81\\": ""
|
||||
},
|
||||
"classmap": [
|
||||
"Resources/stubs"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"polyfill",
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/polyfill-php81/tree/v1.29.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-01-29T20:11:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/service-contracts",
|
||||
"version": "v3.4.1",
|
@ -46,5 +46,18 @@ return [
|
||||
'schema' => env('PG_SCHEMA', 'public'),
|
||||
'sslmode' => 'prefer',
|
||||
],
|
||||
'mongolog' => [
|
||||
'driver' => 'mongodb',
|
||||
'host' => env('MONGOLOG_HOST', '127.0.0.1'),
|
||||
'port' => env('MONGOLOG_PORT', 27017),
|
||||
'database' => env('MONGOLOG_DATABASE', 'log'),
|
||||
'username' => env('MONGOLOG_USERNAME', null),
|
||||
'password' => env('MONGOLOG_PASSWORD', null),
|
||||
'options' => [
|
||||
// here you can pass more settings to the Mongo Driver Manager
|
||||
// see https://www.php.net/manual/en/mongodb-driver-manager.construct.php under "Uri Options" for a list of complete parameters that you can use
|
||||
'appname' => 'homestead'
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
|
||||
use MongoDB\Client;
|
||||
/**
|
||||
* This file is part of webman.
|
||||
*
|
||||
@ -19,13 +21,21 @@ return [
|
||||
'class' => Monolog\Handler\RotatingFileHandler::class,
|
||||
'constructor' => [
|
||||
runtime_path() . '/logs/webman.log',
|
||||
7, //$maxFiles
|
||||
Monolog\Logger::DEBUG,
|
||||
env('LOG_MAX_FIlES', 7), //$maxFiles
|
||||
Monolog\Level::Debug,
|
||||
],
|
||||
'formatter' => [
|
||||
'class' => Monolog\Formatter\LineFormatter::class,
|
||||
'constructor' => [null, 'Y-m-d H:i:s', true],
|
||||
],
|
||||
], [
|
||||
'class' => Monolog\Handler\MongoDBHandler::class,
|
||||
'constructor' => [
|
||||
new Client(env('MONGOLOG_URL', 'mongodb://localhost:27017')),
|
||||
env('MONGOLOG_DATABASE', 'log'),
|
||||
'default',
|
||||
Monolog\Level::Debug,
|
||||
],
|
||||
]
|
||||
],
|
||||
],
|
||||
@ -36,24 +46,32 @@ return [
|
||||
'constructor' => [
|
||||
runtime_path() . '/logs/debug/debug.log',
|
||||
env('LOG_MAX_FILES_DEBUG') ?: env('LOG_MAX_FIlES') ?: 7, //$maxFiles
|
||||
Monolog\Logger::DEBUG,
|
||||
Monolog\Level::Debug,
|
||||
],
|
||||
'formatter' => [
|
||||
'class' => Monolog\Formatter\LineFormatter::class,
|
||||
'constructor' => [null, 'Y-m-d H:i:s.u', true, true],
|
||||
],
|
||||
], [
|
||||
'class' => Monolog\Handler\MongoDBHandler::class,
|
||||
'constructor' => [
|
||||
new Client(env('MONGOLOG_URL', 'mongodb://localhost:27017')),
|
||||
env('MONGOLOG_DATABASE', 'log'),
|
||||
'debug',
|
||||
Monolog\Level::Debug,
|
||||
],
|
||||
], [
|
||||
// 把日志输出到控制台
|
||||
'class' => Monolog\Handler\StreamHandler::class,
|
||||
'constructor' => [
|
||||
'php://stdout',
|
||||
Monolog\Logger::DEBUG,
|
||||
Monolog\Level::Debug,
|
||||
],
|
||||
'formatter' => [
|
||||
'class' => Monolog\Formatter\LineFormatter::class,
|
||||
'constructor' => [null, 'Y-m-d H:i:s.u', true, true],
|
||||
],
|
||||
],
|
||||
]
|
||||
],
|
||||
],
|
||||
'error' => [
|
||||
@ -63,18 +81,26 @@ return [
|
||||
'constructor' => [
|
||||
runtime_path() . '/logs/error/error.log',
|
||||
env('LOG_MAX_FILES_ERROR') ?: env('LOG_MAX_FIlES') ?: 7, //$maxFiles
|
||||
Monolog\Logger::DEBUG,
|
||||
Monolog\Level::Debug,
|
||||
],
|
||||
'formatter' => [
|
||||
'class' => Monolog\Formatter\LineFormatter::class,
|
||||
'constructor' => [null, 'Y-m-d H:i:s.u', true, true],
|
||||
],
|
||||
], [
|
||||
'class' => Monolog\Handler\MongoDBHandler::class,
|
||||
'constructor' => [
|
||||
new Client(env('MONGOLOG_URL', 'mongodb://localhost:27017')),
|
||||
env('MONGOLOG_DATABASE', 'log'),
|
||||
'error',
|
||||
Monolog\Level::Debug,
|
||||
],
|
||||
], [
|
||||
// 把日志输出到控制台
|
||||
'class' => Monolog\Handler\StreamHandler::class,
|
||||
'constructor' => [
|
||||
'php://stdout',
|
||||
Monolog\Logger::DEBUG,
|
||||
Monolog\Level::Debug,
|
||||
],
|
||||
'formatter' => [
|
||||
'class' => Monolog\Formatter\LineFormatter::class,
|
||||
@ -83,5 +109,18 @@ return [
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
// 记录请求日志
|
||||
'request' => [
|
||||
'handlers' => [
|
||||
[
|
||||
'class' => Monolog\Handler\MongoDBHandler::class,
|
||||
'constructor' => [
|
||||
new Client(env('MONGOLOG_URL', 'mongodb://localhost:27017')),
|
||||
env('MONGOLOG_DATABASE', 'log'),
|
||||
'request',
|
||||
Monolog\Level::Debug,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
@ -12,4 +12,13 @@
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
return [];
|
||||
return [
|
||||
'' => [
|
||||
// 静态文件保护
|
||||
app\middleware\StaticFile::class,
|
||||
// 跨域请求
|
||||
app\middleware\AccessControl::class,
|
||||
// 记录请求日志
|
||||
app\middleware\RequestLog::class,
|
||||
],
|
||||
];
|
12
api/docker-compose.yml
Normal file
12
api/docker-compose.yml
Normal file
@ -0,0 +1,12 @@
|
||||
version: "3.1"
|
||||
|
||||
services:
|
||||
webman-jsonrpc:
|
||||
image: wandoubaba517/workerman:8.1
|
||||
container_name: webman-jsonrpc
|
||||
network_mode: host
|
||||
volumes:
|
||||
- ./:/app/service
|
||||
- ./php.ini:/usr/local/etc/php/php.ini
|
||||
working_dir: /app/service
|
||||
stdin_open: true
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
@ -7,7 +7,7 @@ if [ -z "$1" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
container_name="webman-jsonrpc"
|
||||
container_name="webman-jsonrpc-api"
|
||||
|
||||
if [ "$1" = "stop" ]; then
|
||||
if [ "$(docker inspect -f {{.State.Running}} $container_name 2>/dev/null)" = "true" ]; then
|
@ -1,13 +1,26 @@
|
||||
version: "3.1"
|
||||
|
||||
services:
|
||||
webman-jsonrpc:
|
||||
api:
|
||||
image: wandoubaba517/workerman:8.1
|
||||
container_name: webman-jsonrpc
|
||||
container_name: webman-jsonrpc-api
|
||||
network_mode: host
|
||||
restart: always
|
||||
volumes:
|
||||
- ./:/app/service
|
||||
- ./php.ini:/usr/local/etc/php/php.ini
|
||||
- ./api/:/app/service
|
||||
- ./api/php.ini:/usr/local/etc/php/php.ini
|
||||
working_dir: /app/service
|
||||
stdin_open: true
|
||||
depends_on:
|
||||
- log
|
||||
command: ['php', 'start.php', 'start']
|
||||
|
||||
log:
|
||||
image: mongo:6.0
|
||||
container_name: webman-jsonrpc-log
|
||||
restart: always
|
||||
volumes:
|
||||
- ./log/db:/data/db
|
||||
- ./log/mongod.conf:/etc/mongod.conf
|
||||
network_mode: host
|
||||
command: ['mongod', '--config', '/etc/mongod.conf']
|
||||
|
2
log/.gitignore
vendored
Normal file
2
log/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
!.gitignore
|
||||
db/*
|
40
log/mongod.conf
Normal file
40
log/mongod.conf
Normal file
@ -0,0 +1,40 @@
|
||||
# mongod.conf
|
||||
|
||||
# for documentation of all options, see:
|
||||
# http://docs.mongodb.org/manual/reference/configuration-options/
|
||||
|
||||
# Where and how to store data.
|
||||
storage:
|
||||
dbPath: /data/db
|
||||
# engine:
|
||||
# wiredTiger:
|
||||
|
||||
# where to write logging data.
|
||||
# systemLog:
|
||||
# destination: file
|
||||
# logAppend: true
|
||||
# path: /var/log/mongodb/mongod.log
|
||||
|
||||
# network interfaces
|
||||
net:
|
||||
port: 27019
|
||||
bindIp: 0.0.0.0
|
||||
|
||||
|
||||
# how the process runs
|
||||
# processManagement:
|
||||
# timeZoneInfo: /usr/share/zoneinfo
|
||||
|
||||
#security:
|
||||
|
||||
#operationProfiling:
|
||||
|
||||
#replication:
|
||||
|
||||
#sharding:
|
||||
|
||||
## Enterprise-Only Options:
|
||||
|
||||
#auditLog:
|
||||
|
||||
#snmp:
|
Loading…
Reference in New Issue
Block a user