1.1.3 • Published 6 years ago
writelog v1.1.3
Description
Writelog is a lightweight library to auto export log to file.
Why to use
- Catch problem in runtime ( best for server app )
- Easy to view
- Easy to analysis by history
- Easy to work with another team member
Feature
- Write log to file
- Two mode : one file log and multi file log
- Clear log date
- Auto clean up old log
- Auto push up log in Visual Code
How to use
const writelog = require("writelog");
// wrap your code block could have some bug to use
try {
// do some thing
throw new Error("this is feature, not bug !");
} catch (err) {
console.error(err);
writelog("demo", err.stack);
}
Result
your_app/.log/demo.log
12-07-2018 02:55:27 : Error: this is feature, not bug !
at Object.<anonymous> (d:\Workspace\Program\Nodejs\hyron\test\mid.js:6:9)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
at startup (bootstrap_node.js:193:16)
at bootstrap_node.js:617:3
--------------------
API Docs
writelog (name, content, config)
Return : (String) file path
Paramenter
- name (String) : name of file. Note, in multi log mode, filename will display with format : name_yyyy-MM-dd_hh-mm-ss.log
- content (String) : log section data. Suggest is "err.stack" in try catch, and your IDE should install extendsion to jump to error by Ctrl + Click
- config (Object) : (option) for custom your log file
- oneFile (String) : turn on / off onePage mode. Default : true
- history (String) : number of max history log item can view. Default : 20
- dir (String) : to dir to write log file. Default : "./.log/"
- dateFormat (String) : format of date in log file. default : "dd-MM-yyyy hh:mm:ss",
Contact
- Report bug / Request new feature : thangphung.work@gmail.com
- Help me with a cup of coffee : Donate with PayPal