Skip to content

Instantly share code, notes, and snippets.

@joeywhelan
Last active January 1, 2016 22:59
Show Gist options
  • Select an option

  • Save joeywhelan/8213306 to your computer and use it in GitHub Desktop.

Select an option

Save joeywhelan/8213306 to your computer and use it in GitHub Desktop.
Custom Timestamp function along with how to call it out of winston.
var timeStamper = function()
{
var date = new Date();
var sec = date.getSeconds();
if (sec < 10)
sec = '0' + sec;
var min = date.getMinutes();
if (min < 10)
min = '0' + min;
var hrs = date.getHours();
if (hrs < 10)
hrs = '0' + hrs;
var mdate = date.getDate();
if (mdate < 10)
mdate = '0' + mdate;
var month = date.getMonth() + 1;
if (month < 10)
month = '0' + month;
var mil = date.getMilliseconds();
if (mil < 100)
mil = '0' + mil;
if (mil < 10)
mil = '0' + mil;
var stamp = date.getFullYear() + '-' + month + '-' + mdate + ' ' + hrs +
':' + min + ':' + sec + '.' + mil;
return stamp;
};
Invoking this timestamp function for use in the winston logger:
logger.add(logger.transports.Console,
{
....
timestamp: timeStamper,
....
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment