{"id":22779434,"url":"https://github.com/mccann-hub/express-log-smith","last_synced_at":"2026-02-12T11:34:41.492Z","repository":{"id":266334160,"uuid":"895157630","full_name":"McCann-Hub/express-log-smith","owner":"McCann-Hub","description":"Skillfully forges logs for Express.js applications","archived":false,"fork":false,"pushed_at":"2024-12-06T02:04:13.000Z","size":234,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-24T18:23:17.807Z","etag":null,"topics":["express-middleware","expressjs","logger-middleware","logging","morgan","morgan-middleware","typescript","typescript-library"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/McCann-Hub.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-11-27T16:59:15.000Z","updated_at":"2024-12-06T02:03:29.000Z","dependencies_parsed_at":"2025-04-13T10:02:52.000Z","dependency_job_id":null,"html_url":"https://github.com/McCann-Hub/express-log-smith","commit_stats":null,"previous_names":["mccann-hub/express-log-smith"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/McCann-Hub/express-log-smith","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/McCann-Hub%2Fexpress-log-smith","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/McCann-Hub%2Fexpress-log-smith/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/McCann-Hub%2Fexpress-log-smith/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/McCann-Hub%2Fexpress-log-smith/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/McCann-Hub","download_url":"https://codeload.github.com/McCann-Hub/express-log-smith/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/McCann-Hub%2Fexpress-log-smith/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29364417,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-12T08:51:36.827Z","status":"ssl_error","status_checked_at":"2026-02-12T08:51:26.849Z","response_time":55,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["express-middleware","expressjs","logger-middleware","logging","morgan","morgan-middleware","typescript","typescript-library"],"created_at":"2024-12-11T20:08:47.922Z","updated_at":"2026-02-12T11:34:41.487Z","avatar_url":"https://github.com/McCann-Hub.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Express Log Smith\n\nExpress Log Smith is a middleware library for Express.js designed to enhance logging and request tracing.\nIt simplifies request/response observability by integrating structured logging and unique identifiers like\n`correlationId`, `traceId`, and `spanId` into your application.\n\n## Features\n\n- **Request ID Middleware**: Automatically assigns correlationId, traceId, and spanId to each request.\n- **Contextual Logger**: Attaches a logger with enriched metadata to the request object for consistent, contextual logging.\n- **Request Logger**: Logs structured details of incoming requests and outgoing responses.\n- **Customizable**: Configure ID generation, log formats, and skip conditions as needed.\n- **Plug-and-Play**: Works seamlessly with any logger implementing the provided ILogger interface.\n\n## Installation\n\nInstall ExpressLogSmith via npm:\n\n```bash\nnpm install @mccann-hub/express-log-smith\n```\n\n## Basic Usage\n\nA simple example integrating the middlewares into an Express.js application:\n\n```typescript\nimport express from \"express\";\nimport {\n  dexter,\n  requestId,\n  requestLogger,\n} from \"@mccann-hub/express-log-smith\";\n\n// Import your logger (must implement ILogger)\nimport myLogger from \"./myLogger\";\n\nconst app = express();\n\n// Add request ID middleware to generate unique IDs\napp.use(requestId());\n\n// Add contextual logger middleware\napp.use(dexter(myLogger));\n\n// Add request logging middleware\napp.use(requestLogger(myLogger));\n\n// Define routes\napp.get(\"/\", (req, res) =\u003e {\n  req.logger.info(\"Processing request\", { custom: \"metadata\" });\n  res.send(\"Hello, world!\");\n});\n\napp.listen(3000, () =\u003e {\n  console.log(\"Server is running on port 3000\");\n});\n```\n\n## Exported Middlewares\n\n### `requestId(options?: RequestIdOptions)`\n\nAdds `correlationId`, `traceId`, and `spanId` to each request.\nThese IDs help trace logs across distributed systems.\n\n#### Options\n\n- **correlation (optional)**: Configuration for the correlation ID.\n  - **headerName**: The header name for the correlation ID (default: X-Correlation-Id).\n  - **generator**: A custom ID generation function.\n  - **setHeader**: Whether to include the correlation ID in the response headers (default: true).\n- **trace (optional)**: Configuration for the trace ID.\n  - Same properties as correlation.\n- **span (optional)**: Configuration for the span ID.\n  - **headerName**: The header name for the span ID (default: X-svc2svc-Id).\n  - **setHeader**: Whether to include the span ID in the response headers (default: true).\n\n#### Example\n\n```typescript\napp.use(\n  requestId({\n    correlation: { headerName: \"X-My-Correlation-Id\" },\n    trace: { generator: () =\u003e `trace-${Date.now()}` },\n  }),\n);\n```\n\n### `dexter(logger: ILogger)`\n\nLogs structured details of incoming requests and outgoing responses.\nThe default format includes:\n\n- correlation_id\n- trace_id\n- span_id\n- HTTP method, content type, user agent, URI path\n- Response time and status\n\n#### Customization\n\nYou can customize logging behavior by providing a skip function:\n\n```typescript\napp.use(\n  dexter(myLogger, {\n    skip: (req) =\u003e req.url === \"/health\",\n  }),\n);\n```\n\n### `requestLogger(logger: ILogger)`\n\nAttaches a logger to the request object.\nThe logger includes metadata from the request, such as `correlationId`, `traceId`, and `spanId`.\n\n#### Requirements\n\nThe provided logger must implement the ILogger interface.\n\n#### Example\n\n```typescript\napp.use(requestLogger(myLogger));\n\napp.get(\"/test\", (req, res) =\u003e {\n  req.logger.info(\"This is a test log\");\n  res.send(\"Logged successfully!\");\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmccann-hub%2Fexpress-log-smith","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmccann-hub%2Fexpress-log-smith","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmccann-hub%2Fexpress-log-smith/lists"}