{"id":13455781,"url":"https://github.com/maraisr/diary","last_synced_at":"2025-03-31T04:04:19.403Z","repository":{"id":37043076,"uuid":"294836783","full_name":"maraisr/diary","owner":"maraisr","description":"📑 Zero-dependency, fast logging library for Node, Browser and Workers","archived":false,"fork":false,"pushed_at":"2024-09-06T03:03:36.000Z","size":507,"stargazers_count":253,"open_issues_count":1,"forks_count":7,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-10-30T03:57:08.243Z","etag":null,"topics":["cloudflare-workers","debug","fast","logger","logging","logging-library","middleware","pino","winston"],"latest_commit_sha":null,"homepage":"","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/maraisr.png","metadata":{"funding":{"github":"maraisr"},"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}},"created_at":"2020-09-12T00:10:28.000Z","updated_at":"2024-10-26T16:10:10.000Z","dependencies_parsed_at":"2024-01-19T02:18:21.686Z","dependency_job_id":"8c1c6498-1460-4e70-94d1-07b8b32370d9","html_url":"https://github.com/maraisr/diary","commit_stats":{"total_commits":132,"total_committers":6,"mean_commits":22.0,"dds":"0.037878787878787845","last_synced_commit":"8fa3fdf5ca1e62885ba15d9e09b61a778aa4461e"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maraisr%2Fdiary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maraisr%2Fdiary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maraisr%2Fdiary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maraisr%2Fdiary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maraisr","download_url":"https://codeload.github.com/maraisr/diary/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246413230,"owners_count":20773053,"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":["cloudflare-workers","debug","fast","logger","logging","logging-library","middleware","pino","winston"],"created_at":"2024-07-31T08:01:11.000Z","updated_at":"2025-03-31T04:04:19.384Z","avatar_url":"https://github.com/maraisr.png","language":"TypeScript","funding_links":["https://github.com/sponsors/maraisr","https://www.buymeacoffee.com/marais"],"categories":["Packages","TypeScript"],"sub_categories":["Logging"],"readme":"\u003cdiv align=\"center\"\u003e\n\n\u003csamp\u003e\n\n# ![diary](./shots/logo.png)\n\n\u003c/samp\u003e\n\n\u003c/div\u003e\n\n\u003cdiv align=\"left\"\u003e\n\n**Dear diary, you make my logging so easy**\n\n\u003ca href=\"https://npm-stat.com/charts.html?package=diary\"\u003e\n  \u003cimg src=\"https://badgen.net/npm/dm/diary?color=black\u0026label=npm%20downloads\" alt=\"js downloads\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://licenses.dev/npm/diary\"\u003e\n  \u003cimg src=\"https://licenses.dev/b/npm/diary?style=dark\" alt=\"licenses\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://unpkg.com/diary/\"\u003e\n  \u003cimg src=\"https://img.badgesize.io/https://unpkg.com/diary/browser.mjs?compression=gzip\u0026label=gzip\u0026color=black\" alt=\"gzip size\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://unpkg.com/diary/\"\u003e\n  \u003cimg src=\"https://img.badgesize.io/https://unpkg.com/diary/browser.mjs?compression=brotli\u0026label=brotli\u0026color=black\" alt=\"brotli size\" /\u003e\n\u003c/a\u003e\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n\u003csup\u003e\n\nThis is free to use software, but if you do like it, consisder supporting me ❤️\n\n[![sponsor me](https://badgen.net/badge/icon/sponsor?icon=github\u0026label\u0026color=gray)](https://github.com/sponsors/maraisr)\n[![buy me a coffee](https://badgen.net/badge/icon/buymeacoffee?icon=buymeacoffee\u0026label\u0026color=gray)](https://www.buymeacoffee.com/marais)\n\n\u003c/sup\u003e\n\n\u003c/div\u003e\n\n## ⚡ Features\n\n- No [dependencies](https://npm.anvaka.com/#/view/2d/diary)\n- Outstanding [performance](#-benchmark)\n- Support for [`debug`'s filter](https://www.npmjs.com/package/debug#wildcards)\n\n## ⚙️ Install\n\n```sh\nnpm add diary\n```\n\n## 🚀 Usage\n\n```ts\nimport { info, diary, enable } from 'diary';\n\n// 1️⃣ Choose to enable the emission of logs, or not.\nenable('*');\n\n// 2️⃣ log something\ninfo('this important thing happened');\n// ~\u003e ℹ info  this important thing happened\n\n// Maybe setup a scoped logger\nconst scopedDiary = diary('my-module', (event) =\u003e {\n  if (event.level === 'error') {\n    Sentry.captureException(event.error);\n  }\n});\n\n// 3️⃣ log more things\nscopedDiary.info('this other important thing happened');\n// ~\u003e ℹ info  [my-module] this other important thing happened\n```\n\n\u003cdetails\u003e\u003csummary\u003eNode users\u003c/summary\u003e\n\nThe `enable` function is executed for you from the `DEBUG` environment variable. And as a drop in replacement for\n`debug`.\n\n```shell\nDEBUG=client:db,server:* node example.js\n```\n\n\u003c/details\u003e\n\n## 🔎 API\n\n### diary(name: string, onEmit?: Reporter)\n\nReturns: [log functions](#log-functions)\n\n\u003e A default diary is exported, accessible through simply importing any [log function](#log-functions).\n\u003e\n\u003e \u003cdetails\u003e\n\u003e \u003csummary\u003eExample of default diary\u003c/summary\u003e\n\u003e\n\u003e ```ts\n\u003e import { info } from 'diary';\n\u003e\n\u003e info(\"i'll be logged under the default diary\");\n\u003e ```\n\u003e\n\u003e \u003c/details\u003e\n\n#### name\n\nType: `string`\n\nThe name given to this _diary_—and will also be available in all logEvents.\n\n#### onEmit \u003csmall\u003e(optional)\u003c/small\u003e\n\nType: `Reporter`\n\nA reporter is run on every log message (provided its [enabled](#enablequery-string)). A reporter gets given the\n`LogEvent` interface:\n\n```ts\ninterface LogEvent {\n  name: string;\n  level: LogLevels;\n\n  messages: any[];\n}\n```\n\n\u003e _Note_: you can attach any other context in middleware.\n\u003e\n\u003e \u003cdetails\u003e\u003csummary\u003eExample\u003c/summary\u003e\n\u003e\n\u003e ```ts\n\u003e import { diary, default_reporter } from 'diary';\n\u003e const scope = diary('scope', (event) =\u003e {\n\u003e   event.ts = new Date();\n\u003e   return default_reporter(event);\n\u003e });\n\u003e ```\n\u003e\n\u003e \u003c/details\u003e\n\nErrors (for `error` and `fatal`) there is also an `error: Error` property.\n\n### _log functions_\n\nA set of functions that map to `console.error`, `console.warn`, `console.debug`, `console.info` and `console.info`.\nAptly named;\n\n`fatal`, `error`, `warn`, `debug`, `info`, and `log`. All of which follow the same api signature:\n\n```ts\ndeclare logFunction(message: object | Error | string, ...args: unknown[]): void;\n```\n\nAll parameters are simply spread onto the function and reported. Node/browser's built-in formatters will format any\nobjects (by default).\n\n```ts\ninfo('hi there'); // ℹ info  hi there\ninfo('hi %s', 'there'); // ℹ info  hi there\ninfo('hi %j', { foo: 'bar' }); // ℹ info hi { \"foo\": \"bar\" }\ninfo('hi %o', { foo: 'bar' }); // ℹ info hi { foo: 'bar' }\ninfo({ foo: 'bar' }); // ℹ info { foo: 'bar' }\n```\n\n#### diary \u003csmall\u003e(optional)\u003c/small\u003e\n\nType: `Diary`\n\nThe result of a calling [diary](#diary-name-string);\n\n### enable(query: string)\n\nType: `Function`\n\nOpts certain log messages into being output. See more [here](#programmatic).\n\n## 💨 Benchmark\n\n\u003e via the [`/bench`](/bench) directory with Node v20.2.0\n\n```\nJIT\n✔ diary  ~ 1,434,414 ops/sec ± 0.16%\n✔ pino   ~    47,264 ops/sec ± 0.02%\n✔ bunyan ~     9,644 ops/sec ± 0.01%\n✔ debug  ~   444,612 ops/sec ± 0.22%\n\nAOT\n✔ diary  ~ 1,542,796 ops/sec ± 0.29%\n✔ pino   ~   281,232 ops/sec ± 0.03%\n✔ bunyan ~   588,768 ops/sec ± 0.16%\n✔ debug  ~ 1,287,846 ops/sec ± 0.24%\n```\n\n\u003e AOT: The logger is setup a head of time, and ops/sec is the result of calling the log fn. Simulates long running\n\u003e process, with a single logger. JIT: The logger is setup right before the log fn is called per op. Simulates setting up\n\u003e a logger per request for example.\n\n## Related\n\n- [workers-logger](https://github.com/maraisr/workers-logger) — fast and effective logging for\n  [Cloudflare Workers](https://workers.cloudflare.com/)\n\n## License\n\nMIT © [Marais Rossouw](https://marais.io)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaraisr%2Fdiary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaraisr%2Fdiary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaraisr%2Fdiary/lists"}