@rafe.daniels.official/betterlogs
Version:
Enhanced logger for NodeJS
34 lines (29 loc) • 1.05 kB
JavaScript
// Import.
const log = require('./app');
const fs = require('fs');
// Remove log files.
fs.unlink('default.log', () => { });
fs.unlink('my-log.log', () => { });
// Log data.
log('Some data to default log file "default.log".');
log('Another data to custom log file "my-log.log".', 'my-log.log');
log('Another data to custom log file "my-log.log" with delimiter "\\r\\n".',
'my-log.log', '\r\n');
log(
'Another data to custom log file "my-log.log" with delimiter "\\n-----\\n".',
'my-log.log', '\n-----\n');
log('Another data to custom log file "my-log.log".', 'my-log.log');
// Wait 0,5 second and check default log file.
setTimeout(function() {
fs.readFile('default.log', function(error, data) {
if (error) console.log('Error:\n' + error);
console.log('Default log file:\n' + data);
});
}, 500);
// Wait 1 second and check custom log file.
setTimeout(function() {
fs.readFile('my-log.log', function(error, data) {
if (error) console.log('Error:\n' + error);
console.log('Custom log file:\n' + data);
});
}, 1000);