Installation
Node.js
npm install katch --save
Add in top of your entry point app
Basic usage
// detect automatically all errors;// others modules
Browser
Add before others scripts
Local
CDN unpkg
CDN jsDeliver
Examples
const katch = ; const config = // works only in server environment, in browser store to localStorage writeFile: folderPath: './errors' ; ; // events katch;
Log format
{"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"}
{"level":"INFO","code":104,"message":"info message","params":{},"time":"2017-08-06 22:19:13","hash":"86677fb54af6bb0d646af35ae56afe35275290c046959a27ecce3171f680b61e","host":"Zallo","pid":9344,"platform":"win32"}
{"level":"WARN","code":103,"message":"wanr message","params":{},"time":"2017-08-06 22:19:13","hash":"ffb322974b101dc063ca0b150e4d2a817ce0e58e362bac149caf0791018c0171","host":"Zallo","pid":9344,"platform":"win32"}
{"level":"DEBUG","code":105,"message":"debug message","params":{},"time":"2017-08-06 22:19:13","hash":"dbb69a4d04a33f4b13f90dd3a068d9c358d33f210a98e3c07e27a24f3dfe7d51","host":"Zallo","pid":9344,"platform":"win32"}
{"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"}
Log archive
- Server
- The log files are saved by default in the logs folder with the file name of the current day
- Browser
- The log are saved in localStorage with key name
katch
- The log are saved in localStorage with key name
Capture manually
const katch = ; katch; try ; ; catch e katchlog; //... or using a wrap method katch; katch;
Append to log
Katch was created to capture all the errors in an app but can also be used as a logger
// Infokatchlog; katch; // Debugkatchlog; katch; // Warnkatchlog; katch; // Fatalkatchlog; katch; // Errorkatchlog; katch; // Tracekatchlog; katch;
Log levels
Name | Code |
---|---|
FATAL | 101 |
ERROR | 102 |
WARN | 103 |
INFO | 104 |
DEBUG | 105 |
TRACE | 106 |
Add custom level
katch;katchlog;katch;
Remove custom level
katch;
Log event
Every invoked
katch;
Catch error from Koa and Express
- Koaconst app = ;katchfrom;app;
- Expressconst app = ;app;// after all routesapp;
Configuration
const config = console: true // outputs in console logging: true // if false disable writing log. The event "log" will be invoked anyway writeFile: // only server environment prefix: '' // add a prefix to filename humanize: true // write a readable log folderPath: './logs' // folder path
Changelog
You can view the changelog here
License
katch is open-sourced software licensed under the MIT license