{"id":19621578,"url":"https://github.com/pkg6/think-http-logger","last_synced_at":"2025-04-28T03:32:19.252Z","repository":{"id":57080363,"uuid":"488122299","full_name":"pkg6/think-http-logger","owner":"pkg6","description":"A Thinkphp package to log HTTP requests ","archived":false,"fork":false,"pushed_at":"2024-07-05T03:37:52.000Z","size":29,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-05T06:11:12.446Z","etag":null,"topics":["log","php","thinkphp6"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/tp5er/think-http-logger","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pkg6.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-03T07:54:59.000Z","updated_at":"2024-09-26T09:19:27.000Z","dependencies_parsed_at":"2024-11-11T11:26:21.284Z","dependency_job_id":"c815badb-0d1e-4b17-ae71-198767f7755f","html_url":"https://github.com/pkg6/think-http-logger","commit_stats":null,"previous_names":["open-package/think-http-logger"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg6%2Fthink-http-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg6%2Fthink-http-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg6%2Fthink-http-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkg6%2Fthink-http-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pkg6","download_url":"https://codeload.github.com/pkg6/think-http-logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251246280,"owners_count":21558762,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["log","php","thinkphp6"],"created_at":"2024-11-11T11:23:37.077Z","updated_at":"2025-04-28T03:32:18.882Z","avatar_url":"https://github.com/pkg6.png","language":"PHP","readme":"这个包添加了一个中间件，可以将传入的请求记录到默认日志中。 如果在用户请求期间出现任何问题，您仍然可以访问该用户发送的原始请求数据。\n\n\n\n配置文件`config/http-logger.php`内容：\n\n~~~\n\u003c?php\nreturn [\n    /*\n   * The log profile which determines whether a request should be logged.\n   * It should implement `LogProfile`.\n   */\n    'log_profile' =\u003e \\tp5er\\think\\HttpLogger\\LogProfile\\LogNonGetRequests::class,\n\n    /*\n     * The log writer used to write the request to a log.\n     * It should implement `LogWriter`.\n     */\n    'log_writer'  =\u003e \\tp5er\\think\\HttpLogger\\LogWriter\\DefaultLogWriter::class,\n\n    /*\n    * The log channel used to write the request.\n    */\n    'log_channel' =\u003e env('LOG_CHANNEL', 'file')\n];\n~~~\n\n\n\n## 控制器中使用\n\n~~~\nuse tp5er\\think\\HttpLogger\\Middlewares\\HttpLogger;\nclass Index extends BaseController\n{\n    protected $middleware =[\n        HttpLogger::class\n    ];\n    public function index()\n    {\n        return 'test HttpLogger';\n    }\n}\n~~~\n\n## 路由中使用\n\n~~~\nRoute::get('think', function () {\n    return 'hello,ThinkPHP6!';\n})-\u003emiddleware(\\tp5er\\think\\HttpLogger\\Middlewares\\HttpLogger::class);\n~~~\n\n## 全局`app/middleware.php`\n\n~~~\n\u003c?php\n// 全局中间件定义文件\nreturn [\n\t\t......\n    \\tp5er\\think\\HttpLogger\\Middlewares\\HttpLogger::class\n];\n~~~\n\n日志记录\n两个类用于处理传入请求的日志记录：`LogProfile` 类将确定是否应记录请求，`LogWriter` 类将请求写入日志。\n\n在这个包中添加了一个默认的日志实现。 它只会记录 `POST`、`PUT`、`PATCH` 和 `DELETE` 请求，并将写入默认的 thinkphp 记录器。\n\n您可以自由实现自己的日志配置文件和/或日志编写器类，并在` config/http-logger.php` 中进行配置。\n\n自定义日志配置文件必须实现` \\tp5er\\think\\HttpLogger\\LogProfile`。 这个接口需要你实现 shouldLogRequest。\n\n~~~\n// Example implementation from `tp5er\\think\\HttpLogger\\LogNonGetRequests`\n\npublic function shouldLogRequest(Request $request): bool\n{\n   return in_array(strtolower($request-\u003emethod()), ['post', 'put', 'patch', 'delete']);\n}\n~~~\n\n自定义日志编写器必须实现 \\tp5er\\think\\HttpLogger\\LogWriter。 这个接口需要你实现logRequest。\n\n~~~\n// Example implementation from ` \\tp5er\\think\\HttpLogger\\DefaultLogWriter`\n\npublic function logRequest(Request $request): void\n{\n    $method = strtoupper($request-\u003emethod());\n    $uri = $request-\u003epathinfo();\n    $bodyAsJson = json_encode($request-\u003eall());\n    $message = \"{$method} {$uri} - {$bodyAsJson}\";\n    Log::channel(config('http-logger.log_channel'))-\u003einfo($message);\n}\n~~~\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkg6%2Fthink-http-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpkg6%2Fthink-http-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkg6%2Fthink-http-logger/lists"}