{"id":26611099,"url":"https://github.com/ioncache/log-defer","last_synced_at":"2025-04-10T00:43:42.456Z","repository":{"id":5403295,"uuid":"50949342","full_name":"ioncache/log-defer","owner":"ioncache","description":"Generate log object compatible with log-defer-viz (https://github.com/hoytech/Log-Defer-Viz)","archived":false,"fork":false,"pushed_at":"2023-04-24T10:58:00.000Z","size":206,"stargazers_count":2,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T00:43:35.582Z","etag":null,"topics":["javascript","javascript-library","logger","logger-interface","logging","npm"],"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/ioncache.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}},"created_at":"2016-02-02T20:24:13.000Z","updated_at":"2021-10-21T12:42:33.000Z","dependencies_parsed_at":"2023-02-10T02:31:21.621Z","dependency_job_id":null,"html_url":"https://github.com/ioncache/log-defer","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioncache%2Flog-defer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioncache%2Flog-defer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioncache%2Flog-defer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ioncache%2Flog-defer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ioncache","download_url":"https://codeload.github.com/ioncache/log-defer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137998,"owners_count":21053775,"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":["javascript","javascript-library","logger","logger-interface","logging","npm"],"created_at":"2025-03-24T02:25:29.925Z","updated_at":"2025-04-10T00:43:42.433Z","avatar_url":"https://github.com/ioncache.png","language":"JavaScript","readme":"# log-defer\n\n![Unit Tests](https://github.com/ioncache/log-defer/actions/workflows/nodejs.yml/badge.svg) [![codecov](https://codecov.io/gh/ioncache/log-defer/branch/main/graph/badge.svg)](https://codecov.io/gh/ioncache/log-defer)\n\n## Description\n\nGenerate log object compatible with [log-defer-viz](https://github.com/hoytech/Log-Defer-Viz)\n\nlog-defer is a module that creates structured logs. The log-defer documentation explains structured logging and its benefits over ad-hoc logging.\n\nThis is the javascript implementation, full documentation for log-defer can be found at \u003chttps://metacpan.org/pod/Log::Defer\u003e\n\n## Installation\n\n``` bash\nnpm install log-defer\n```\n\nor\n\n```bash\nbower install log-defer\n```\n\n## Synopsis\n\n```javascript\n'use strict';\n\nvar log = require('log-defer');\nvar process = require('process');\n\nlog.timer('Log Messages'); // begin a timer called 'Log Messages'\nlog.info('Info level logging');\nlog.warn('Warn level logging');\nlog.error('Error level logging');\nlog.debug('Debug level logging');\nlog.timer('Log Messages'); // end the 'Log Messages' timer\nlog.data({ bar: 'baz', foo: 'bar' }); // add to the data object in the log-defer\n\nlog.warn('Warning with data!', { bar: 'baz', foo: 'bar' }, { barbaz: 'bazfoo', foobar: 'barbaz' });\n\nvar output = log.finalizeLog(); // finalize the log, and return a json string of the log-defer\n\nprocess.stdout.write(output);\n```\n\nThe above code should produce the following output:\n\n```bash\n{\"data\":{\"bar\":\"baz\",\"foo\":\"bar\"},\"logs\":[[0.0009999275207519531,30,\"Info level logging\"],[0.0009999275207519531,20,\"Warn level logging\"],[0.0009999275207519531,10,\"Error level logging\"],[0.0009999275207519531,40,\"Debug level logging\"],[0.0009999275207519531,20,\"Warning with data!\",{\"bar\":\"baz\",\"foo\":\"bar\",\"barbaz\":\"bazfoo\",\"foobar\":\"barbaz\"}]],\"start\":1457018806.914,\"timers\":[[\"Log Messages\",0.0009999275207519531,0.0009999275207519531]],\"end\":0.0019998550415039062}\n```\n\nIf viewed using the log-defer-viz cli then it would format as follows:\n\n```bash\n------ 2016-03-03 Thu 10:26:46.914 EST (1457018806.914) ------\n  | 0.001000 [ INFO] Info level logging\n  | 0.001000 [ WARN] Warn level logging\n  | 0.001000 [ERROR] Error level logging\n  | 0.001000 [DEBUG] Debug level logging\n  | 0.001000 [ WARN] Warning with data! [{\"foo\":\"bar\",\"bar\":\"baz\",\"foobar\":\"barbaz\",\"barbaz\":\"bazfoo\"}]\n  |_0.002000 [END]\n\n Log Messages                                                                                  X\n_______________________________________________________________________________________________________\ntimes in ms                                                                                    1.0\n\n  Data:\n{\n   \"bar\" : \"baz\",\n   \"foo\" : \"bar\"\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fioncache%2Flog-defer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fioncache%2Flog-defer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fioncache%2Flog-defer/lists"}