{"id":15369897,"url":"https://github.com/sergiodxa/use-log","last_synced_at":"2025-04-15T13:52:06.327Z","repository":{"id":38361298,"uuid":"276175617","full_name":"sergiodxa/use-log","owner":"sergiodxa","description":"Log a state or prop every time it changes","archived":false,"fork":false,"pushed_at":"2023-01-07T19:39:43.000Z","size":1550,"stargazers_count":12,"open_issues_count":14,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T20:46:08.752Z","etag":null,"topics":["hooks","logger","logging","react","react-hooks"],"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/sergiodxa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"patreon":"sergiodxa","github":"sergiodxa","custom":"https://paypal.me/sergiodxa"}},"created_at":"2020-06-30T18:14:37.000Z","updated_at":"2024-05-30T15:02:35.000Z","dependencies_parsed_at":"2023-02-07T23:16:34.385Z","dependency_job_id":null,"html_url":"https://github.com/sergiodxa/use-log","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergiodxa%2Fuse-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergiodxa%2Fuse-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergiodxa%2Fuse-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergiodxa%2Fuse-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sergiodxa","download_url":"https://codeload.github.com/sergiodxa/use-log/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249085474,"owners_count":21210267,"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":["hooks","logger","logging","react","react-hooks"],"created_at":"2024-10-01T13:39:08.389Z","updated_at":"2025-04-15T13:52:06.309Z","avatar_url":"https://github.com/sergiodxa.png","language":"TypeScript","funding_links":["https://patreon.com/sergiodxa","https://github.com/sponsors/sergiodxa","https://paypal.me/sergiodxa"],"categories":[],"sub_categories":[],"readme":"# useLog ![CI](https://github.com/sergiodxa/use-log/workflows/CI/badge.svg) ![Publish](https://github.com/sergiodxa/use-log/workflows/Publish/badge.svg)\n\n\u003e Log a state or prop every time it changes\n\n## Usage\n\nInstall it:\n\n```sh\n$ yarn add use-log\n```\n\nImport it:\n\n```ts\nimport useLog from 'use-log';\n```\n\nUse it:\n\n```ts\nfunction MyComponent() {\n  const [value, setValue]= React.useState(\"\")\n  useLog(`The value is ${value}`);\n  return \u003cinput value={value} onChange={event =\u003e setValue(event.target.value)}\u003e\n}\n```\n\nNow you will get a log with `The value is ${value}` everytime the message change, this will happen everytime the value change.\n\n### Log objects or arrays\n\nWhen using it with an object or array as value to log you may want to memoize it to avoid the log running on every render:\n\n```ts\nfunction MyComponent() {\n  const [value, setValue]= React.useState(\"\")\n  useLog(React.useMemo(() =\u003e ({ value }), [value]));\n  return \u003cinput value={value} onChange={event =\u003e setValue(event.target.value)}\u003e\n}\n```\n\n### Configuration\n\nuseLog receives an optional configuration object as second argument with the following interface:\n\n```js\ninterface Config {\n  level?: 'log' | 'info' | 'warn' | 'error' | 'debug' | 'dir' | 'table';\n  shouldLogInProduction?: boolean;\n}\n```\n\n### Changing the log level\n\nYou can change the log level this way:\n\n```ts\nfunction MyComponent() {\n  const [value, setValue]= React.useState(\"\")\n  useLog(`The value is ${value}`, { level: \"debug\" });\n  return \u003cinput value={value} onChange={event =\u003e setValue(event.target.value)}\u003e\n}\n```\n\nThis will basically change the `console` method useLog is calling.\n\n### Production-safe\n\nYou can keep the hook in your code and the code will do nothing in production by default, if you want to enable it in production environments you can set `shouldLogInProduction` to `true`.\n\n```ts\nfunction MyComponent() {\n  const [value, setValue]= React.useState(\"\")\n  useLog(`The value is ${value}`, { shouldLogInProduction: true });\n  return \u003cinput value={value} onChange={event =\u003e setValue(event.target.value)}\u003e\n}\n```\n\nThis way the log will continue working in production.\n\n## Author\n\n- [Sergio Xalambrí](https://sergiodxa.com) - [Able](https://able.co)\n\n## License\n\nThe MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergiodxa%2Fuse-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsergiodxa%2Fuse-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergiodxa%2Fuse-log/lists"}