node-windows
node-windows copied to clipboard
timestamp for err.log
It would be great if the daemons xx.err.log would have the same timestamps like xx.wrapper.log
Yes! I was just looking at the error log and was frustrated because I had no idea when those errors occurred.
Had the same challenge while working on this. Created a log.js file as a workaround, which I call to generate logs:
const dateTimeMapper = function(formatArr){ let transformedObj = {}; for (let format of formatArr){ transformedObj[format["type"]] = format["value"]; } return transformedObj; }
const getLogPrefix = function(){ let timeFields = ["year", "month", "day", "hour", "minute", "second", "dayPeriod"]; let dateTimeFormat = new Intl.DateTimeFormat('en', { year: 'numeric', month: 'short', day: '2-digit' , hour : '2-digit', minute : '2-digit', second : '2-digit'}); let arr = dateTimeFormat.formatToParts(new Date()).filter(format => ~timeFields.indexOf(format["type"])); let dateTimeMap = dateTimeMapper(arr); if(dateTimeMap){ return dateTimeMap["year"]+"-"+dateTimeMap["month"]+"-"+dateTimeMap["day"]+" "+dateTimeMap["hour"]+":"+dateTimeMap["minute"]+":"+dateTimeMap["second"]+" "+dateTimeMap["dayPeriod"] + " "; } }
exports.log = { info : function(){ arguments[0] = typeof arguments[0] === "string" ? getLogPrefix() + arguments[0] : arguments[0]; console.log.apply(this, arguments); }, warn : function(){ arguments[0] = typeof arguments[0] === "string" ? getLogPrefix() + arguments[0] : arguments[0]; console.warn.apply(this, arguments); }, error : function(){ arguments[0] = typeof arguments[0] === "string" ? getLogPrefix() + arguments[0] : arguments[0]; console.error.apply(this, arguments); } }