{"id":27854112,"url":"https://github.com/zxc7563598/php-error-log","last_synced_at":"2026-03-03T11:38:48.146Z","repository":{"id":287489812,"uuid":"964889720","full_name":"zxc7563598/php-error-log","owner":"zxc7563598","description":"基于责任链模式的错误日志处理组件，支持多通道日志处理（如本地文件、远程 API、控制台输出），适用于复杂日志策略场景 | An error logging component using the Chain of Responsibility pattern. Supports multiple output channels like local files, remote APIs, and console logs—ideal for flexible and scalable logging strategies.","archived":false,"fork":false,"pushed_at":"2025-07-28T05:57:02.000Z","size":29,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-29T18:06:38.640Z","etag":null,"topics":["chain-of-responsibility","composer","console-log","error-logging","file-log","log-handler","logging","php","php8","remote-logging"],"latest_commit_sha":null,"homepage":"","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/zxc7563598.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,"zenodo":null}},"created_at":"2025-04-12T01:09:55.000Z","updated_at":"2025-07-28T05:56:43.000Z","dependencies_parsed_at":"2025-04-12T03:27:51.940Z","dependency_job_id":"d7155155-1492-414d-9ecb-74e4ddd9e432","html_url":"https://github.com/zxc7563598/php-error-log","commit_stats":null,"previous_names":["zxc7563598/php-error-log"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/zxc7563598/php-error-log","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxc7563598%2Fphp-error-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxc7563598%2Fphp-error-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxc7563598%2Fphp-error-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxc7563598%2Fphp-error-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zxc7563598","download_url":"https://codeload.github.com/zxc7563598/php-error-log/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zxc7563598%2Fphp-error-log/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278786685,"owners_count":26045591,"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","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["chain-of-responsibility","composer","console-log","error-logging","file-log","log-handler","logging","php","php8","remote-logging"],"created_at":"2025-05-04T08:58:18.971Z","updated_at":"2025-10-07T14:05:48.301Z","avatar_url":"https://github.com/zxc7563598.png","language":"PHP","readme":"# hejunjie/error-log\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"./README.md\"\u003eEnglish\u003c/a\u003e｜\u003ca href=\"./README.zh-CN.md\"\u003e简体中文\u003c/a\u003e\n  \u003chr width=\"50%\"/\u003e\n\u003c/div\u003e\n\nAn error logging component using the Chain of Responsibility pattern. Supports multiple output channels like local files, remote APIs, and console logs—ideal for flexible and scalable logging strategies.\n\n**This project has been parsed by Zread. If you need a quick overview of the project, you can click here to view it：[Understand this project](https://zread.ai/zxc7563598/php-error-log)**\n\n## Installation\n\nInstall via Composer:\n\n```bash\ncomposer require hejunjie/error-log\n```\n\n## Usage\n\n```php\n\u003c?php\n\nuse Hejunjie\\ErrorLog\\Logger;\nuse Hejunjie\\ErrorLog\\Handlers;\n\n$log = new Logger([\n    new Handlers\\ConsoleHandler(),                // Print to console\n    new Handlers\\FileHandler('path'),  // Save to file\n    new Handlers\\RemoteApiHandler('url')       // Send to a specific address\n]);\n\n$log-\u003einfo('title','content',['Context']);     // INFO Level\n$log-\u003ewarning('title','content',['Context']);  // WARNING Level\n$log-\u003eerror('title','content',['Context']);    // ERROR Level\n\n$log-\u003elog('level','title','content',['Context']);\n```\n\n## Purpose \u0026 Original Intent\n\nThe origin of this component is actually quite simple:\nThe code runs on different servers, some are as quiet as retired old men, while others explode into fireworks at the slightest provocation — but they're all running \"the same code,\" and every time something breaks, they come looking for me.\n\nThe most absurd part is that everyone claims they’re running the \"latest version,\" but whether it's a code issue, an environment issue, or a deployment issue, who knows?\nSo, I wrote this little tool: to flexibly output logs to files, consoles, and remote servers, with customizable formats. This way, I can find the problem before I'm questioned.\n\nLater, I also wrote a small log receiving script. Combined with this component, it can directly display remote logs, allowing me to receive, display, filter, and manage log error information.\n\n👉 [oh-shit-logger](https://github.com/zxc7563598/oh-shit-logger)\n\n\u003e Corresponding complete custom error handling (from webman)\n\n```php\n\u003c?php\n\nnamespace app\\exception;\n\nuse Carbon\\Carbon;\nuse Throwable;\nuse Webman\\Exception\\ExceptionHandler;\nuse Webman\\Http\\Request;\nuse Webman\\Http\\Response;\nuse support\\exception\\BusinessException;\nuse Hejunjie\\ErrorLog\\Logger;\nuse Hejunjie\\ErrorLog\\Handlers;\n\n/**\n * Class Handler\n * @package support\\exception\n */\nclass Handler extends ExceptionHandler\n{\n    public $dontReport = [\n        BusinessException::class,\n    ];\n\n    public function report(Throwable $exception)\n    {\n        parent::report($exception);\n        if ($this-\u003eshouldntReport($exception)) {\n            return;\n        }\n        $request = request();\n        $date = Carbon::now()-\u003etimezone(config('app')['default_timezone'])-\u003eformat('Y-m-d');\n        (new Logger([\n            new Handlers\\FileHandler(runtime_path(\"logs/{$date}/critical\")),\n            new Handlers\\RemoteApiHandler(config('app')['log_report_url'])\n        ]))-\u003eerror(get_class($exception), $exception-\u003egetMessage(), [\n            'project' =\u003e config('app')['app_name'],\n            'ip' =\u003e $request-\u003egetRealIp(),\n            'method' =\u003e $request-\u003emethod(),\n            'full_url' =\u003e $request-\u003efullUrl(),\n            'trace' =\u003e $this-\u003egetDebugData($exception)\n        ]);\n    }\n\n    public function render(Request $request, Throwable $exception): Response\n    {\n        $isDebug = config('app')['debug'] == 1;\n        $statusCode = $this-\u003egetHttpStatusCode($exception);\n        $response = [\n            'code' =\u003e $this-\u003egetErrorCode($exception),\n            'message' =\u003e $isDebug ? $exception-\u003egetMessage() : 'Server Error',\n            'data' =\u003e $isDebug ? $this-\u003egetDebugData($exception) : new \\stdClass()\n        ];\n        if ($requestId = $request-\u003eheader('X-Request-ID')) {\n            $response['request_id'] = $requestId;\n        }\n        return new Response(\n            $statusCode,\n            ['Content-Type' =\u003e 'application/json'],\n            json_encode($response, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)\n        );\n    }\n\n    protected function getHttpStatusCode(Throwable $exception): int\n    {\n        $code = $exception-\u003egetCode();\n        return ($code \u003e= 100 \u0026\u0026 $code \u003c 600) ? $code : 500;\n    }\n\n    protected function getErrorCode(Throwable $exception): int\n    {\n        return $exception-\u003egetCode() ?: 500;\n    }\n\n    protected function getDebugData(Throwable $exception): array\n    {\n        $trace = $exception-\u003egetTrace();\n        $simplifiedTrace = array_map(function ($frame) {\n            return [\n                'file' =\u003e $frame['file'] ?? '[internal function]',\n                'line' =\u003e $frame['line'] ?? 0,\n                'function' =\u003e $frame['function'] ?? null,\n                'class' =\u003e $frame['class'] ?? null,\n                'type' =\u003e $frame['type'] ?? null\n            ];\n        }, $trace);\n        return [\n            'class' =\u003e get_class($exception),\n            'message' =\u003e $exception-\u003egetMessage(),\n            'code' =\u003e $exception-\u003egetCode(),\n            'file' =\u003e $exception-\u003egetFile(),\n            'line' =\u003e $exception-\u003egetLine(),\n            'trace' =\u003e config('app')['debug'] == 1 ? $simplifiedTrace : array_slice($simplifiedTrace, 0, 5),\n            'previous' =\u003e $exception-\u003egetPrevious() ? [\n                'class' =\u003e get_class($exception-\u003egetPrevious()),\n                'message' =\u003e $exception-\u003egetPrevious()-\u003egetMessage()\n            ] : null\n        ];\n    }\n}\n\n```\n\n## 🔧 Additional Toolkits (Can be used independently or installed together)\n\nThis project was originally extracted from [hejunjie/tools](https://github.com/zxc7563598/php-tools).\nTo install all features in one go, feel free to use the all-in-one package:\n\n```bash\ncomposer require hejunjie/tools\n```\n\nAlternatively, feel free to install only the modules you need：\n\n[hejunjie/utils](https://github.com/zxc7563598/php-utils) - A lightweight and practical PHP utility library that offers a collection of commonly used helper functions for files, strings, arrays, and HTTP requests—designed to streamline development and support everyday PHP projects.\n\n[hejunjie/cache](https://github.com/zxc7563598/php-cache) - A layered caching system built with the decorator pattern. Supports combining memory, file, local, and remote caches to improve hit rates and simplify cache logic.\n\n[hejunjie/china-division](https://github.com/zxc7563598/php-china-division) - Regularly updated dataset of China's administrative divisions with ID-card address parsing. Distributed via Composer and versioned for use in forms, validation, and address-related features\n\n[hejunjie/error-log](https://github.com/zxc7563598/php-error-log) - An error logging component using the Chain of Responsibility pattern. Supports multiple output channels like local files, remote APIs, and console logs—ideal for flexible and scalable logging strategies.\n\n[hejunjie/mobile-locator](https://github.com/zxc7563598/php-mobile-locator) - A mobile number lookup library based on Chinese carrier rules. Identifies carriers and regions, suitable for registration checks, user profiling, and data archiving.\n\n[hejunjie/address-parser](https://github.com/zxc7563598/php-address-parser) - An intelligent address parser that extracts name, phone number, ID number, region, and detailed address from unstructured text—perfect for e-commerce, logistics, and CRM systems.\n\n[hejunjie/url-signer](https://github.com/zxc7563598/php-url-signer) - A PHP library for generating URLs with encryption and signature protection—useful for secure resource access and tamper-proof links.\n\n[hejunjie/google-authenticator](https://github.com/zxc7563598/php-google-authenticator) - A PHP library for generating and verifying Time-Based One-Time Passwords (TOTP). Compatible with Google Authenticator and similar apps, with features like secret generation, QR code creation, and OTP verification.\n\n[hejunjie/simple-rule-engine](https://github.com/zxc7563598/php-simple-rule-engine) - A lightweight and flexible PHP rule engine supporting complex conditions and dynamic rule execution—ideal for business logic evaluation and data validation.\n\n👀 All packages follow the principles of being lightweight and practical — designed to save you time and effort. They can be used individually or combined flexibly. Feel free to ⭐ star the project or open an issue anytime!\n\n---\n\nThis library will continue to be updated with more practical features. Suggestions and feedback are always welcome — I’ll prioritize new functionality based on community input to help improve development efficiency together.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzxc7563598%2Fphp-error-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzxc7563598%2Fphp-error-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzxc7563598%2Fphp-error-log/lists"}