{"id":23819889,"url":"https://github.com/kth/skog","last_synced_at":"2026-05-15T13:03:26.892Z","repository":{"id":307086021,"uuid":"198434933","full_name":"KTH/skog","owner":"KTH","description":"Logging with context for Node.js","archived":false,"fork":false,"pushed_at":"2025-07-29T09:41:10.000Z","size":2237,"stargazers_count":0,"open_issues_count":9,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-19T06:35:31.662Z","etag":null,"topics":["bunyan","kth-e-larande","logging","nodejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KTH.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2019-07-23T13:20:42.000Z","updated_at":"2025-07-29T09:41:14.000Z","dependencies_parsed_at":"2025-07-29T11:50:17.822Z","dependency_job_id":"948fd6d1-4eb0-4a0b-bb2b-b53fa3088583","html_url":"https://github.com/KTH/skog","commit_stats":null,"previous_names":["kth/skog"],"tags_count":34,"template":false,"template_full_name":null,"purl":"pkg:github/KTH/skog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KTH%2Fskog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KTH%2Fskog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KTH%2Fskog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KTH%2Fskog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KTH","download_url":"https://codeload.github.com/KTH/skog/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KTH%2Fskog/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33067476,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T11:35:32.926Z","status":"ssl_error","status_checked_at":"2026-05-15T11:35:31.362Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["bunyan","kth-e-larande","logging","nodejs"],"created_at":"2025-01-02T07:16:15.296Z","updated_at":"2026-05-15T13:03:26.845Z","avatar_url":"https://github.com/KTH.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"media/skog-logo.png\" width=\"384\"\u003e\n\u003cp\u003e\nAdd \u003cem\u003econtext\u003c/em\u003e to your Node.js logs\n\u003c/p\u003e\n\u003cem\u003eForest photo by \u003ca href=\"https://unsplash.com/photos/d6kSvT2xZQo\"\u003eGustav Gullstrand\u003c/a\u003e on \u003ca href=\"https://unsplash.com\"\u003eUnsplash\u003c/a\u003e\u003c/em\u003e\n\u003c/div\u003e\n\n# Getting started\n\nSkog is a opinionated logging library built on top of Pino.\n\n```\nnpm install skog\n```\n\n```ts\nimport log, { initializeLogger } from \"skog\";\n\ninitializeLogger();\nsetFields({ app: \"my-app\" });\nlog.info(\"Hello world\");\n```\n\nIf your app uses Express, use `skogMiddleware` to add `req_id` to every log line.\n\n```ts\nimport log, { initializeLogger, skogMiddleware, setFields } from \"skog\";\nimport express from \"express\";\n\nconst app = express();\n\nconst app = express();\napp.use(skogMiddleware);\napp.get(\"/\", () =\u003e {\n  // This will log \"req_id\" automatically! You don't need to do anything else!\n  log.info(\"Logging a message\");\n});\n\ninitializeLogger();\nsetFields({ app: \"demo\" });\napp.listen(3000, () =\u003e {\n  log.info(\"Starting server\");\n});\n```\n\n# Recipes\n\n`skog` exports more functions so you can create your own middleware. For example, if you want to add your own fields or if you want to create middleware for other frameworks.\n\n## Add other fields\n\nExample: add a \"session_id\" field in your logs\n\n```ts\nimport { runWithSkog } from \"skog\";\nimport { nanoid } from \"nanoid\";\n\nfunction myMiddleware(req, res, next) {\n  // Assuming that \"req.session.id\" exists...\n  runWithSkog({ req_id: nanoid(), session_id: req.session.id.slice(-3) }, next);\n}\n```\n\n## Middleware for other frameworks\n\nAs you can see from the example above, `runWithSkog` accepts two arguments: an object with fields and a function. `runWithSkog` will return the same thing as returned by the function.\n\nSo, you can create a middleware for Next.js:\n\n```ts\nimport { NextResponse } from \"next/server\";\nimport { nanoid } from \"nanoid\";\n\nfunction middleware(req: NextRequest, ev: NextFetchEvent) {\n  return runWithSkogContext(\n    {\n      session_id: req.cookies[\"session_id\"]?.slice(-3),\n      req_id: nanoid(),\n    },\n    NextResponse.next\n  );\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkth%2Fskog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkth%2Fskog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkth%2Fskog/lists"}