{"id":15700826,"url":"https://github.com/fabioricali/katch","last_synced_at":"2025-05-12T15:11:28.173Z","repository":{"id":57288681,"uuid":"98116118","full_name":"fabioricali/katch","owner":"fabioricali","description":"Simple module that capture errors and log it. Works both server and browser.","archived":false,"fork":false,"pushed_at":"2017-09-21T13:19:15.000Z","size":150,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-25T09:08:32.492Z","etag":null,"topics":["error-handling","error-monitoring","error-reporting","errors","exception-handling","javascript","logging","logging-library","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/fabioricali.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-23T18:06:41.000Z","updated_at":"2022-06-02T20:51:02.000Z","dependencies_parsed_at":"2022-09-20T03:54:15.802Z","dependency_job_id":null,"html_url":"https://github.com/fabioricali/katch","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabioricali%2Fkatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabioricali%2Fkatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabioricali%2Fkatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabioricali%2Fkatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fabioricali","download_url":"https://codeload.github.com/fabioricali/katch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243151074,"owners_count":20244501,"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":["error-handling","error-monitoring","error-reporting","errors","exception-handling","javascript","logging","logging-library","nodejs"],"created_at":"2024-10-03T19:54:41.131Z","updated_at":"2025-03-12T03:31:34.295Z","avatar_url":"https://github.com/fabioricali.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003cbr/\u003e\u003cbr/\u003e\n\u003cimg width=\"320\" src=\"https://raw.githubusercontent.com/fabioricali/katch/develop/extra/logo-katch.png\" title=\"katch\"/\u003e\n\u003cbr/\u003e\u003cbr/\u003e\nSimple module that capture errors and log it. Works both server and browser.\n\u003cbr/\u003e\u003cbr/\u003e\n\u003ca href=\"https://travis-ci.org/fabioricali/katch\" target=\"_blank\"\u003e\u003cimg src=\"https://travis-ci.org/fabioricali/katch.svg?branch=master\" title=\"Build Status\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://coveralls.io/github/fabioricali/katch?branch=master\" target=\"_blank\"\u003e\u003cimg src=\"https://coveralls.io/repos/github/fabioricali/katch/badge.svg?branch=master\" title=\"Coverage Status\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://opensource.org/licenses/MIT\" target=\"_blank\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-yellow.svg\" title=\"License: MIT\"/\u003e\u003c/a\u003e\n\u003cimg src=\"https://img.shields.io/badge/team-terrons-orange.svg\" title=\"Team Terrons\"/\u003e\n\u003c/div\u003e\n\n## Installation\n\n### Node.js\n```\nnpm install katch --save\n```\n\nAdd in top of your entry point app\n\n## Basic usage\n```javascript\n// detect automatically all errors\nrequire('katch')();\n// others modules\n```\n\n### Browser\n\nAdd before others scripts\n\n#### Local\n```html\n\u003cscript src=\"node_modules/katch/dist/katch.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003ekatch()\u003c/script\u003e\n```\n\n#### CDN unpkg\n```html\n\u003cscript src=\"https://unpkg.com/katch/dist/katch.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003ekatch()\u003c/script\u003e\n```\n\n#### CDN jsDeliver\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/katch/dist/katch.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003ekatch()\u003c/script\u003e\n```\n\n### Examples\n```javascript\nconst katch = require('katch');\n\nconst config = {\n    // works only in server environment, in browser store to localStorage\n    writeFile: {\n        folderPath: './errors'\n    }\n};\n\nkatch(config);\n\n// events\n\nkatch.on('error', (error, params) =\u003e {\n    console.log(error, params);\n});\n```\n### Log format\n```\n{\"level\":\"ERROR\",\"code\":102,\"message\":\"ReferenceError: func4 is not defined... ecc...ecc...\",\"params\":{\"custom\":\"horror\"},\"time\":\"2017-08-06 13:39:41\",\"hash\":\"0bc33304126ab9051e585f931074175597e8fb6f5e721f23f4e9804d42c32173\",\"host\":\"Zallo\",\"pid\":9972,\"platform\":\"win32\"}\n{\"level\":\"INFO\",\"code\":104,\"message\":\"info message\",\"params\":{},\"time\":\"2017-08-06 22:19:13\",\"hash\":\"86677fb54af6bb0d646af35ae56afe35275290c046959a27ecce3171f680b61e\",\"host\":\"Zallo\",\"pid\":9344,\"platform\":\"win32\"}\n{\"level\":\"WARN\",\"code\":103,\"message\":\"wanr message\",\"params\":{},\"time\":\"2017-08-06 22:19:13\",\"hash\":\"ffb322974b101dc063ca0b150e4d2a817ce0e58e362bac149caf0791018c0171\",\"host\":\"Zallo\",\"pid\":9344,\"platform\":\"win32\"}\n{\"level\":\"DEBUG\",\"code\":105,\"message\":\"debug message\",\"params\":{},\"time\":\"2017-08-06 22:19:13\",\"hash\":\"dbb69a4d04a33f4b13f90dd3a068d9c358d33f210a98e3c07e27a24f3dfe7d51\",\"host\":\"Zallo\",\"pid\":9344,\"platform\":\"win32\"}\n{\"level\":\"TRACE\",\"code\":106,\"message\":\"Trace: trace message... ecc...ecc...\",\"params\":{},\"time\":\"2017-08-06 22:19:13\",\"hash\":\"7a2625faa021efb2a6a9a7fcd4ccbef26c40e98cd400938775248abb12ebd8df\",\"host\":\"Zallo\",\"pid\":9344,\"platform\":\"win32\"}\n```\n### Log archive\n\n- **Server**\n    - The log files are saved by default in the logs folder with the file name of the current day\n- **Browser**\n    - The log are saved in localStorage with key name `katch`\n\n#### Capture manually\n\n```javascript\nconst katch = require('katch');\n\nkatch.setup({\n    writeFile: false\n});\n\ntry {\n    foo();\n    bar();\n} catch (e) {\n    katch.log.error(e, {\n        customParam: 'hello horror'\n    });\n}\n\n//... or using a wrap method\n\nkatch.wrap(() =\u003e {\n    foo();\n    bar();\n}, {\n    customParam: 'hello horror'\n});\n\nkatch.on('error', (error, params) =\u003e {\n    console.log(error, params);\n});\n```\n\n#### Append to log\n\nKatch was created to capture all the errors in an app but can also be used as a logger\n\n```javascript\n\n// Info\nkatch.log.info('A log message', {custom: 1234});\n\nkatch.on('info', (message, params) =\u003e {\n    console.log(message, params);\n});\n\n// Debug\nkatch.log.debug('A debug message', {custom: 1234});\n\nkatch.on('debug', (message, params) =\u003e {\n    console.log(message, params);\n});\n\n// Warn\nkatch.log.warn('A log message', {custom: 1234});\n\nkatch.on('warn', (message, params) =\u003e {\n    console.log(message, params);\n});\n\n// Fatal\nkatch.log.fatal('A log message', {custom: 1234});\n\nkatch.on('fatal', (message, params) =\u003e {\n    console.log(message, params);\n});\n\n// Error\nkatch.log.error(new Error('my error'), {custom: 1234});\n\nkatch.on('error', (error, params) =\u003e {\n    console.log(error, params);\n});\n\n// Trace\nkatch.log.trace('trace', {custom: 1234});\n\nkatch.on('trace', (trace, params) =\u003e {\n    console.log(trace, params);\n});\n```\n\n#### Log levels\n\n| Name | Code |\n| - | - |\n| FATAL | 101 |\n| ERROR | 102 |\n| WARN | 103 |\n| INFO | 104 |\n| DEBUG | 105 | \n| TRACE | 106 |  \n\n#### Add custom level\n```javascript\nkatch.addLevel('MYLEVEL', '123');\nkatch.log.MYLEVEL('hello level', {myParams: 'wow'});\nkatch.on('MYLEVEL', (message) =\u003e {\n    console.log(message);\n});\n```\n#### Remove custom level\n```javascript\nkatch.removeLevel('MYLEVEL');\n```\n#### Log event\n\nEvery invoked\n\n```javascript\nkatch.on('log', obj =\u003e {\n    console.log(obj);\n    // obj\n    { \n        time: '2017-08-02 19:01:46',\n        level: 'INFO', // INFO, WARN, FATAL, ERROR, DEBUG, ...custom\n        code: 104,\n        hash: 'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9',\n        message: 'hello world',\n        params: { foo: 'bar' },\n        host: 'DEVELOP-STATION', // only server\n        pid: 22232, // only server\n        platform: 'win32' // only server,\n        useragent: '\"Mozilla/5.0...' // only browser\n     }\n     \n});\n```\n\n### Catch error from Koa and Express\n\n- Koa\n    ```javascript\n    const app = new Koa();\n    katch.from.koa(app);\n    app.use(ctx =\u003e {\n      throw new Error('koa error');\n    });\n    ```\n- Express\n    ```javascript\n    const app = require('express')();\n    app.get('/', function (req, res) {\n        throw new Error('express error');\n    });\n    // after all routes\n    app.use(katch.from.express);\n    ```\n\n### Configuration\n```javascript\nconst config = {\n    console: true, // outputs in console\n    logging: true, // if false disable writing log. The event \"log\" will be invoked anyway \n    writeFile: { // only server environment\n        prefix: '', // add a prefix to filename\n        humanize: true, // write a readable log\n        folderPath: './logs' // folder path\n    }\n}\n```\n\n## Changelog\nYou can view the changelog \u003ca target=\"_blank\" href=\"https://github.com/fabioricali/katch/blob/master/CHANGELOG.md\"\u003ehere\u003c/a\u003e\n\n## License\nkatch is open-sourced software licensed under the \u003ca target=\"_blank\" href=\"http://opensource.org/licenses/MIT\"\u003eMIT license\u003c/a\u003e\n\n## Author\n\u003ca target=\"_blank\" href=\"http://rica.li\"\u003eFabio Ricali\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabioricali%2Fkatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffabioricali%2Fkatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabioricali%2Fkatch/lists"}