{"id":23131221,"url":"https://github.com/emartech/json-logger-js","last_synced_at":"2026-06-01T08:01:00.254Z","repository":{"id":25079607,"uuid":"103106113","full_name":"emartech/json-logger-js","owner":"emartech","description":"A tiny and fast logging library that outputs logs in JSON format.","archived":false,"fork":false,"pushed_at":"2026-05-04T11:55:11.000Z","size":936,"stargazers_count":5,"open_issues_count":9,"forks_count":4,"subscribers_count":27,"default_branch":"main","last_synced_at":"2026-05-04T13:32:35.711Z","etag":null,"topics":[],"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/emartech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-09-11T07:50:59.000Z","updated_at":"2026-05-04T11:53:36.000Z","dependencies_parsed_at":"2025-11-28T17:09:12.488Z","dependency_job_id":null,"html_url":"https://github.com/emartech/json-logger-js","commit_stats":{"total_commits":85,"total_committers":14,"mean_commits":6.071428571428571,"dds":0.3764705882352941,"last_synced_commit":"d623408d3e5c42f2479e7b89d07c558e184fce48"},"previous_names":[],"tags_count":56,"template":false,"template_full_name":null,"purl":"pkg:github/emartech/json-logger-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emartech%2Fjson-logger-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emartech%2Fjson-logger-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emartech%2Fjson-logger-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emartech%2Fjson-logger-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emartech","download_url":"https://codeload.github.com/emartech/json-logger-js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emartech%2Fjson-logger-js/sbom","scorecard":{"id":251854,"data":{"date":"2025-08-11","repo":{"name":"github.com/emartech/json-logger-js","commit":"b1a1447d8999acf95064d2e76eaec70d3c39f3a4"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":5.1,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/5 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":10,"reason":"15 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/_init.yml:1","Warn: no topLevel permission defined: .github/workflows/_release.yml:1","Warn: no topLevel permission defined: .github/workflows/_test.yml:1","Warn: no topLevel permission defined: .github/workflows/dev.yml:1","Warn: no topLevel permission defined: .github/workflows/release.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":9,"reason":"dependency not pinned by hash detected -- score normalized to 9","details":["Warn: npmCommand not pinned by hash: .github/workflows/_init.yml:51","Info:   9 out of   9 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":4,"reason":"branch protection is not maximal on development and all release branches","details":["Info: 'allow deletion' disabled on branch 'master'","Info: 'force pushes' disabled on branch 'master'","Info: 'branch protection settings apply to administrators' is required to merge on branch 'master'","Info: 'stale review dismissal' is required to merge on branch 'master'","Warn: branch 'master' does not require approvers","Warn: codeowners review is required - but no codeowners file found in repo","Warn: 'last push approval' is disabled on branch 'master'","Info: 'up-to-date branches' is required to merge on branch 'master'","Info: status check found to merge onto on branch 'master'","Info: PRs are required in order to make changes on branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: github.com/emartech/.github/SECURITY.md:1","Info: Found linked content: github.com/emartech/.github/SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/emartech/.github/SECURITY.md:1","Info: Found text in security policy: github.com/emartech/.github/SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":1,"reason":"9 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-h5c3-5r3r-rr8q","Warn: Project is vulnerable to: GHSA-rmvr-2pp2-xj38","Warn: Project is vulnerable to: GHSA-xx4v-prfh-6cgc","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j","Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22","Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-17T08:39:46.267Z","repository_id":25079607,"created_at":"2025-08-17T08:39:46.267Z","updated_at":"2025-08-17T08:39:46.267Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33765379,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-01T02:00:06.963Z","response_time":115,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-12-17T11:12:21.161Z","updated_at":"2026-06-01T08:01:00.245Z","avatar_url":"https://github.com/emartech.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @emartech/json-logger\n\nA tiny and fast logging library that outputs logs in JSON format.\nIt has the same namespace based enabling/disabling mechanism as [debug].\n\n### Installation\n\n```bash\nnpm install @emartech/json-logger\n```\n\n### Usage\n\nSince 8.0.0, by default ECS fields will be used when logging. \n\nIf for reason you still need the old format, you need to override the `outputFormat` config.\n`configure` will apply this setting globally, for all instances of the logger.\n\n```javascript\nconst { createLogger } = require('@emartech/json-logger');\n\ncreateLogger.configure({\n  outputFormat: 'legacy'\n});\n\n```\n\n#### Script\n\n```javascript\nprocess.env.DEBUG = 'redis';\nconst { createLogger } = require('@emartech/json-logger');\nconst mongoLogger = createLogger('mongo');\nconst redisLogger = createLogger('redis');\n\nredisLogger.info('connected', { domain: 'yahoo' });\n// ECS format: {\"event\":{\"action\":\"connected\",\"created\":\"2016-08-15T08:50:23.566Z\"},\"log\":{\"logger\":\"redis\",\"level\":30},\"domain\":\"yahoo\"}\n// Legacy format: {\"name\":\"redis\",\"action\":\"connected\",\"level\":30,\"time\":\"2016-08-15T08:50:23.566Z\",\"domain\":\"yahoo\"}\n\nmongoLogger.info('connected', { domain: 'google' });\n// no output, because 'mongo' is not within namespaces (process.env.DEBUG)\n\nredisLogger.fromError('query', new Error('Unauthorized'), { problem: 'missmatch' });\n// ECS format: {\"event\":{\"action\":\"query\",\"created\":\"2016-08-15T08:50:23.569Z\"},\"log\":{\"logger\":\"redis\",\"level\":50},\"error\":{\"type\":\"Error\",\"message\":\"Unauthorized\",\"stack_trace\":\"...\"},\"problem\":\"mismatch\"}\n// Legacy format: {\"name\":\"redis\",\"action\":\"query\",\"level\":50,\"time\":\"2016-08-15T08:50:23.569Z\",\"error_name\":\"Error\",\"error_stack\":\"Error: Unauthorized\\n    at Object.\u003canonymous\u003e (/home/blacksonic/workspace/bunyan-debug/example.js:15:32)\\n    at Module._compile (module.js:541:32)\\n    at Object.Module._extensions..js (module.js:550:10)\\n    at Module.load (module.js:458:32)\\n    at tryModuleLoad (module.js:417:12)\\n    at Function.Module._load (module.js:409:3)\\n    at Module.runMain (module.js:575:10)\\n    at run (bootstrap_node.js:352:7)\\n    at startup (bootstrap_node.js:144:9)\\n    at bootstrap_node.js:467:3\",\"error_message\":\"Unauthorized\",\"problem\":\"missmatch\"}\n```\n\n#### Class\n\n```javascript\nconst { createLogger } = require('@emartech/json-logger');\nconst logger = createLogger('Exporter');\n\nclass Exporter {\n  export() {\n    mongoLogger.info('export', { customer_id: 123 });\n  }\n}\n```\n\n```typescript\nimport { createLogger } from '@emartech/json-logger';\nconst logger = createLogger('Exporter');\n\nclass Exporter {\n  export() {\n    mongoLogger.info('export', { customer_id: 123 });\n  }\n}\n```\n\n#### Tests\n\n```javascript\nimport { Logger } from '@emartech/json-logger';\n\ndescribe('Exporter', () =\u003e {\n  it('should log', () =\u003e {\n    jest.spyOn(Logger.prototype, 'info').mockReturnValue();\n    const exporter = new Exporter();\n    \n    exporter.export();\n\n    expect(Logger.prototype.info).toHaveBeenCalledWith('export', { customer_id: 123 });\n  })\n});\n```\n\nMore examples can be found in the `examples` directory.\n\n### API\n\n##### JsonLogger(namespace)\n\nThe default export of the library acts as a factory method.\nReturns a logging instance with the given namespace.\nThe `DEBUG` environment variable is then used to enable these instances based on comma-delimited names.\nDisabled instances output no logs.\n\n```javascript\nprocess.env.DEBUG = 'redis,mysql';\nconst { createLogger } = require('@emartech/json-logger');\n\nconst mongoLogger = createLogger('mongo');\n// mongo instance will be disabled\n\nconst redisLogger = createLogger('redis');\n// redis instance will be enabled\n```\n\n##### JsonLogger.prototype.info(action, data)\n\nPrints the provided data to the console in JSON format.\n\n```javascript\nconst { createLogger } = require('@emartech/json-logger');\nconst redisLogger = createLogger('redis');\n\nredisLogger.info('connected', { domain: 'yahoo' });\n// ECS format: {\"event\":{\"action\":\"connected\",\"created\":\"2016-08-15T08:50:23.566Z\"},\"log\":{\"logger\":\"redis\",\"level\":30},\"domain\":\"yahoo\"}\n// Legacy format: {\"name\":\"redis\",\"action\":\"connected\",\"level\":30,\"time\":\"2016-08-15T08:50:23.566Z\",\"domain\":\"yahoo\"}\n\nredisLogger.info('connected');\n// ECS format: {\"event\":{\"action\":\"connected\",\"created\":\"2016-08-15T08:50:23.566Z\"},\"log\":{\"logger\":\"redis\",\"level\":30}}\n// Legacy format: {\"name\":\"redis\",\"action\":\"connected\",\"level\":30,\"time\":\"2016-08-15T08:50:23.566Z\"}\n```\n\nBy default displays the namespace of the instance (`name`), the current time in ISO8601 format (`time`),\nthe action passed to the log method and the log level associated with the method.\nThe second argument is assigned to these basic fields and is displayed along with them.\n\n##### JsonLogger.prototype.trace(action, data)\n\nSame as info with trace log level.\n\n##### JsonLogger.prototype.debug(action, data)\n\nSame as info with debug log level.\n\n##### JsonLogger.prototype.warn(action, data)\n\nSame as info with warn log level.\n\n##### JsonLogger.prototype.error(action, data)\n\nSame as info with error log level.\n\n##### JsonLogger.prototype.fatal(action, data)\n\nSame as info with fatal log level.\n\n##### JsonLogger.prototype.fromError(action, data)\n\nDisplays an error object which formatted to fit into one line.\nThe displayed line contains the stack trace, the name and the message of the error (for Axios errors, also request and response details).\nThe log level defaults to error.\n\n```javascript\nconst { createLogger } = require('@emartech/json-logger');\nconst redisLogger = createLogger('redis');\n\nredisLogger.fromError('query', new Error('Unauthorized'), { problem: 'missmatch' });\n// ECS format: {\"event\":{\"action\":\"query\",\"created\":\"2016-08-15T08:50:23.569Z\"},\"log\":{\"logger\":\"redis\",\"level\":50},\"error\":{\"type\":\"Error\",\"message\":\"Unauthorized\",\"stack_trace\":\"...\"},\"problem\":\"mismatch\"}\n// Legacy format: {\"name\":\"redis\",\"action\":\"query\",\"level\":50,\"time\":\"2016-08-15T08:50:23.569Z\",\"error_name\":\"Error\",\"error_stack\":\"Error: Unauthorized\\n    at Object.\u003canonymous\u003e (/home/blacksonic/workspace/bunyan-debug/example.js:15:32)\\n    at Module._compile (module.js:541:32)\\n    at Object.Module._extensions..js (module.js:550:10)\\n    at Module.load (module.js:458:32)\\n    at tryModuleLoad (module.js:417:12)\\n    at Function.Module._load (module.js:409:3)\\n    at Module.runMain (module.js:575:10)\\n    at run (bootstrap_node.js:352:7)\\n    at startup (bootstrap_node.js:144:9)\\n    at bootstrap_node.js:467:3\",\"error_message\":\"Unauthorized\",\"problem\":\"missmatch\"}\n```\n\n##### JsonLogger.prototype.warnFromError(action, data)\n\nSame as `fromError`, but with warn log level.\n\n##### JsonLogger.prototype.timer()\n\nCreates a new instance of timer that has the same methods as the logging instance (info, warn, error, fromError etc.)\nbut also logs the elapsed time in milliseconds from the creation of the instance.\nThe elapsed time will be logged into the `duration` field.\n\n```javascript\nconst { createLogger } = require('@emartech/json-logger');\nconst redisLogger = createLogger('redis');\n\nconst timer = redisLogger.timer();\n\n// heavy task\n\ntimer.info('completed');\n// Legacy format: {\"name\":\"redis\",\"action\":\"completed\",\"level\":30,\"time\":\"2016-08-15T08:50:23.566Z\",\"duration\": 1500}\n// ECS format: {\"event\":{\"action\":\"completed\",\"duration\":\"1500\",\"created\":\"2016-08-15T08:50:23.566Z\"},\"log\":{\"logger\":\"redis\",\"level\":30}}\n```\n\n##### JsonLogger.configure(options)\n\nThe separate steps of the logging process can be configured here.\nThese modifications affect all the instances of the library.\nWith transformers we can alter the data to be logged before passing to the formatter and then to the output.\nIt is a perfect place to add the name of the machine is running on or the request id associated with the current thread stored on a continuation local storage. \nWith the 'enhancedStackTrace' option set to true, the error stack traces will include the causes of the errors as well (if any) including their stack traces \nwith a significantly improved truncation limit.\n\n```javascript\nconst { createLogger } = require('@emartech/json-logger');\n\ncreateLogger.configure({\n  formatter: JSON.stringify,\n  output: console.log,\n  transformers: [],\n  outputFormat: 'ecs',\n  enhancedStackTrace: true\n});\n\n```\n\n### Log levels\n\n- \"fatal\" (60): The service/app is going to stop or become unusable now.\n  An operator should definitely look into this soon.\n- \"error\" (50): Fatal for a particular request, but the service/app continues\n  servicing other requests. An operator should look at this soon(ish).\n- \"warn\" (40): A note on something that should probably be looked at by an\n  operator eventually.\n- \"info\" (30): Detail on regular operation.\n- \"debug\" (20): Anything else, i.e. too verbose to be included in \"info\" level.\n- \"trace\" (10): Logging from external libraries used by your app or *very*\n  detailed application logging.\n\n### Logging request identifier automatically\n\nYou need to use the middlewares of `@emartech/cls-adapter` and add its transformer to the logger's configure method.\nThis way it will log the request identifier coming from the header field (`X-Request-Id`) to every log line \nwhere the called function is originating from the route handler.\n\nFor automating \n\n```javascript\nconst Koa = require('koa');\nconst { createLogger } = require('@emartech/json-logger');\nconst clsAdapter = require('@emartech/cls-adapter');\nconst logger = createLogger('redis');\n\ncreateLogger.configure({\n  transformers: [\n    clsAdapter.addContextStorageToInput()\n  ]\n});\n\nconst app = new Koa();\napp.use(clsAdapter.getKoaMiddleware());\n\napp.use(async () =\u003e {\n  logger.info('connected');\n  // Legacy format: {\"name\":\"redis\",\"action\":\"connected\",\"level\":30,\"time\":\"2016-08-15T08:50:23.566Z\",\"request_id\":\"d5caaa0e-b04e-4d94-bc88-3ed3b62dc94a\"}\n})\n```\n\n[debug]: https://github.com/visionmedia/debug\n[bunyan]: https://github.com/trentm/node-bunyan\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femartech%2Fjson-logger-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femartech%2Fjson-logger-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femartech%2Fjson-logger-js/lists"}