{"id":22275666,"url":"https://github.com/igrek8/gc-json-logger","last_synced_at":"2025-10-08T05:24:53.825Z","repository":{"id":60633837,"uuid":"544389470","full_name":"igrek8/gc-json-logger","owner":"igrek8","description":"Log JSON entries to stdout/stderr to be queried in Google Cloud Monitoring","archived":false,"fork":false,"pushed_at":"2024-11-05T05:41:51.000Z","size":1719,"stargazers_count":3,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-09T12:08:41.560Z","etag":null,"topics":["google-cloud","logger","logging","logging-library"],"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/igrek8.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-02T11:01:15.000Z","updated_at":"2024-06-17T18:25:31.000Z","dependencies_parsed_at":"2023-11-24T06:41:09.896Z","dependency_job_id":"bcb4ef95-888c-4b15-8264-d9a6af0dc66f","html_url":"https://github.com/igrek8/gc-json-logger","commit_stats":{"total_commits":282,"total_committers":5,"mean_commits":56.4,"dds":0.07092198581560283,"last_synced_commit":"1a040203c2dfb9d5721345f85ae0837ddea1c6de"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrek8%2Fgc-json-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrek8%2Fgc-json-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrek8%2Fgc-json-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igrek8%2Fgc-json-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/igrek8","download_url":"https://codeload.github.com/igrek8/gc-json-logger/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227932626,"owners_count":17843136,"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":["google-cloud","logger","logging","logging-library"],"created_at":"2024-12-03T14:11:30.640Z","updated_at":"2025-10-08T05:24:48.763Z","avatar_url":"https://github.com/igrek8.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Logger for [Structured Logging](https://cloud.google.com/logging/docs/structured-logging) with [Asynchronous Context Tracking](https://nodejs.org/api/async_context.html#class-asynclocalstorage) (Stability: 2 - Stable)\n\nAllows printing logs to `stdout`, `stderr` for further action in Google Cloud platform. Given that log agent ingests logs from `stdout` streams when running in GKE.\n\n[![NPM](https://badgen.net/npm/v/gc-json-logger)](https://www.npmjs.com/gc-json-logger)\n[![Coverage](https://codecov.io/gh/igrek8/gc-json-logger/branch/main/graph/badge.svg)](https://codecov.io/gh/igrek8/gc-json-logger)\n![Health](https://badgen.net/github/checks/igrek8/gc-json-logger)\n![License](https://badgen.net/github/license/igrek8/gc-json-logger)\n[![Runkit](https://badgen.net/badge/runkit/playground/cyan)](https://npm.runkit.com/gc-json-logger)\n\n## Installation\n\n```bash\nnpm install --save gc-json-logger\n\nyarn add gc-json-logger\n```\n\n## View in Google Cloud Logging\n\n![Google Cloud Logging](./media/google-cloud-logging.png)\n\n## Integration\n\n```js\nconst { Logger } = require('gc-json-logger');\nconst { createServer } = require('http');\n\nlet job = 0;\n\nfunction scheduleJob() {\n  /**\n   * 4) Retrieving a context logger\n   */\n  const logger = Logger.getLogger();\n\n  /**\n   * 5) Logs with job id from the parent\n   */\n  logger.info('scheduling job');\n\n  setTimeout(() =\u003e {\n    /**\n     * 6) Logs with job id from the parent\n     */\n    logger.info('job done');\n  }, 3000);\n}\n\nconst server = createServer((_, res) =\u003e {\n  job++;\n\n  /**\n   * 1) Setting a context logger using job id\n   */\n  const logger = new Logger(job);\n  Logger.runWith(logger, () =\u003e {\n    /**\n     * 2) Logs with with job id\n     */\n    logger.info('creating a new job');\n\n    /**\n     * 3) Calls another function that uses the context\n     */\n    scheduleJob();\n\n    res.setHeader('content-type', 'application/json');\n    res.end(JSON.stringify({ id: job, status: 'scheduled' }));\n  });\n});\n\nserver.listen(8080);\n```\n\n```jsonc\n{\n  \"severity\": \"INFO\",\n  \"time\": \"2022-12-03T10:00:00.000Z\",\n  \"message\": \"creating a new job\",\n  \"logging.googleapis.com/operation\": { \"id\": 1 } // \u003c- always includes context id\n}\n\n{\n  \"severity\": \"INFO\",\n  \"time\": \"2022-12-03T10:00:00.398Z\",\n  \"message\": \"scheduling job\",\n  \"logging.googleapis.com/operation\": { \"id\": 1 } // \u003c- always includes context id\n}\n\n{\n  \"severity\": \"INFO\",\n  \"time\": \"2022-12-03T10:00:01.000Z\",\n  \"message\": \"job done\",\n  \"logging.googleapis.com/operation\": { \"id\": 1 } // \u003c- always includes context id\n}\n```\n\n## Usage\n\nThe various logging methods (`debug`, `info`, `notice`, etc.) require two parameters. The first parameter is intended for a human-readable string, while the second parameter captures context (such as JSON objects with circular references).\n\nExample of **incorrect** use: :x:\n\n```ts\nthis.logger.log(Severity.DEBUG, JSON.stringify(someObject));\n```\n\nExample of **correct** use: :white_check_mark:\n\n```ts\nthis.logger.debug('received tickets', someObject);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figrek8%2Fgc-json-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figrek8%2Fgc-json-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figrek8%2Fgc-json-logger/lists"}