{"id":23282098,"url":"https://github.com/bitpatty/ts-transformer-log-position","last_synced_at":"2025-08-21T13:33:13.424Z","repository":{"id":37030551,"uuid":"504909878","full_name":"BitPatty/ts-transformer-log-position","owner":"BitPatty","description":"A TypeScript AST transformer that injects the position of log statements into the log messages during compilation","archived":false,"fork":false,"pushed_at":"2024-12-11T16:51:33.000Z","size":2171,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-13T00:05:55.101Z","etag":null,"topics":["transformer","ttypescript","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@bitpatty/ts-transformer-log-position","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/BitPatty.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}},"created_at":"2022-06-18T17:35:48.000Z","updated_at":"2024-12-11T16:51:36.000Z","dependencies_parsed_at":"2024-04-22T18:25:45.759Z","dependency_job_id":"40a25178-aa39-4d4c-94e7-c69b8a5261cb","html_url":"https://github.com/BitPatty/ts-transformer-log-position","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BitPatty%2Fts-transformer-log-position","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BitPatty%2Fts-transformer-log-position/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BitPatty%2Fts-transformer-log-position/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BitPatty%2Fts-transformer-log-position/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BitPatty","download_url":"https://codeload.github.com/BitPatty/ts-transformer-log-position/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230516174,"owners_count":18238353,"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":["transformer","ttypescript","typescript"],"created_at":"2024-12-20T00:14:36.334Z","updated_at":"2024-12-20T00:14:36.977Z","avatar_url":"https://github.com/BitPatty.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ts-transformer-log-position\n\nA configurable Typescript AST transformer that injects the position of a log statement from the original source file into the respective log message at build time, allowing you to trace back log messages without emitting, exposing or requiring source maps.\n\n## Usage\n\n1. Use a compiler that allows you to use transformers (such as [ts-patch](https://github.com/nonara/ts-patch))\n2. Install the package `npm i --save-dev @bitpatty/ts-transformer-log-position`\n3. For ts-patch users: Add the transformer to your `tsconfig.json`:\n\n```jsonc\n{\n  \"compilerOptions\": {\n    \"plugins\": [\n      {\n        \"transform\": \"@bitpatty/ts-transformer-log-position\",\n        // Additional transformer configuration can be applied here\n      },\n    ],\n  },\n}\n```\n\nIf you use a different compiler than ts-patch, refer to the respective documentation on how to apply transformers.\n\n## Compatibility\n\n| TypeScript Version | Package Version |\n| ------------------ | --------------- |\n| 4.x.x              | 2.x.x           |\n| 5.x.x              | 3.x.x           |\n\n## Sample\n\n```typescript\nconsole.log(); // input\nconsole.log('[src/sample.ts:0:0]'); // output\n\nconsole.log(foo); // input\nconsole.log('[src/sample.ts:3:0]', foo); // output\n```\n\n## Ignoring lines\n\nIndividual lines can be ignored by adding `@ts-transformer-log-position ignore` to the line before the log statement. To ignore an entire file add `@ts-transformer-log-position disable` on the top of the file (before any imports or logic).\n\n```typescript\n// @ts-transformer-log-position disable\nconsole.log('foo'); // will be ignored\nconsole.log('foo'); // will be ignored\n```\n\n```typescript\n/* Some other comments */\n// ...\n\n// @ts-transformer-log-position disable\nconsole.log('foo'); // will be ignored\nconsole.log('foo'); // will be ignored\n```\n\n```typescript\nconsole.log('foo'); // will NOT be ignored\n// @ts-transformer-log-position ignore\nconsole.log('foo'); // will be ignored\nconsole.log('foo'); // will NOT be ignored\n```\n\n## Configuration\n\nThe plugin provides the configuration options below.\n\n### `split`\n\nWhether to split the arguments in the log statement. Defaults to `true`.\n\n```typescript\nconsole.log('[src/sample.ts:0:0]', foo); // split: true\nconsole.log('[src/sample.ts:1:0] ' + `${foo}`); // split: false\n```\n\n### `templateString`\n\nThe template string for the log prefix. Defaults to `\"[{projectFilePath}:{line}:{character}]\"`.\n\nThe following placeholders are available:\n\n- `absoluteFilePath`: The absolute path to the file\n- `fileName`: The name of the file\n- `projectFilePath`: The absolute path to the file from the project root. The project root is auto-detected, but can be modified via the `projectRoot` option\n\n```typescript\nconsole.log('[/workspace/src/sample.ts:0:0]', foo); // templateString: \"[{absoluteFilePath}:{line}:{character}]\"\nconsole.log('src/sample.ts, line 1', foo); // templateString: \"{projectFilePath}, line {line}\"\nconsole.log('sample.ts, line 1', foo); // templateString: \"{fileName}, line {line}\"\n```\n\n### `expressions`\n\nThe pattern of the call expression that should be matched against to apply the transformer. Defaults to: `['console.log', 'console.warn', 'console.debug', 'console.error', 'console.trace']`\n\n```typescript\n// expressions: \"Logger.log\"\nLogger.log('[src/sample.ts:1:0]', foo);\nconsole.log(foo); // not modified\n\n// expressions: [\"Logger.log\", \"console.log\"]\nLogger.log('[src/sample.ts:5:0]', foo);\nconsole.log('[src/sample.ts:6:0]', foo);\n```\n\n### `incrementLineNumber` / `incrementCharNumber`\n\nAdds +1 to each line / character number to match the numbering of common editors (starting from 1 instead of 0). Defaults to `false`.\n\n### `argsToJson` / `stringArgsToJson`\n\nIf `argsToJson` is true, the log arguments are wrapped in a JSON stringify. It omits strings and template expressions unless `stringArgsToJson` is `true`. Defaults to `false` / `false`.\n\nExamples:\n\n```typescript\n// argsToJson: true\n\n// in\nconsole.log(foo);\n// out\nconsole.log('[src/sample.ts:0:0] ' + JSON.stringify(foo));\n\n// in\nconsole.log(1 + 1);\n// out\nconsole.log('[src/sample.ts:0:0] ' + JSON.stringify(1 + 1));\n\n// in\nconsole.log(...foo);\n// out\nconsole.log(\n  '[src/sample.ts:0:0] ',\n  ...foo.map((__ttlp__v_0) =\u003e JSON.stringify(__ttlp__v_0)),\n);\n\n// in\nconsole.log(a, b, c);\n// out\nconsole.log(\n  '[src/sample.ts:0:0] ' + JSON.stringify(a),\n  JSON.stringify(b),\n  JSON.stringify(c),\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitpatty%2Fts-transformer-log-position","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitpatty%2Fts-transformer-log-position","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitpatty%2Fts-transformer-log-position/lists"}