{"id":28390088,"url":"https://github.com/zen-cronic/scope-logger","last_synced_at":"2026-02-23T22:03:15.013Z","repository":{"id":226464843,"uuid":"762467728","full_name":"Zen-cronic/scope-logger","owner":"Zen-cronic","description":"Trace a variable through function calls","archived":false,"fork":false,"pushed_at":"2025-01-06T04:54:37.000Z","size":423,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-31T13:12:07.060Z","etag":null,"topics":["log","scope","trace","variables"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/scope-logger","language":"TypeScript","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/Zen-cronic.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2024-02-23T20:59:04.000Z","updated_at":"2025-01-06T04:55:19.000Z","dependencies_parsed_at":"2024-03-18T00:22:14.783Z","dependency_job_id":"591da9ca-1c14-4ef5-a217-1e5966ce349e","html_url":"https://github.com/Zen-cronic/scope-logger","commit_stats":null,"previous_names":["zen-cronic/scope-logger"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Zen-cronic/scope-logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zen-cronic%2Fscope-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zen-cronic%2Fscope-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zen-cronic%2Fscope-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zen-cronic%2Fscope-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Zen-cronic","download_url":"https://codeload.github.com/Zen-cronic/scope-logger/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zen-cronic%2Fscope-logger/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262335216,"owners_count":23295595,"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","scope","trace","variables"],"created_at":"2025-05-31T03:30:22.541Z","updated_at":"2026-02-23T22:03:09.967Z","avatar_url":"https://github.com/Zen-cronic.png","language":"TypeScript","readme":"# scope-logger\n\n# What it does\n\nLogs a variable and a sequence of scopes through which it's accessed. It automatically logs the name of the variable. A NodeJs logger. Inspired by the debug library.\n\n# Why??\n\nToo lazy to write `console.log(\"variableName %o\", variableValue)` :))\nThe same effect can be achieved with `console.log({variable})` =\u003e `$ variableName: variableValue`  \nBut this logger shows the **sequence of scopes**(i.e., functions) from the variable is logged, a feature that I wished I had when I was logging many different variables.\n\n# Example\n\n```javascript\nfunction outerFn() {\n  function innerFn() {\n    const logger = new Logger(\"lazy-log\");\n\n    const foofoo = \"barbar\";\n    logger.log({ foofoo });\n  }\n\n  innerFn();\n}\n\nouterFn();\n```\n\nOutput:\n![usage-sample-output](https://github.com/Zen-cronic/scope-logger/assets/83657429/bc54bf1d-3609-4cb4-a00c-d811c2038c54)\n\n# Installation\n\n`$ npm install scope-logger`\n\n# Usage\n\n1. Create an instance of `Logger`. Namespace and options are optional args for constructor.\n\n2. Pass the variable you want to log to the `log` method inside **curly brackets** `{}`!\n\n# Additional Control\n\n- `disableAll()`\n  Toggle to disable all the logging of a logger/namespace. A much more efficient approach than commenting every `console.log()` line (and deleting them) before pushing the code to production. Can be used to get rid of a logger instance's logs in the terminal.\n\nFor _instance_:\n\n```javascript\nconst logger = new Logger(\"Log tester\").disableAll();\n//or\nlogger.disableAll();\n\nconst foo = \"bar\";\nlogger.log({ foo });\n```\n\nOutput: nothing!\n`$     `   \n\n\n# Configuration Options\n\n1. **ignoreIterators** (boolean): set `true` to omit the native iterator calls (e.g., Array.forEach) in the scope log statement. This applies to all types of array-like iterators available in JS and NodeJs such as Map, Set, Array, Int8Array, and so on.\n\n```javascript\nfunction outerFn() {\n  function innerFn() {\n    const logger = new Logger(\"Server\");\n\n    const testArr = [1, 2, 3];\n    testArr.forEach((val) =\u003e {\n      logger.log({ val });\n    });\n  }\n\n  innerFn();\n}\n\nouterFn();\n```\n\n_Default output:_\n\n![ignore-iterators](https://github.com/Zen-cronic/scope-logger/assets/83657429/83a8abe0-2a95-4372-8d3d-ae629ded3a85)\n\n```javascript\ntestArr.forEach((val) =\u003e {\n  logger.log({ val }, { ignoreIterators: true });\n});\n```\n\n_Configured output: `Array.forEach` is omitted_\n\n![ignore-iterators-enabled](https://github.com/Zen-cronic/scope-logger/assets/83657429/94f10f12-5adc-4f7f-8315-b55e2f84163a)\n\n2. **onlyFirstElem** (boolean): set to `true` to log only the first element in an iterator call. This is useful in scenarios where you only care about the scope journey of a variable in the iterator call, but **not** about the value of each variable.\n\nAll the elements would have the same scope signature, therefore it's redundant to print all those logs. The non-first variables are not logged. This applies recursively for nested iterator calls.\n\n```javascript\nfunction main() {\n  const outerArr = [1, 2, 3];\n  const innerArr = [1, 2, 3];\n\n  outerArr.forEach(() =\u003e {\n    innerArr.map((val) =\u003e {\n      logger.log({ val });\n    });\n  });\n}\n\nmain();\n```\n\n_Default output: The following 3 lines x 3 = 9 logs in total_\n\n![only-first-elem](https://github.com/Zen-cronic/scope-logger/assets/83657429/3a9a61f6-0bc0-433e-99b2-52ea8ea16aef)\n\n```javascript\nouterArr.forEach(() =\u003e {\n  innerArr.map((val) =\u003e {\n    logger.log({ val }, { onlyFirstElem: true });\n  });\n});\n```\n\n_Configured output: Only the first element is logged_\n\n![only-first-elem-enabled](https://github.com/Zen-cronic/scope-logger/assets/83657429/56607c75-625f-45ab-a9c8-846cb2c81d85)\n\n_The default configuration:_\n\n```javascript\n  {\n    ignoreIterators: false,\n    onlyFirstElem: false\n  }\n\n```\n\n---\n\n# Limitations\n\n1. Cannot pass a property of an object. Because the library is based on JS object destructing (`console.log({foo})` outputs the same as `console.log({foo: \u003cvalue\u003e})`).\n\n- Where `foo.name = \"bar\"` Cannot type `logger.log({foo.name})`. This will throw a syntax error.\n\n# Test\n\n`$ npm run test`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzen-cronic%2Fscope-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzen-cronic%2Fscope-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzen-cronic%2Fscope-logger/lists"}