{"id":33959444,"url":"https://github.com/tourze/workerman-psr-logger","last_synced_at":"2025-12-12T21:11:24.051Z","repository":{"id":284021461,"uuid":"953580916","full_name":"tourze/workerman-psr-logger","owner":"tourze","description":"[READ-ONLY] PSR Logger for Workerman","archived":false,"fork":false,"pushed_at":"2025-06-30T13:12:16.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-23T05:56:23.219Z","etag":null,"topics":["logger","psr","workerman"],"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/tourze.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-03-23T17:31:31.000Z","updated_at":"2025-06-30T13:12:20.000Z","dependencies_parsed_at":"2025-04-17T10:54:30.838Z","dependency_job_id":"d62200df-a1b0-4fd8-a716-fd54c20215a5","html_url":"https://github.com/tourze/workerman-psr-logger","commit_stats":null,"previous_names":["tourze/workerman-psr-logger"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/tourze/workerman-psr-logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tourze%2Fworkerman-psr-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tourze%2Fworkerman-psr-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tourze%2Fworkerman-psr-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tourze%2Fworkerman-psr-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tourze","download_url":"https://codeload.github.com/tourze/workerman-psr-logger/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tourze%2Fworkerman-psr-logger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27691642,"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-12-12T02:00:06.775Z","response_time":129,"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":["logger","psr","workerman"],"created_at":"2025-12-12T21:11:23.383Z","updated_at":"2025-12-12T21:11:24.046Z","avatar_url":"https://github.com/tourze.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Workerman PSR Logger\n\n[English](README.md) | [中文](README.zh-CN.md)\n\n[![Latest Version](https://img.shields.io/packagist/v/tourze/workerman-psr-logger.svg?style=flat-square)](https://packagist.org/packages/tourze/workerman-psr-logger)\n[![Build Status](https://github.com/tourze/workerman-psr-logger/actions/workflows/ci.yml/badge.svg)](https://github.com/tourze/workerman-psr-logger/actions)\n[![Quality Score](https://img.shields.io/scrutinizer/g/tourze/workerman-psr-logger.svg?style=flat-square)](https://scrutinizer-ci.com/g/tourze/workerman-psr-logger)\n[![Total Downloads](https://img.shields.io/packagist/dt/tourze/workerman-psr-logger.svg?style=flat-square)](https://packagist.org/packages/tourze/workerman-psr-logger)\n[![PHP Version Require](https://img.shields.io/packagist/php-v/tourze/workerman-psr-logger.svg?style=flat-square)](https://packagist.org/packages/tourze/workerman-psr-logger)\n[![License](https://img.shields.io/packagist/l/tourze/workerman-psr-logger.svg?style=flat-square)](https://packagist.org/packages/tourze/workerman-psr-logger)\n[![Coverage Status](https://img.shields.io/codecov/c/github/tourze/workerman-psr-logger/main.svg?style=flat-square)](https://codecov.io/gh/tourze/workerman-psr-logger)\n\nA PSR-3 compatible logger that integrates seamlessly with Workerman's built-in logging system and outputs structured JSON logs.\n\n## Features\n\n- Implements PSR-3 LoggerInterface for standard logging\n- Integrates with Workerman's built-in logging system\n- JSON formatted log output for easy parsing and analysis\n- Supports all PSR-3 log levels (emergency, alert, critical, error, warning, notice, info, debug)\n- Context support for structured logging\n- Extra utility for hexdump and binary data logging\n- Automatic timestamp formatting with microsecond precision\n- Only logs when Workerman is running (prevents logging in non-daemon mode)\n\n## Installation\n\nRequirements:\n- PHP \u003e= 8.1\n- Workerman \u003e= 5.1\n- PSR Log Interface (v1, v2, or v3)\n\nInstall via Composer:\n\n```bash\ncomposer require tourze/workerman-psr-logger\n```\n\n## Quick Start\n\n### Basic Usage\n\n```php\n\u003c?php\n\nuse Tourze\\Workerman\\PsrLogger\\WorkermanLogger;\n\n$logger = new WorkermanLogger();\n\n// Basic logging\n$logger-\u003einfo('Server started');\n$logger-\u003eerror('Connection failed');\n$logger-\u003edebug('Processing request');\n\n// With context\n$logger-\u003eerror('Connection failed', [\n    'ip' =\u003e '127.0.0.1',\n    'port' =\u003e 8080,\n    'error_code' =\u003e 500\n]);\n```\n\n### Log Format\n\nLogs are output as JSON with the following structure:\n\n```json\n{\n    \"level\": \"INFO\",\n    \"datetime\": \"2024-03-24 10:30:45.123456\",\n    \"message\": \"Server started\",\n    \"context\": {\n        \"ip\": \"127.0.0.1\",\n        \"port\": 8080\n    }\n}\n```\n\n### Advanced Usage with LogUtil\n\nUse `LogUtil` for specialized logging scenarios:\n\n```php\nuse Tourze\\Workerman\\PsrLogger\\LogUtil;\n\n// Binary data logging with hexdump\nLogUtil::debug('Received binary data', $binaryData);\n\n// Exception logging with stack trace\nLogUtil::error('Exception occurred', $exception);\n\n// Info logging with optional binary data\nLogUtil::info('Processing data', $optionalBinaryData);\n\n// Warning logging\nLogUtil::warning('Memory usage high', $memoryDumpData);\n```\n\n## API Documentation\n\n### WorkermanLogger\n\nImplements `Psr\\Log\\LoggerInterface` with the following methods:\n\n- `emergency(string|\\Stringable $message, array $context = []): void`\n- `alert(string|\\Stringable $message, array $context = []): void`\n- `critical(string|\\Stringable $message, array $context = []): void`\n- `error(string|\\Stringable $message, array $context = []): void`\n- `warning(string|\\Stringable $message, array $context = []): void`\n- `notice(string|\\Stringable $message, array $context = []): void`\n- `info(string|\\Stringable $message, array $context = []): void`\n- `debug(string|\\Stringable $message, array $context = []): void`\n- `log(mixed $level, string|\\Stringable $message, array $context = []): void`\n\n### LogUtil\n\nStatic utility class for specialized logging:\n\n- `debug(string $message, ?string $binaryData = null): void`\n- `info(string $message, ?string $binaryData = null): void`\n- `error(string $message, ?\\Throwable $e = null): void`\n- `warning(string $message, ?string $binaryData = null): void`\n\n## Performance Considerations\n\n- Logs are only written when `Worker::isRunning()` returns true\n- JSON encoding is performed for each log entry\n- Binary data is hexdumped using the `clue/hexdump` library\n- Context arrays are preserved as-is in the JSON output\n\n## Contributing\n\nWe welcome contributions! Please follow these guidelines:\n\n- Submit issues for bugs and feature requests\n- Follow PSR coding standards\n- Write tests for new features\n- Ensure all tests pass before submitting PR\n- Keep commits focused and atomic\n\n## License\n\nThe MIT License (MIT). Please see [LICENSE](LICENSE) for more information.\n\n## Changelog\n\nSee [CHANGELOG.md](CHANGELOG.md) if available.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftourze%2Fworkerman-psr-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftourze%2Fworkerman-psr-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftourze%2Fworkerman-psr-logger/lists"}