{"name":"ts-log","version":"3.0.2","keywords":["typescript","abstract","logger","console","dummy"],"author":{"name":"Stagnation Lab"},"license":"MIT","_id":"ts-log@3.0.2","maintainers":[{"name":"kallaspriit","email":"kallaspriit@gmail.com"}],"homepage":"https://github.com/kallaspriit/ts-log#readme","bugs":{"url":"https://github.com/kallaspriit/ts-log/issues"},"dist":{"shasum":"e37ebc147c63f1ad3de1bee903c26831fd35f9cb","tarball":"http://registry-npm.ywwl.com/ts-log/download/ts-log-3.0.2.tgz","fileCount":7,"integrity":"sha512-esq6hx2lM66sQV1YcFkIYTqrWWabmqBqobKHyn1CswdI5FgfQhkmiKiRWVGBNlIbdjBxEIkNvMIwLKKPgRYZLQ==","signatures":[{"sig":"MEUCIQDxSWaqZ6xAmbEsd0HgqtIk5c2lUoBSvZarCqlVKqhfQwIgdSI+enFLNVbQ8GY4iA6ZuH3pLzu9xLy4UASEvdjyWnA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":9050,"size":3587,"noattachment":false,"key":"/ts-log/-/ts-log-3.0.2.tgz"},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"npm":">=10","node":">=20"},"exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}}},"gitHead":"fb742980273fe697c9f9c59c96818f1392fc2eba","scripts":{"lint":"eslint src/","test":"vitest run","build":"tsup","format":"prettier --check src/","lint:fix":"eslint --fix src/","validate":"npm run format && npm run build && npm run typecheck && npm run lint && npm run test:coverage","typecheck":"tsc --noEmit","format:fix":"prettier --write src/","test:coverage":"vitest run --coverage","prepublishOnly":"tsup"},"_npmUser":{"name":"kallaspriit","email":"kallaspriit@gmail.com"},"repository":{"url":"git+https://github.com/kallaspriit/ts-log.git","type":"git"},"_npmVersion":"11.6.1","description":"Abstract logger TypeScript interface with a dummy logger that does nothing, useful for libraries.","directories":{},"_nodeVersion":"24.11.0","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.1","eslint":"^10.2.1","vitest":"^4.1.5","prettier":"^3.8.3","@eslint/js":"^10.0.1","typescript":"^6.0.3","@types/node":"^25.6.0","typescript-eslint":"^8.59.1","@vitest/coverage-v8":"^4.1.5","eslint-config-prettier":"^10.1.8"},"_npmOperationalInternal":{"tmp":"tmp/ts-log_3.0.2_1777379141663_0.9236076864614255","host":"s3://npm-registry-packages-npm-production"},"readme":"# ts-log\r\n\r\n[![CI](https://github.com/kallaspriit/ts-log/actions/workflows/ci.yml/badge.svg)](https://github.com/kallaspriit/ts-log/actions/workflows/ci.yml)\r\n[![Downloads](https://img.shields.io/npm/dm/ts-log.svg)](http://npm-stat.com/charts.html?package=ts-log)\r\n[![Version](https://img.shields.io/npm/v/ts-log.svg)](http://npm.im/ts-log)\r\n[![License](https://img.shields.io/npm/l/ts-log.svg)](http://opensource.org/licenses/MIT)\r\n[![StackGrit Score](https://img.shields.io/endpoint?url=https%3A%2F%2Ffleet-trout-946.convex.site%2Fapi%2Fbadge%2Fab080bce-08cf-4c0a-9ffa-c165470ad08d)](https://app.stackgrit.com/shared/b16e2501260e476597552a610a0b5542/reports/latest)\r\n\r\nA zero-dependency TypeScript logger interface. Let library consumers choose their own logger — or stay silent by default.\r\n\r\n## Installation\r\n\r\n```\r\nnpm install ts-log\r\n```\r\n\r\n## Usage\r\n\r\nAccept a `Logger` in your library's constructor, defaulting to `dummyLogger` (which does nothing):\r\n\r\n```typescript\r\nimport { Logger, dummyLogger } from \"ts-log\";\r\n\r\nclass MyService {\r\n  constructor(private readonly logger: Logger = dummyLogger) {}\r\n\r\n  doWork() {\r\n    this.logger.info(\"work started\");\r\n    // ...\r\n    this.logger.debug(\"details\", { foo: \"bar\" });\r\n  }\r\n}\r\n```\r\n\r\nConsumers can then pass in any compatible logger — or leave the default:\r\n\r\n```typescript\r\n// silent by default\r\nconst service = new MyService();\r\n\r\n// or use the built-in console\r\nconst service = new MyService(console);\r\n\r\n// or use pino, bunyan, winston, etc.\r\nimport pino from \"pino\";\r\nconst service = new MyService(pino());\r\n```\r\n\r\n## Logger Interface\r\n\r\nThe interface mirrors `console` — five methods, each accepting a message and optional parameters:\r\n\r\n```typescript\r\ninterface Logger {\r\n  trace(message?: any, ...optionalParams: any[]): void;\r\n  debug(message?: any, ...optionalParams: any[]): void;\r\n  info(message?: any, ...optionalParams: any[]): void;\r\n  warn(message?: any, ...optionalParams: any[]): void;\r\n  error(message?: any, ...optionalParams: any[]): void;\r\n}\r\n```\r\n\r\nAny object matching this shape works — no adapters needed. This includes `console`, [pino](https://github.com/pinojs/pino), [bunyan](https://github.com/trentm/node-bunyan), [winston](https://github.com/winstonjs/winston), and most other Node.js loggers.\r\n\r\n## Custom Logger\r\n\r\nYou can implement the interface directly for custom behavior:\r\n\r\n```typescript\r\nimport fs from \"node:fs\";\r\nimport { Logger } from \"ts-log\";\r\n\r\nclass FileLogger implements Logger {\r\n  private readonly fd: number;\r\n\r\n  constructor(filename: string) {\r\n    this.fd = fs.openSync(filename, \"a\");\r\n  }\r\n\r\n  trace(message?: any, ...params: any[]) {\r\n    this.write(\"TRACE\", message, params);\r\n  }\r\n  debug(message?: any, ...params: any[]) {\r\n    this.write(\"DEBUG\", message, params);\r\n  }\r\n  info(message?: any, ...params: any[]) {\r\n    this.write(\"INFO\", message, params);\r\n  }\r\n  warn(message?: any, ...params: any[]) {\r\n    this.write(\"WARN\", message, params);\r\n  }\r\n  error(message?: any, ...params: any[]) {\r\n    this.write(\"ERROR\", message, params);\r\n  }\r\n\r\n  private write(level: string, message: any, params: any[]) {\r\n    fs.writeSync(this.fd, `${new Date().toISOString()} ${level} ${message} ${JSON.stringify(params)}\\n`);\r\n  }\r\n}\r\n```\r\n\r\n## v3 Migration\r\n\r\nv3 is a tooling modernization — the `Logger` interface and `dummyLogger` API are unchanged.\r\n\r\n- Dual CJS/ESM package (via `exports` field).\r\n- `\"type\": \"module\"` added to package.json.\r\n- Minimum Node.js version is 20.\r\n- Build output moved from `build/src/` to `dist/`.\r\n\r\n## License\r\n\r\nMIT\r\n","publish_time":1777379141992,"_cnpm_publish_time":1777379141992,"dist-tags":{"latest":"3.0.3"}}