{"id":13484912,"url":"https://github.com/denosaurs/log","last_synced_at":"2025-05-04T20:50:07.527Z","repository":{"id":223280265,"uuid":"759543292","full_name":"denosaurs/log","owner":"denosaurs","description":"📜 Dead-simple drop-in logging solution using streams and the native console api","archived":false,"fork":false,"pushed_at":"2024-06-03T14:31:00.000Z","size":47,"stargazers_count":28,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-30T09:22:56.535Z","etag":null,"topics":["browser","bun","deno","log","logging","node","streams"],"latest_commit_sha":null,"homepage":"https://jsr.io/@denosaurs/log","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/denosaurs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"open_collective":"denosaurs","github":"denosaurs"}},"created_at":"2024-02-18T21:41:16.000Z","updated_at":"2025-04-26T22:25:11.000Z","dependencies_parsed_at":"2024-02-19T12:49:45.114Z","dependency_job_id":"cbcacb96-6709-4673-94cd-db587484d71e","html_url":"https://github.com/denosaurs/log","commit_stats":{"total_commits":33,"total_committers":1,"mean_commits":33.0,"dds":0.0,"last_synced_commit":"0fabf7c547c4f27574a0d448a55ada0575f7a23b"},"previous_names":["denosaurs/log"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denosaurs%2Flog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denosaurs%2Flog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denosaurs%2Flog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denosaurs%2Flog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denosaurs","download_url":"https://codeload.github.com/denosaurs/log/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252379076,"owners_count":21738512,"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":["browser","bun","deno","log","logging","node","streams"],"created_at":"2024-07-31T17:01:38.560Z","updated_at":"2025-05-04T20:50:07.503Z","avatar_url":"https://github.com/denosaurs.png","language":"TypeScript","funding_links":["https://opencollective.com/denosaurs","https://github.com/sponsors/denosaurs"],"categories":["TypeScript","browser"],"sub_categories":[],"readme":"# Log\n\nThe denosaurs log module is a tiny, cross-platform, drop-in module for handling\nlogs using streams. It has been tested and works in the browser, Deno, Node and\nBun with second-class support for all runtimes and environments which implement\n[web streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API).\n\n## Installation\n\n**Log** is supported in all runtimes and environments which implement web\nstreams, but installation method may differ between runtimes. It is published to\n[jsr](https://jsr.io/).\n\n### Deno\n\nImport it directly from JSR using the `jsr` protocol.\n\n```typescript\nimport { ConsoleReadableStream } from \"jsr:@denosaurs/log\";\n```\n\nOr add it to your\n[import map](https://docs.deno.com/runtime/manual/basics/import_maps) or\n[`deno.json`](https://docs.deno.com/runtime/manual/getting_started/configuration_file):\n\n```json\n{\n  \"imports\": {\n    \"log\": \"jsr:@denosaurs/log\"\n  }\n}\n```\n\n### Node and Bun\n\nAdd this line to the project's\n[.npmrc](https://docs.npmjs.com/cli/v10/configuring-npm/npmrc) file or the\nglobal one.\n\n```\n@jsr:registry=https://npm.jsr.io\n```\n\nAnd install the package using npm or the package manager of your choice.\n\n```bash\nnpm install @jsr/denosaurs__log\n```\n\nIf you would like a prettier package name I would suggest changing it in the\n`package.json` file to something like `@denosaurs/log`.\n\n```diff\n{\n  \"dependencies\": {\n-    \"@jsr/denosaurs__log\": \"*\"\n+    \"@denosaurs/log\": \"npm:@jsr/denosaurs__log\"\n  }\n}\n```\n\n## Examples\n\n\u003cdetails\u003e\n\u003csummary\u003e\nNote that we use the \u003ccode\u003eJsonStringifyStream\u003c/code\u003e from the deno standard library in the example.\nIn Node, Bun and other runtimes you can install it from \u003ca href=\"https://jsr.io/@std/json\"\u003ejsr\u003c/a\u003e.\n\u003c/summary\u003e\n\nAdd this line to the project's\n[.npmrc](https://docs.npmjs.com/cli/v10/configuring-npm/npmrc) file or the\nglobal one.\n\n```\n@jsr:registry=https://npm.jsr.io\n```\n\nAnd install the package using npm or the package manager of your choice.\n\n```bash\nnpm install @jsr/std__json\n```\n\nIf you would like a prettier package name I would suggest changing it in the\n`package.json` file to something like `@std/json`.\n\n```diff\n{\n  \"dependencies\": {\n-    \"@jsr/std__json\": \"*\"\n+    \"@std/json\": \"npm:@jsr/std__json\"\n  }\n}\n```\n\n\u003c/details\u003e\n\n### [JSON](./examples/json/json.js)\n\nThe following example demonstrates how to capture and log messages as JSON to\nstdout.\n\n```typescript\n// Ensure Bun compatibility. [It currently lacks support for TextEncoderStream](https://github.com/oven-sh/bun/issues/5648)\nimport \"@denosaurs/log/transforms/text_encoder_stream\";\n\nimport { ConsoleReadableStream } from \"@denosaurs/log\";\n\nimport { StdoutWritableStream } from \"@denosaurs/log/writables/std\";\n\nimport { JsonStringifyStream } from \"@std/json\";\n\n// Capture logs from the console\nconst stream = new ConsoleReadableStream();\nstream\n  // Stringify the logs to JSON\n  .pipeThrough(new JsonStringifyStream())\n  // Encode the output to an UTF-8 byte stream\n  .pipeThrough(new TextEncoderStream())\n  // Pipe the output to stdout\n  .pipeTo(new StdoutWritableStream());\n\n// Log some messages\nconsole.log(\"Hello, world!\");\nconsole.group(\"Group 1\");\nconsole.debug(\"Debug message\");\nconsole.groupEnd();\nconsole.info(\"Info message\");\n```\n\n### [Teeing](./examples/tee/tee.js)\n\nSometimes you may want to log messages to multiple destinations. This can be\ndone using\n[teeing](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams#teeing_a_stream).\n\nIn the example we also use the `OmitLogLevelStream` and `PickLogLevelStream` to\nfilter the logs before they are written to the different destinations.\n\n```typescript\n// Ensure Bun compatibility. [It currently lacks support for TextEncoderStream](https://github.com/oven-sh/bun/issues/5648)\nimport \"@denosaurs/log/transforms/text_encoder_stream\";\n\nimport { ConsoleReadableStream } from \"@denosaurs/log\";\n\nimport {\n  StderrWritableStream,\n  StdoutWritableStream,\n} from \"@denosaurs/log/writables/std\";\n\nimport { OmitLogLevelStream } from \"@denosaurs/log/transforms/omit\";\nimport { PickLogLevelStream } from \"@denosaurs/log/transforms/pick\";\n\nimport { JsonStringifyStream } from \"@std/json\";\n\n// Capture logs from the console\nconst stream = new ConsoleReadableStream();\n// Split the stream in two\nconst [a, b] = stream.tee();\n\na\n  // Omit only the error logs\n  .pipeThrough(new OmitLogLevelStream(\"error\"))\n  // Stringify the logs to JSON\n  .pipeThrough(new JsonStringifyStream())\n  // Encode the output to an UTF-8 byte stream\n  .pipeThrough(new TextEncoderStream())\n  // Pipe the output to stdout\n  .pipeTo(new StdoutWritableStream());\n\nb\n  // Pick only the error logs\n  .pipeThrough(new PickLogLevelStream(\"error\"))\n  // Stringify the logs to JSON\n  .pipeThrough(new JsonStringifyStream())\n  // Encode the output to an UTF-8 byte stream\n  .pipeThrough(new TextEncoderStream())\n  // Pipe the output to stderr\n  .pipeTo(new StderrWritableStream());\n\n// Log some messages\nconsole.error(\"This is going to stderr\");\nconsole.trace(\"This is going to stdout\");\nconsole.debug(\"This is going to stdout\");\nconsole.info(\"This is going to stdout\");\nconsole.warn(\"This is going to stdout\");\nconsole.log(\"This is going to stdout\");\n```\n\n## Features\n\nThe module is still young, with lot's of planned features and improvements. **It\nis far from stable, so expect breaking changes.** But anyways, here are some\nfeatures:\n\n- [ ] Add support for more runtimes and environments\n  - The goal should be to support all [WinterCG](https://wintercg.org/)\n    compatible runtimes\n  - [x] [Deno](https://deno.land/)\n  - [ ] **Untested** [Deno Deploy](https://deno.com/deploy/)\n  - [x] [Node.js](https://nodejs.org/)\n  - [x] [Bun](https://bun.sh/)\n  - [ ] **Untested** [Cloudflare Workers](https://workers.cloudflare.com/)\n  - [ ] **Untested** [Vercel Edge Runtime](https://edge-runtime.vercel.app/)\n  - [ ] **Untested** [Fastly Compute](https://www.fastly.com/products/compute/)\n  - [ ] **Untested** [LLRT](https://github.com/awslabs/llrt)\n  - [ ] **Untested** Browsers\n- [ ] Exception and rejection handling\n  - [ ] Add a `fatal` log level, which will be used for unhandled exceptions and\n        rejections. Unreachable from the normal `console` API.\n- [ ] Metrics/timings using `console.time` and `console.timeEnd`\n- [ ] Transforms\n  - [x] [Filter](./transforms/filter.ts)\n  - [x] [Omit](./transforms/omit.ts)\n  - [x] [Pick](./transforms/pick.ts)\n  - [x] JSON (Using [`JsonStringifyStream`](https://deno.land/std/json/mod.ts))\n  - [x] Redaction\n    - [x] `[Symbol.for(\"log.secret\")]` (This only works when not using\n          [`structuredClone`](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#javascript_types)\n          because `symbol`s are not cloneable. A future fix for this might be to\n          write our own `structuredClone` function which keeps symbols.)\n    - [x] Exact match\n    - [x] Regex\n    - [x] [fast-redact](https://github.com/davidmarkclements/fast-redact)\n  - [ ] Request and response metadata\n    - [ ] `[Symbol.for(\"log.request\")]` or `instanceof Request`\n    - [ ] `[Symbol.for(\"log.response\")]` or `instanceof Response`\n  - [ ] Pretty print\n  - [ ] [Logfmt](https://brandur.org/logfmt)\n- [ ] Destinations\n  - [x] Console\n  - [x] Stdout\n  - [x] Stderr\n  - [ ] File\n    - [ ] Single file\n    - [ ] Rotating file\n  - [ ] Network\n    - [ ] Fetch\n    - [ ] WebSocket\n    - [ ] UDP\n    - [ ] TCP\n  - [ ] Integrations\n    - [ ] [OpenTelemetry](https://opentelemetry.io/docs/specs/otel/logs/)\n    - [ ] [Logstash](https://www.elastic.co/logstash/)\n- [ ] First-class support for popular web-frameworks\n  - [ ] [Hono](https://github.com/honojs/hono)\n  - [ ] [Express](https://github.com/expressjs/express)\n  - [ ] [Koa](https://github.com/koajs/koa)\n  - [ ] [Oak](https://github.com/oakserver/oak)\n  - [ ] [Fastify](https://github.com/fastify/fastify)\n\n## Goals\n\nSome goals of this module are:\n\n- **Web Standards** - It should to the greatest extent possible follow web\n  standards and try to emulate (and in the case of `console` extend) the\n  standards we already know and love.\n- **Ease of use** - It should be easy to use and understand. It should be\n  familiar, or dare I say, effortless to anyone who has used the `console`.\n- **Minimal** - It should be as small as possible, with minimal dependencies.\n  Logging doesn't have to be complicated.\n- **Performance** - It needs to be fast. It should never noticeably slow down\n  the application. Logging is a critical part of the application, but it should\n  never be the bottleneck.\n- **Quality** - It should be well tested and well documented. It should be\n  reliable and trustworthy.\n\n## Maintainers\n\n- Elias Sjögreen ([@eliassjogreen](https://github.com/eliassjogreen))\n\n## Contributing\n\nPull request, issues and feedback are very welcome. Code style is formatted with\n`deno fmt` and commit messages are done following Conventional Commits spec.\n\nPlease use it! And let us know if you have any issues, feedback or requests.\n\n## Licence\n\nCopyright 2024, the Denosaurs team. All rights reserved. MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenosaurs%2Flog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenosaurs%2Flog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenosaurs%2Flog/lists"}