{"id":48089606,"url":"https://github.com/vllnt/logger","last_synced_at":"2026-04-04T15:28:56.022Z","repository":{"id":343497045,"uuid":"1174786426","full_name":"vllnt/logger","owner":"vllnt","description":"Structured JSON logging for the @vllnt ecosystem. Zero deps, tree-shakeable, multi-runtime (Node, Convex, browser, edge).","archived":false,"fork":false,"pushed_at":"2026-03-10T17:26:26.000Z","size":80,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-10T21:35:06.271Z","etag":null,"topics":["convex","logger","posthog","structured-logging","tree-shakeable","typescript","zero-dependencies"],"latest_commit_sha":null,"homepage":null,"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/vllnt.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-06T20:55:39.000Z","updated_at":"2026-03-10T17:26:29.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/vllnt/logger","commit_stats":null,"previous_names":["vllnt/logger"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/vllnt/logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vllnt%2Flogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vllnt%2Flogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vllnt%2Flogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vllnt%2Flogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vllnt","download_url":"https://codeload.github.com/vllnt/logger/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vllnt%2Flogger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31403958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T10:20:44.708Z","status":"ssl_error","status_checked_at":"2026-04-04T10:20:06.846Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["convex","logger","posthog","structured-logging","tree-shakeable","typescript","zero-dependencies"],"created_at":"2026-04-04T15:28:54.415Z","updated_at":"2026-04-04T15:28:55.820Z","avatar_url":"https://github.com/vllnt.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @vllnt/logger\n\nStructured JSON logging for the [@vllnt](https://github.com/vllnt) ecosystem.\n\nZero runtime dependencies. Tree-shakeable. Works in Node.js, Convex, browser, and edge runtimes.\n\n## Install\n\n```bash\npnpm add @vllnt/logger\n```\n\n## Quick Start\n\n```ts\nimport { createBackendLogger } from \"@vllnt/logger\";\n\nconst logger = createBackendLogger(\"auth\");\n\nlogger.info(\"login\", { userId: \"123\" });\n// → {\"event\":\"auth.login\",\"level\":\"info\",\"timestamp\":\"...\",\"userId\":\"123\"}\n\nlogger.warn(\"rate-limited\", { ip: \"1.2.3.4\" });\n```\n\nSet `LOG_LEVEL` env var to control verbosity (`debug`, `info`, `warn`, `error`). Defaults to `warn`.\n\n## Subpath Exports\n\n| Import | Use Case |\n|--------|----------|\n| `@vllnt/logger` | Core API + Node.js backend preset |\n| `@vllnt/logger/convex` | Convex-safe logger (no `process.env`) |\n| `@vllnt/logger/posthog` | PostHog output adapter |\n| `@vllnt/logger/testing` | In-memory test output for assertions |\n\n## API\n\n### `createBackendLogger(scope): ExtendedLogger`\n\nPre-configured for Node.js. Reads `LOG_LEVEL` from `process.env` lazily on each log call.\n\n```ts\nconst logger = createBackendLogger(\"payments\");\nlogger.info(\"charge\", { amount: 99, currency: \"usd\" });\n```\n\n### `createLogger(scope, config): Logger`\n\nCore factory. Bring your own level strategy and output.\n\n```ts\nimport { createLogger, consoleOutput } from \"@vllnt/logger\";\n\nconst logger = createLogger(\"api\", {\n  getLogLevel: () =\u003e \"debug\",\n  output: consoleOutput,\n});\n```\n\n### `createExtendedLogger(scope, config): ExtendedLogger`\n\nSame as `createLogger` but adds `withTiming` and `withTimingSync` helpers.\n\n```ts\nconst result = await logger.withTiming(\"db.query\", async () =\u003e {\n  return db.query(\"SELECT ...\");\n});\n// Logs: scope.db.query.start → scope.db.query.complete (with durationMs)\n// On error: scope.db.query.error (with durationMs + error message)\n```\n\n### `composeOutputs(...outputs): LogOutput`\n\nFan-out to multiple outputs. Each output is error-isolated.\n\n```ts\nimport { composeOutputs, consoleOutput } from \"@vllnt/logger\";\nimport { createPostHogOutput } from \"@vllnt/logger/posthog\";\n\nconst output = composeOutputs(\n  consoleOutput,\n  createPostHogOutput(posthog.capture.bind(posthog)),\n);\n```\n\n### `createConvexLogger(scope, level?): ExtendedLogger`\n\nSafe for Convex queries, mutations, and actions. No `process.env` access.\n\n```ts\nimport { createConvexLogger } from \"@vllnt/logger/convex\";\n\nconst logger = createConvexLogger(\"myFunction\", \"debug\");\nlogger.info(\"started\");\n```\n\n### `createPostHogOutput(capture): LogOutput`\n\nWraps a PostHog-compatible `capture` function as a `LogOutput`. Swallows errors.\n\n```ts\nimport { createPostHogOutput } from \"@vllnt/logger/posthog\";\n\nconst output = createPostHogOutput(posthog.capture.bind(posthog));\n```\n\n### `createTestOutput(): TestOutput`\n\nCaptures log entries in-memory for test assertions.\n\n```ts\nimport { createTestOutput } from \"@vllnt/logger/testing\";\nimport { createLogger } from \"@vllnt/logger\";\n\nconst { entries, output } = createTestOutput();\nconst logger = createLogger(\"test\", {\n  getLogLevel: () =\u003e \"debug\",\n  output,\n});\n\nlogger.info(\"hello\", { a: 1 });\nexpect(entries[0].event).toBe(\"test.hello\");\n```\n\n### Utilities\n\n| Function | Description |\n|----------|-------------|\n| `formatLogEntry(level, event, data?)` | Build a `LogEntry` manually |\n| `parseLogLevel(value, default?)` | Safe `string` to `LogLevel` parsing |\n| `consoleOutput(entry)` | JSON to `console.debug/info/warn/error` (crash-safe) |\n\n## Types\n\n```ts\ntype LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\";\ntype LogData = Record\u003cstring, unknown\u003e;\ntype LogEntry = { event: string; level: LogLevel; timestamp: string } \u0026 Record\u003cstring, unknown\u003e;\ntype LogOutput = (entry: LogEntry) =\u003e void;\ntype Logger = { debug, info, warn, error: (event: string, data?: LogData) =\u003e void };\ntype ExtendedLogger = Logger \u0026 { withTiming, withTimingSync };\ntype LoggerConfig = { getLogLevel: () =\u003e LogLevel; output: LogOutput };\n```\n\n## Design Decisions\n\n- **Scoped events**: All events are prefixed with the logger scope (`auth.login`, `payments.charge`)\n- **Reserved field protection**: User data cannot overwrite `event`, `level`, or `timestamp`\n- **Crash-safe serialization**: `BigInt`, circular refs, and throwing `toJSON` are caught gracefully\n- **Synchronous outputs**: `LogOutput` is synchronous by design — async adapters manage their own promises\n- **Lazy level evaluation**: `getLogLevel()` is called per-emit, so env changes are picked up without restart\n- **Zero side effects**: Core module has zero module-level side effects (`sideEffects: false`)\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvllnt%2Flogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvllnt%2Flogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvllnt%2Flogger/lists"}