{"_id":"@ashulab/universal-logger","_rev":"2-59cdd6fd11ef7c72f75b03243ec55a80","name":"@ashulab/universal-logger","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@ashulab/universal-logger","version":"0.1.0","keywords":["logger","logging","universal","isomorphic","browser","node","typescript","esm"],"author":{"name":"Diego Ghersi"},"license":"MIT","_id":"@ashulab/universal-logger@0.1.0","maintainers":[{"name":"ghersidl","email":"ghersidl@gmail.com"}],"homepage":"https://github.com/vemec/universal-logger#readme","bugs":{"url":"https://github.com/vemec/universal-logger/issues"},"dist":{"shasum":"48a45e3214b333c49abebfd0e98c363f479aba88","tarball":"https://registry.npmjs.org/@ashulab/universal-logger/-/universal-logger-0.1.0.tgz","fileCount":6,"integrity":"sha512-fYF3tn8EKowuzW6lBguQlkPtiZV3L6JIzb6n5N31vrPr6aNFelkRf3uViC75oT1JOpE45yWMB9bAeIzF/4eS9g==","signatures":[{"sig":"MEUCIQClPTL7z3eLi1YonZJoMEc6cslBoyaIOeHr3MDJ1JKHDAIgbr3aoHDEp8IdxdOTvyBvDUbagBB+qSiwnKTr22xJUho=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":35769},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=18"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"gitHead":"199eb05579c084f99bb220ede7ea0a81ff8cff5d","scripts":{"dev":"tsup --watch","test":"npm run build && NODE_ENV=test node --test","build":"tsup","typecheck":"tsc --noEmit","prepublishOnly":"npm run typecheck && npm run build"},"_npmUser":{"name":"ghersidl","email":"ghersidl@gmail.com"},"repository":{"url":"git+https://github.com/vemec/universal-logger.git","type":"git"},"_npmVersion":"11.9.0","description":"Isomorphic logger for Node.js and the browser — log levels, scoped loggers, structured server output and provider-agnostic error reporting, with zero config.","directories":{},"sideEffects":false,"_nodeVersion":"25.6.0","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8","typescript":"^5","@types/node":"^20"},"_npmOperationalInternal":{"tmp":"tmp/universal-logger_0.1.0_1782072398577_0.5904300883065321","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@ashulab/universal-logger","version":"0.1.1","description":"Isomorphic logger for Node.js and the browser — log levels, scoped loggers, structured server output and provider-agnostic error reporting, with zero config.","type":"module","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"main":"./dist/index.js","module":"./dist/index.js","types":"./dist/index.d.ts","sideEffects":false,"keywords":["logger","logging","universal","isomorphic","browser","node","typescript","esm"],"author":"Diego Ghersi","license":"MIT","repository":{"type":"git","url":"git+https://github.com/AshuLab/universal-logger.git"},"bugs":{"url":"https://github.com/AshuLab/universal-logger/issues"},"homepage":"https://github.com/AshuLab/universal-logger#readme","engines":{"node":">=18"},"devDependencies":{"@types/node":"^20","tsup":"^8","typescript":"^5"},"scripts":{"build":"tsup","dev":"tsup --watch","typecheck":"tsc --noEmit","test":"npm run build && NODE_ENV=test node --test"},"_nodeVersion":"25.6.0","_id":"@ashulab/universal-logger@0.1.1","dist":{"integrity":"sha512-EKARUNoWSPir7C/thAfYEYlX/i0pKqd5ew91NJGH9X8Owl/wPEBDEgE6gFRGXFP9HctxnnjKqe1qOhIJG0kEKw==","shasum":"b95bed34bfc80217caf19fbc1adb2b61a3ac47fe","tarball":"https://registry.npmjs.org/@ashulab/universal-logger/-/universal-logger-0.1.1.tgz","fileCount":6,"unpackedSize":35714,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQC4qak7lBJLtnV+koIL/bey+ikDPtqWpHx0yw8B0hoNdQIgZRWYcJZ0EzFCd0g9faGUcZWYs8ZGElnW87khX5EZyD0="}]},"_npmUser":{"name":"ghersidl","email":"ghersidl@gmail.com"},"directories":{},"maintainers":[{"name":"ghersidl","email":"ghersidl@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/universal-logger_0.1.1_1788787618070_0.6515039562323872"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-21T20:06:38.441Z","modified":"2026-09-07T13:26:58.408Z","0.1.0":"2026-06-21T20:06:38.708Z","0.1.1":"2026-09-07T13:26:58.208Z"},"bugs":{"url":"https://github.com/AshuLab/universal-logger/issues"},"author":"Diego Ghersi","license":"MIT","homepage":"https://github.com/AshuLab/universal-logger#readme","keywords":["logger","logging","universal","isomorphic","browser","node","typescript","esm"],"repository":{"type":"git","url":"git+https://github.com/AshuLab/universal-logger.git"},"description":"Isomorphic logger for Node.js and the browser — log levels, scoped loggers, structured server output and provider-agnostic error reporting, with zero config.","maintainers":[{"name":"ghersidl","email":"ghersidl@gmail.com"}],"readme":"# universal-logger\n\nIsomorphic logger for **Node.js** and the **browser**. It auto-detects the\nexecution context and adjusts behavior — structured object logs on the server,\nformatted strings on the client — with a single, consistent API and no\nconfiguration required.\n\n- 🌐 **Universal**: same import works on server and client (import-safe even\n  when `process` is not defined in the browser).\n- 🎚️ **Log levels**: `debug`, `info`, `warn`, `error` behind a single min-level threshold.\n- 🏷️ **Scoped loggers**: prefix every log with a module/service name.\n- 🧱 **Structured server output**: JSON in production, readable objects in dev.\n- 🪝 **Provider-agnostic error reporting**: wire any sink — Sentry, Datadog, a custom endpoint.\n- 📦 **ESM-only**, zero runtime dependencies.\n\n## Install\n\n```bash\nnpm install universal-logger\n```\n\n> Requires Node.js >= 18. ESM only — use `import`, not `require`.\n\n## Usage\n\n```ts\nimport { logInfo, logError, createScopedLogger } from 'universal-logger';\n\nlogInfo('Server started', { port: 3000 });\n\ntry {\n  await fetchData();\n} catch (err) {\n  logError('Failed to fetch data', err, { url: '/api/data' });\n}\n\nconst log = createScopedLogger('AuthService');\nlog.debug('Checking token');\nlog.info('User authenticated');\n```\n\n## Behavior by environment\n\n| | Server (Node.js) | Client (browser) |\n|---|---|---|\n| Format | Structured object / JSON | Formatted string |\n| Default min level | `debug` in dev, `warn` in prod | `debug` in dev, `warn` in prod |\n| Prefix | none | `[App]` |\n\nA single min-level threshold governs what is logged, with the same model on\nserver and client: in development (`NODE_ENV=development`) everything from\n`debug` up; in production only `warn` and `error`. Override it anytime via\n`configureUniversalLogger({ minLevel })` or the `LOG_LEVEL` env var.\n\nOn the server, dev mode prints readable objects; otherwise it emits one-line\nJSON suitable for log collectors.\n\n## Configuration\n\n```ts\nimport { configureUniversalLogger, LogLevel } from 'universal-logger';\n\nconfigureUniversalLogger({\n  enabled: true,\n  minLevel: LogLevel.INFO,\n  prefix: '[MyApp]',\n});\n```\n\n### Environment variables\n\n| Variable | Effect |\n|---|---|\n| `LOG_LEVEL` | Sets the default min level (`debug` \\| `info` \\| `warn` \\| `error`). Read on the server; on the client set the level via `configureUniversalLogger`. |\n| `NODE_ENV=development` | When `LOG_LEVEL` is unset, lowers the default to `debug` and switches server output to readable objects. |\n\n## Error reporting (provider-agnostic)\n\n`logError` forwards exceptions to a reporter of your choosing — Sentry,\nDatadog, Rollbar, a custom endpoint, anything — on both server and client.\nOnly `configureUniversalLogger({ enabled: false })` stops it.\n\nThe reporter receives the original error untouched (or a synthetic `Error` when\n`logError` is called without one) plus `{ message, context }`, and is\nresponsible for shaping it for its provider. Register it once at startup:\n\n```ts\nimport * as Sentry from '@sentry/node';\nimport { setErrorReporter } from 'universal-logger';\n\nsetErrorReporter((error, { message, context }) => {\n  Sentry.captureException(error instanceof Error ? error : new Error(message), {\n    extra: { message, ...context },\n  });\n});\n```\n\nAny other provider follows the same shape:\n\n```ts\nsetErrorReporter((error, { message, context }) => {\n  myMonitoring.report({ error, message, ...context });\n});\n```\n\n## API\n\n| Export | Description |\n|---|---|\n| `logDebug(message, context?)` | Debug-level log |\n| `logInfo(message, context?)` | Info-level log |\n| `logWarn(message, context?)` | Warning-level log |\n| `logError(message, error?, context?)` | Error-level log; forwards to the error reporter |\n| `createScopedLogger(scope)` | Returns `{ debug, info, warn, error }` prefixed with `[scope]` |\n| `configureUniversalLogger(config)` | Override `enabled` / `minLevel` / `prefix` |\n| `setErrorReporter(fn)` | Register a provider-agnostic error reporter |\n| `LogLevel` | Enum: `DEBUG`, `INFO`, `WARN`, `ERROR` |\n\n## Scripts\n\n```bash\nnpm run build      # bundle to dist/ (ESM + .d.ts) with tsup\nnpm run dev        # build in watch mode\nnpm run typecheck  # tsc --noEmit\nnpm test           # build + run the node:test suite\n```\n\n## License\n\nMIT © Diego Ghersi\n","readmeFilename":""}