{"_id":"@apihive/logger-facade","_rev":"2-e3fc722a523b72c190991252d112f585","name":"@apihive/logger-facade","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@apihive/logger-facade","version":"1.0.0","author":{"name":"Nicola Dal Pont"},"license":"MIT","_id":"@apihive/logger-facade@1.0.0","maintainers":[{"name":"aekidna","email":"ndalpont@gmail.com"}],"dist":{"shasum":"4e4722f850605d911be6227f205fa47e8618f45a","tarball":"https://registry.npmjs.org/@apihive/logger-facade/-/logger-facade-1.0.0.tgz","fileCount":11,"integrity":"sha512-cA8cgomkoN/bQKax6d6nAIfH3qDexaZ3aLEVeiO+JZLfzcvyKMNigj/1B1CY5UDQhp65K/p8tedIiUS8I9dZMw==","signatures":[{"sig":"MEYCIQCt4f9BKXggxvGV3rcp9drHESE38L8HfHdWXQR/4INuAwIhAPUCRu2uuzt2BddOcldEFCo5Ocpoy6FYv4whbBSjEb8P","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":9256},"main":"./lib/index.js","type":"module","types":"./lib/index.d.ts","module":"./lib/index.js","exports":{".":{"types":"./lib/index.d.ts","import":"./lib/index.js"}},"scripts":{"build":"tsc -p tsconfig.json","prepublishOnly":"npm run build"},"_npmUser":{"name":"aekidna","email":"ndalpont@gmail.com"},"_npmVersion":"10.9.2","description":"A minimal logging facade: LogLevel, LoggerFacade, and a ConsoleLogger implementation.","directories":{},"_nodeVersion":"22.13.0","_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.9.2"},"_npmOperationalInternal":{"tmp":"tmp/logger-facade_1.0.0_1754796763011_0.6149017962904786","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@apihive/logger-facade","version":"1.0.1","description":"A minimal logging facade: LogLevel, LoggerFacade, and a ConsoleLogger implementation.","type":"module","main":"./lib/index.js","module":"./lib/index.js","types":"./lib/index.d.ts","exports":{".":{"import":"./lib/index.js","types":"./lib/index.d.ts"}},"scripts":{"build":"tsc -p tsconfig.json","clean":"rm -rf lib","prepublishOnly":"yarn build","publish:jsr":"npx jsr publish","publish:npm":"npm run build && npm publish"},"author":{"name":"Nicola Dal Pont"},"license":"MIT","devDependencies":{"tsc":"^2.0.4","typescript":"^5.9.2"},"_id":"@apihive/logger-facade@1.0.1","gitHead":"ab7c55667da0f9d652204f9f6b2ec87787547b62","_nodeVersion":"22.13.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-lDo7GDvz0wwNVhvrTTCAcyeshvbHvDNcK8YxWtlch5m3M3WnAV2ivR466feD1oIJIgPWm8x6P2DFC1EEuRBYcQ==","shasum":"262b143bf1d9da185b2d546371625de41087888b","tarball":"https://registry.npmjs.org/@apihive/logger-facade/-/logger-facade-1.0.1.tgz","fileCount":11,"unpackedSize":9305,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCCZxXVNMHua9PRXGAZ0tsazOVvT9WSyHJjA6KXAdmDzwIgDMhY5BWtnmfGIm8KiW7NFMHsriMID4FJNF8Po9iYaEo="}]},"_npmUser":{"name":"aekidna","email":"ndalpont@gmail.com"},"directories":{},"maintainers":[{"name":"aekidna","email":"ndalpont@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/logger-facade_1.0.1_1755912425483_0.36184465440866287"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-10T03:32:42.897Z","modified":"2025-08-23T01:27:05.864Z","1.0.0":"2025-08-10T03:32:43.204Z","1.0.1":"2025-08-23T01:27:05.669Z"},"author":{"name":"Nicola Dal Pont"},"license":"MIT","description":"A minimal logging facade: LogLevel, LoggerFacade, and a ConsoleLogger implementation.","maintainers":[{"name":"aekidna","email":"ndalpont@gmail.com"}],"readme":"# @apihive/logger-facade\n\nA tiny, framework-agnostic logging facade that standardizes how libraries and applications log.\n\n- Unify logging behind a minimal interface (`LoggerFacade` + `LogLevel`).\n- Delegate the actual logging to the library of your choice (pino, winston, console, etc.).\n- Swap or configure loggers per environment without changing your code.\n\n> The core idea: any app/module using this facade delegates logging to a single, unified logger chosen by the project. Libraries depend on the facade – applications decide which logger implementation to plug in.\n\n## Why this package?\n\n- **Consistency**: Libraries and modules don’t need to pick a logging engine. They depend on the facade; your application provides the implementation.\n- **Flexibility**: Swap implementations (console in the browser, pino in Node, mocked logger in tests) without refactoring call sites.\n- **Simplicity**: A minimal API covering common levels and a `withMinimumLevel` filter.\n- **Portability**: Works in Node, Bun, Deno, and browsers.\n\n## Ready made facades\n\n- `ConsoleLogger` (built-in)\n- [`PinoLoggerFacade`](https://npmjs.com/package/@apihive/logger-facade-pino) for the popular [pino logger](https://github.com/pinojs/pino)\n\n## Install\n\nnpm:\n```sh\nnpm i @apihive/logger-facade\n```\n\nyarn:\n```sh\nyarn add @apihive/logger-facade\n```\n\nDeno (via JSR):\n```ts\nimport { LoggerFacade, ConsoleLogger } from \"jsr:@apihive/logger-facade\";\n```\n\n## Quick start\n\n```ts\nimport { ConsoleLogger } from \"@apihive/logger-facade\";\n\nconst logger = new ConsoleLogger().withMinimumLevel(\"info\");\n\nlogger.debug(\"hidden\"); // filtered out\nlogger.info(\"hello world\");\nlogger.error(\"something went wrong\", { code: 123 });\n```\n\n## API\n\n```ts\nexport type LogLevel = \"none\" | \"trace\" | \"debug\" | \"info\" | \"warn\" | \"error\" | \"fatal\";\n\nexport type LoggerFacade = {\n  withMinimumLevel(level: LogLevel): LoggerFacade;\n  trace(message: string, ...args: any[]): void;\n  debug(message: string, ...args: any[]): void;\n  info(message: string, ...args: any[]): void;\n  warn(message: string, ...args: any[]): void;\n  error(message: string, ...args: any[]): void;\n  fatal(message: string, ...args: any[]): void;\n};\n```\n\n## Included implementation: ConsoleLogger\n\nA no-dependency logger that writes to the browser/Node console and supports runtime level filtering via `withMinimumLevel`.\n\n```ts\nimport { ConsoleLogger } from \"@apihive/logger-facade\";\n\nconst log = new ConsoleLogger().withMinimumLevel(\"warn\");\nlog.info(\"hidden\");\nlog.warn(\"visible\");\nlog.error(\"visible\");\n```\n\n## Create your own adapter\n\nYou can wrap any logger to conform to `LoggerFacade`. \n\n```ts\nimport MyLogger from \"MyLogger\";\nimport type { LoggerFacade, LogLevel } from \"@apihive/logger-facade\";\n\nexport function myLoggerFacade(base = new MyLogger()): LoggerFacade {\n  return {\n    withMinimumLevel(level: LogLevel) : LoggerFacade {\n      return myLoggerFacade(base.spawn({ level }));\n    },\n    trace: (m, ...a) => base.trace(m, ...a),\n    debug: (m, ...a) => base.debug(m, ...a),\n    info:  (m, ...a) => base.info(m, ...a),\n    warn:  (m, ...a) => base.warn(m, ...a),\n    error: (m, ...a) => base.error(m, ...a),\n    fatal: (m, ...a) => base.fatal(m, ...a),\n  };\n}\n```\n\n## Usage in libraries\n\nLibraries should accept a `LoggerFacade` (optionally with a default `ConsoleLogger`) and use it internally, e.g.:\n\n```ts\nimport type { LoggerFacade } from \"@apihive/logger-facade\";\n\nexport function makeThing(logger: LoggerFacade) {\n  logger.debug(\"creating thing\");\n  // ...\n}\n```\n\nApplications decide which implementation to pass:\n\n```ts\nimport { ConsoleLogger } from \"@apihive/logger-facade\";\nimport { makeThing } from \"my-lib\";\n\nmakeThing(new ConsoleLogger().withMinimumLevel(\"info\"));\n```\n\n## Design goals\n\n- **Minimal**: Just the common levels + level threshold.\n- **Extensible**: Add your own wrappers for any logging backend.\n- **Stable**: Low churn surface; easy to depend on from libraries.\n\n## License\n\nMIT © apihive\n","readmeFilename":"README.md"}