Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timestamp for err.log #259

Open
Obscurator opened this issue Jul 2, 2020 · 2 comments
Open

timestamp for err.log #259

Obscurator opened this issue Jul 2, 2020 · 2 comments

Comments

@Obscurator
Copy link

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

@mdodge-ecgrow
Copy link

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

@Shriram-Nagarajan
Copy link

Shriram-Nagarajan commented Jul 16, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants