node-windows icon indicating copy to clipboard operation
node-windows copied to clipboard

timestamp for err.log

Open Obscurator opened this issue 4 years ago • 2 comments

It would be great if the daemons xx.err.log would have the same timestamps like xx.wrapper.log

Obscurator avatar Jul 02 '20 09:07 Obscurator

Yes! I was just looking at the error log and was frustrated because I had no idea when those errors occurred.

mdodge-ecgrow avatar Jul 07 '20 15:07 mdodge-ecgrow

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); } }

Shriram-Nagarajan avatar Jul 16 '20 11:07 Shriram-Nagarajan