I tried putting timestamp for all my requests.I used morgan for that and i include like below,
if (process.env.NODE_ENV === 'development') {
// Enable logger (morgan)
app.use(morgan('common'));
}
This results in my console as,
::ssss:197.7.8.1 - - [Fri, 28 Apr 2017 00:28:29 GMT] "GET /assets/jqwidgets/styles/images/icon-right.png HTTP/1.1" 200 143
::ssss:197.7.8.1 - - [Fri, 28 Apr 2017 00:28:29 GMT] "GET /assets/jqwidgets/styles/images/icon-left.png HTTP/1.1" 200 139
::ssss:197.7.8.1- - [Fri, 28 Apr 2017 00:28:31 GMT] "GET /admin-get-users
From the above results I i am getting the timestamp as well as the internet address(::ssss:197.7.8.10which i dont want.Can anyone please suggest me help.I f any new module suggested is also a good solution for me.Thanks.
You're asking for how to get the timestamp with Morgan, not expressjs. You should probably retag the question appropriately.
In any event, morgan offers some predefined tokens you use when constructing the object to set up the string it outputs. If you're only interested in the timestamp use app.use(morgan(':date[format]')); to construct the object where format is one of clf (prints like "27/Apr/2017:12:00:00 +0000", iso (prints like "2017-04-27T12:00:00.000Z"), or web (prints like "Thu, 27 Apr 2017 12:00:00 GMT"). Other tokens also exist like :status for the HTTP status code of the response or :url for the url of the request. if you find you're interested in logging those. After your comment it seems you are, so try app.use(morgan(':date[clf] ":method :url"')); or app.use(morgan(':date[clf] ":url"'));.
if (process.env.NODE_ENV === 'development') {
// Enable logger (morgan)
app.use(morgan(':date[clf] ":method :url"')); // prints date in same format as original Q
}