{"id":26716612,"url":"https://github.com/javascript-studio/studio-log","last_synced_at":"2025-04-14T01:40:19.972Z","repository":{"id":17310813,"uuid":"81349551","full_name":"javascript-studio/studio-log","owner":"javascript-studio","description":"👻 A tiny JSON logger with emoji support","archived":false,"fork":false,"pushed_at":"2024-01-31T11:50:09.000Z","size":1626,"stargazers_count":39,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T15:51:54.083Z","etag":null,"topics":["cli","emoji","json","logger","ndjson"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/javascript-studio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","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":"2017-02-08T16:21:18.000Z","updated_at":"2022-04-11T14:55:17.000Z","dependencies_parsed_at":"2024-01-31T12:53:47.387Z","dependency_job_id":null,"html_url":"https://github.com/javascript-studio/studio-log","commit_stats":{"total_commits":129,"total_committers":3,"mean_commits":43.0,"dds":"0.054263565891472854","last_synced_commit":"3397bf2569be07cc244b8b70cfdd0432bb69cd79"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javascript-studio%2Fstudio-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javascript-studio%2Fstudio-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javascript-studio%2Fstudio-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javascript-studio%2Fstudio-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/javascript-studio","download_url":"https://codeload.github.com/javascript-studio/studio-log/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248809038,"owners_count":21164893,"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":["cli","emoji","json","logger","ndjson"],"created_at":"2025-03-27T15:38:02.837Z","updated_at":"2025-04-14T01:40:19.942Z","avatar_url":"https://github.com/javascript-studio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Studio Log 2\n\n👻 Log [ndjson][1] to an output stream, pretty print the output with emoji ✨\n\n![](https://github.com/javascript-studio/studio-log/raw/master/emojilog.png)\n\n\u003e __Note!__ Version 2 has significantly changed compared to the [original\n\u003e announcement][medium]. Make sure to read the release notes for migration\n\u003e instructions!\n\n[medium]: https://medium.com/javascript-studio/introducing-a-new-ndjson-logger-with-7bb5b95e3b\n\n## Features\n\n- API designed to produce expressive source code.\n- Uses topics instead of log levels for more fine grained filtering.\n- Uses object streams to avoid serialize -\u003e parse -\u003e serialize when used in a\n  command line application.\n- Disabled by default. If no output stream is specified, no logs are written.\n\n## Usage\n\nLog output is disabled by default to ensure logs don't get in the way when\nwriting unit tests. Therefore you want to set this up as the first thing in\nyour main:\n\n```js\n// Sending raw ndJSON logs to stdout, e.g. in a server application:\nconst Stringify = require('@studio/ndjson/stringify');\nrequire('@studio/log')\n  .pipe(new Stringify())\n  .pipe(process.stdout);\n\n// Sending fancy formatted logs to stdout, e.g. in a command line tool:\nconst Format = require('@studio/log-format/fancy');\nrequire('@studio/log')\n  .pipe(new Format())\n  .pipe(process.stdout);\n\n// Sending logs to console.log, e.g. in a browser:\nconst Format = require('@studio/log-format/console');\nrequire('@studio/log')\n  .pipe(new Format())\n```\n\nNext, create a logger instance in a module and start writing logs:\n\n```js\nconst logger = require('@studio/log');\n\nconst log = logger('app');\n\nexports.startService = function (port) {\n  log.launch('my service', { port: 433 });\n};\n\n```\n\nIn the server example above, this output is produced:\n\n```json\n{\"ts\":1486630378584,\"ns\":\"app\",\"topic\":\"launch\",\"msg\":\"my service\",\"data\":{\"port\":433}}\n```\n\nSend your logs to the [emojilog][4] CLI for pretty printing:\n\n```bash\n❯ cat logs.ndjson | emojilog\n09:52:58 🚀 app my service port=433\n```\n\n## Install\n\n```bash\n❯ npm i @studio/log\n```\n\n## Topics\n\nInstead of log levels, this logger uses a set of topics. Unlike log levels,\ntopics are not ordered by severity.\n\nThese topics are available: `ok`, `warn`, `error`, `issue`, `ignore`, `input`,\n`output`, `send`, `receive`, `fetch`, `finish`, `launch`, `terminate`, `spawn`,\n`broadcast`, `disk`, `timing`, `money`, `numbers` and `wtf`.\n\nTopics and their mapping to emojis are defined in the [Studio Log Topics][8]\nproject.\n\n## Log format\n\n- `ns`: The logger instance namespace.\n- `ts`: The timestamp as returned by `Date.now()`.\n- `topic`: The topic name.\n- `msg`: The message.\n- `data`: The data.\n- `stack`: The stack of error object.\n- `cause`: The cause stack of `error.cause` object, if available.\n\n## API\n\n### Creating a logger\n\n- `log = logger(ns[, data])`: Creates a new logger with the given namespace.\n  The namespace is added to each log entry as the `ns` property. If `data` is\n  provided, it is added to each log entry. Multiple calls with the same `ns`\n  property return the same logger instance while data is replaced.\n- `log.child(ns[, data])`: Creates a child logger of a log instance. The\n  namespaces are joined with a blank and `data` is merged. Multiple calls with\n  the same `ns` property return the same logger instance while data is\n  replaced.\n\n### Log instance API\n\n- `log.{topic}([message][, data][, error])`: Create a new log entry with these\n  behaviors:\n    - The `topic` is added as the `\"topic\"`.\n    - If `message` is present, it's added as the `\"msg\"`.\n    - If `data` is present, it's added as the `\"data\"`.\n    - If `error` is present, the `stack` property of the error is added as the\n      `\"stack\"`. If no `stack` is present, the `toString` representation of the\n      error is used.\n    - If `error.code` is present, it is added to the `\"data\"` without modifying\n      the original object.\n    - If `error.cause` is present, the `stack` property of the cause is added\n      as the `\"cause\"`. If no `stack` is present, the `toString` representation\n      of the cause is used.\n    - If `error.cause.code` is present, a `cause` object is added to the\n      `\"data\"` with `{ code: cause.code }` and without modifying the original\n      object.\n\n### Module API\n\n- `logger.pipe(stream)`: Configure the output stream to write logs to. If not\n  specified, no logs are written. Returns the stream.\n- `logger.hasStream()`: Whether a stream was set.\n- `logger.reset()`: Resets the internal state.\n\n## Transform streams\n\nTransform streams can be used to alter the data before passing it on. For\nexample, [Studio Log X][7] is a Transform stream that can remove confidential\ndata from the log data and [Studio Log Format][6] project implements the\n`basic`, `fancy` and `console` pretty printers.\n\nFormat transforms are [node transform streams][3] in `writableObjectMode`. Here\nis an example implementation, similar to the [ndjson stringify transform][5]:\n\n```js\nconst { Transform } = require('stream');\n\nconst ndjson = new Transform({\n  writableObjectMode: true,\n\n  transform(entry, enc, callback) {\n    const str = JSON.stringify(entry);\n    callback(null, `${str}\\n`);\n  }\n});\n```\n\n## Related modules\n\n- 🌈 [Studio emojilog][4] is a command line tool that parses and pretty prints\n  the Studio Log ndjson format.\n- ☯️ [Studio ndjson][5] can be used to parse the ndjson produced by Studio log.\n- 🎩 [Studio Log Format][6] pretty prints Studio Log streams.\n- ❎ [Studio Log X][7] x-out confidential data in log entries.\n- 🏷 [Studio Log Topics][8] defines the topics used by Studio Log.\n- 📦 [Studio Changes][9] is used to create the changelog for this module.\n\n## License\n\nMIT\n\n\u003cdiv align=\"center\"\u003eMade with ❤️ on 🌍\u003c/div\u003e\n\n[1]: http://ndjson.org/\n[2]: https://github.com/javascript-studio/studio-log/blob/master/examples/demo.js\n[3]: https://nodejs.org/api/stream.html#stream_implementing_a_transform_stream\n[4]: https://github.com/javascript-studio/studio-emojilog\n[5]: https://github.com/javascript-studio/studio-ndjson\n[6]: https://github.com/javascript-studio/studio-log-format\n[7]: https://github.com/javascript-studio/studio-log-x\n[8]: https://github.com/javascript-studio/studio-log-topics\n[9]: https://github.com/javascript-studio/studio-changes\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavascript-studio%2Fstudio-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjavascript-studio%2Fstudio-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavascript-studio%2Fstudio-log/lists"}