{"id":19382718,"url":"https://github.com/danivek/contextlog","last_synced_at":"2026-05-07T16:40:33.600Z","repository":{"id":57206559,"uuid":"113041219","full_name":"danivek/contextlog","owner":"danivek","description":":scroll: Structured context logging for Node.js. Add meta to log.","archived":false,"fork":false,"pushed_at":"2017-12-22T09:57:32.000Z","size":38,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-20T04:41:14.978Z","etag":null,"topics":["audit-log","context-log","javascript","log","meta","metadata","nodejs","structured-log"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/danivek.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}},"created_at":"2017-12-04T12:44:20.000Z","updated_at":"2018-01-04T10:50:40.000Z","dependencies_parsed_at":"2022-09-04T03:02:33.169Z","dependency_job_id":null,"html_url":"https://github.com/danivek/contextlog","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/danivek/contextlog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danivek%2Fcontextlog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danivek%2Fcontextlog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danivek%2Fcontextlog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danivek%2Fcontextlog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danivek","download_url":"https://codeload.github.com/danivek/contextlog/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danivek%2Fcontextlog/sbom","scorecard":{"id":320946,"data":{"date":"2025-08-11","repo":{"name":"github.com/danivek/contextlog","commit":"2fe0b3d641f9fef43247a3d9c924661503532b09"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/9 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-18T01:21:12.104Z","repository_id":57206559,"created_at":"2025-08-18T01:21:12.104Z","updated_at":"2025-08-18T01:21:12.104Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32746443,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-07T02:14:30.463Z","status":"ssl_error","status_checked_at":"2026-05-07T02:14:29.405Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["audit-log","context-log","javascript","log","meta","metadata","nodejs","structured-log"],"created_at":"2024-11-10T09:22:55.619Z","updated_at":"2026-05-07T16:40:33.580Z","avatar_url":"https://github.com/danivek.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# contextlog\n[![Build Status](https://travis-ci.org/danivek/contextlog.svg?branch=master)](https://travis-ci.org/danivek/contextlog)\n[![Coverage Status](https://coveralls.io/repos/github/danivek/contextlog/badge.svg?branch=master)](https://coveralls.io/github/danivek/contextlog?branch=master)\n[![npm](https://img.shields.io/npm/v/contextlog.svg)](https://www.npmjs.org/package/contextlog)\n\nStructured context logging for NodeJS.\n\nBuild a context object from HTTP request/response informations for your favorite logger.\n\nAllows you to do rich application monitoring/auditing by providing metadata for your logs.\n\n## Motivation\nOne logging best practice is to log as much as you can!\nThe more you log, the bigger the chances are that you will get the right information when debugging or trying to understand what happened.\n\nAdding context to log allow you to answer the following questions:\n- What happened?\n- What it contains?\n- When did it happen?\n- Who initiated it?\n- On what did it happen?\n\n## Supported features\n- Logger agnostic \n- Structured format\n- Request/response context\n- Error context with stacktrace, os, process info\n- Mask sensitive data like Authorization header, url parameters, etc.\n- Exclude specific URLs from logging\n\n## Installation\n\n```bash\nnpm install --save contextlog\n```\n## Usage\n\n```javascript\nconst Contextlog = require('contextlog');\nconst pkg = require('./package.json');\n\nconst contextlog = new Contextlog({\n  skipUrls: [/\\/docs/],\n  application: { \n    name: pkg.name, \n    version: pkg.version \n  },\n  user: ({req}, context) =\u003e ({\n    id: req.user \u0026\u0026 req.user.id\n  }),\n  resource: ({req}, context) =\u003e ({\n    type: req.params.resourceType,\n    id: req.params.id\n  }),\n  custom: ({ req }) =\u003e ({ custom: req.custom }),\n  reqBody: (body) =\u003e {\n    body.password = contextlog.mask(body.password);\n    return body;\n  },\n  resBody: true\n});\n```\n\n**Options:**\n  - **keyValue** (optional): key-value pairs format (except for `req.body` and `res.body` that will be stringify). Default = false;\n  - **skipUrls** (optional): Array of regex to skip/exclude specific URLs from logging.\n  - **application** (optional): *object* or *function*. Describes the application context.\n  - **id** (optional): *object* or *function*. Describes the transaction id.\n  - **user** (optional): *object* or *function*. Describes the user context.\n  - **resource** (optional): *object* or *function*. Describes the resource context.\n  - **custom** (optional): *object* or *function*. Add custom metadata to top-level.\n  - **reqBody** (optional): *boolean* or *function*. include/filter req.body. Default = false.\n  - **resBody** (optional): *boolean* or *function*. include/filter req.body. Default = false.\n  - **maskUrlParams** (optional): Array of url parameters to mask.\n  - **maskHeaders** (optional): Array of headers to mask on req and res.\n  - **parseUserAgent**: *boolean* to indicate if 'user-agent' header should be parsed using [useragent](https://github.com/3rd-Eden/useragent) and added to `req.userAgent`. Default = false.\n\n### standard({ req, res }, [context])\n```javascript\ncontextlog.standard({ req, res });\n```\n\n```json\n{\n  \"date\": \"2017-12-09T17:36:24.655Z\",\n  \"application\": {\n    \"name\": \"contextlog\",\n    \"version\": \"1.0.0\"\n  },\n  \"user\": {\n    \"id\": \"john.doe\"\n  },\n  \"resource\": {\n    \"type\": \"user\",\n    \"id\": \"1\"\n  },\n  \"custom\": \"custom\"\n}\n```\n### request({ req, res }, [context])\n```javascript\ncontextlog.request({ req, res });\n```\n\n```json\n{\n  \"date\": \"2017-12-09T17:36:24.655Z\",\n  \"application\": {\n    \"name\": \"contextlog\",\n    \"version\": \"1.0.0\"\n  },\n  \"user\": {\n    \"id\": \"john.doe\"\n  },\n  \"resource\": {\n    \"type\": \"user\",\n    \"id\": \"1\"\n  },\n  \"custom\": \"custom\",\n  \"req\": {\n    \"httpVersion\": \"1.1\",\n    \"remoteAddress\": \"192.168.1.1\",\n    \"url\": \"/path/to/endpoint\",\n    \"method\": \"POST\",\n    \"headers\": {\n      \"host\": \"localhost\",\n      \"connection\": \"keep-alive\",\n      \"Authorization\": \"Basic *********\"\n    },\n    \"body\": {\n      \"data\": \"data\",\n      \"password\": \"********\"\n    }\n  },\n  \"res\": {\n    \"statusCode\": \"200\",\n    \"headers\": {\n      \"content-type\": \"application/json; charset=utf-8\"\n    },\n    \"body\": {\n      \"data\": \"data\"\n    }\n  }\n}\n```\n### error(err, { req, res }, [context])\n```javascript\ncontextlog.error(err, { req, res })\n```\n\n```json\n{\n  \"date\": \"2017-12-09T17:36:24.655Z\",\n  \"application\": {\n    \"name\": \"contextlog\",\n    \"version\": \"1.0.0\"\n  },\n  \"user\": {\n    \"id\": \"john.doe\"\n  },\n  \"resource\": {\n    \"type\": \"user\",\n    \"id\": \"1\"\n  },\n  \"custom\": \"custom\",\n  \"error\": true,\n  \"os\": {\n    \"hostname\": \"localhost\",\n    \"plateform\": \"win32\",\n    \"loadavg\": [\n      0,\n      0,\n      0\n    ],\n    \"uptime\": 874049.5096699,\n    \"freemem\": 8310415360\n  },\n  \"process\": {\n    \"pid\": 33636,\n    \"uid\": null,\n    \"gid\": null,\n    \"cwd\": \"C:\\\\Users\\\\contextlog\",\n    \"execPath\": \"C:\\\\Program Files\\\\nodejs\\\\node.exe\",\n    \"version\": \"v8.9.1\",\n    \"argv\": [\n      \"node\",\n      \"C:\\\\Users\\\\contextlog\\\\node_modules\\\\mocha\\\\bin\\\\_mocha\",\n      \"-R\",\n      \"spec\",\n      \"./test/**/*.js\"\n    ],\n    \"memoryUsage\": {\n      \"rss\": 50888704,\n      \"heapTotal\": 34512896,\n      \"heapUsed\": 21474088,\n      \"external\": 1463895\n    }\n  },\n  \"message\": \"boom\",\n  \"stack\": \"Error: boom\\n    at Context.it (C:\\\\Users\\\\contextlog\\\\test\\\\unit\\\\Contextlog.test.js:266:19)\\n    at callFnAsync (C:\\\\Users\\\\contextlog\\\\node_modules\\\\mocha\\\\lib\\\\runnable.js:377:21)\\n    at Test.Runnable.run ...\",\n  \"req\": {\n    \"httpVersion\": \"1.1\",\n    \"remoteAddress\": \"192.168.1.1\",\n    \"url\": \"/path/to/endpoint\",\n    \"method\": \"POST\",\n    \"headers\": {\n      \"host\": \"localhost\",\n      \"connection\": \"keep-alive\",\n      \"Authorization\": \"Basic *********\"\n    },\n    \"body\": {\n      \"data\": \"data\",\n      \"password\": \"********\"\n    }\n  },\n  \"res\": {\n    \"statusCode\": \"200\",\n    \"headers\": {\n      \"content-type\": \"application/json; charset=utf-8\"\n    },\n    \"body\": {\n      \"data\": \"data\"\n    }\n  }\n}\n```\n## Mask sensitive data\n\ncontextlog do some default masking of common sensitive data on url parameters and req/res headers: \n- Url params: ['x-api-key']\n- Headers: ['authorization', 'x-api-key']\n\nIt also provides some utilities functions to mask sensitive data:\n\n### mask(string)\n\n```javascript\ncontextlog.mask(body.password)\n```\n\n### maskUrl(url)\n\n```javascript\nconst contextlog = new Contextlog({\n  maskUrlParams: ['mask'],\n});\ncontextlog.maskUrl('/path/to/endpoint?x-api-key=shouldbemask\u0026mask=shouldbemask\u0026notmask=shouldnotbemask');\n// =\u003e '/path/to/endpoint?x-api-key=************\u0026mask=************\u0026notmask=shouldnotbemask';\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanivek%2Fcontextlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanivek%2Fcontextlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanivek%2Fcontextlog/lists"}