Log messages to files that are rotated on a schedule.
The three methods console.log
, console.warn
, and console.error
can be swapped out for either synchronous or asynchronous logger-rotate equivalent methods.
Separate files for the three levels of logging are stored and rotated for new empty files daily.
A history of older log files is available, and a list of the most recent messages is also available.
$ npm install logger-rotate --save
Optional - Set the path where logs should be stored. Eiher relative or absolute:
$ node ./node_modules/logger-rotate/index.js setLogFolder ./logs
var logger = require("logger-rotate");
logger.logSync("Hello World", false);
logger.warnSync("Warning!!!", false);
logger.errorSync("Game Over!", true);
(The second parameter in the synchronous methods is optional and denotes whether to run silently or not i.e. don't show a console message - default is false)
logger.log("Hello World", () => {
console.log(":-)");
});
logger.warn("Warning!!!", () => {
console.warn(":-|");
});
logger.error("Game Over!", () => {
console.error(":-(");
});
To check on the most recent messages:
logger.showrecent(50);
The parameter is the number of recent messages to show (up to 999)
npm test
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
- 0.1.0 Initial release.
- 0.2.1 Ability to set log folder & fixed log rotation bug.
- 0.3.0 Flag for silent sync running.
- 0.3.1 Tidy tests.
- 0.4.0 Show Recent Logs.
- 0.4.1 Convert new lines to \n
- 0.4.2 Stop writing recent log for async calls.
- 0.4.3 Tests that include logger-rotate are accidentally triggering its methods.