0

I need to know at what point the request was made to measure the times.

Search everywhere but I did not find a way to add the date to the log.

This is the way the log shows the requests

GET /api/user/getSessionsByDate 200 253.230 ms - -
POST /api/schedule/getDate 200 162.697 ms - -

I need to show the datetime as I show below

2019-01-01T15:03:01 GET /api/user/getSessionsByDate 200 253.230 ms - -
2019-01-01T15:03:01 POST /api/schedule/getDate 200 162.697 ms - -

I need to do its to have the time that each request was made in the log archive. For example in this log I need to include the time on each row for the file "distribution.log "

  uid                forever pid   id      logfile                                 

distribution-prod   10428   11531    /distr/.forever/distribution.log

Try the following command but it does not work:

forever set timestamp true
Fernando Arbelo
  • 185
  • 2
  • 14
  • Something like this? https://www.freecodecamp.org/forum/t/node-express-timestamp-using-req-query-to-grab-date-and-turn-it-into-unix-utc-timestamp/263047/2 https://stackoverflow.com/questions/46926743/node-express-how-to-pass-date-params-in-url-query-string-and-how-to-parse-that?noredirect=1&lq=1 – fedeteka Jun 11 '19 at 23:22
  • 1
    I don't have problems to get the time at the router, what I need to do its to have the time that each request was made in the log archive. For example in this log I need to include the time on each row for the file "distribution.log " uid forever pid id logfile distribution-prod 10428 11531 /root/.forever/distribution.log – Fernando Arbelo Jun 11 '19 at 23:58

1 Answers1

2

I found a solution, for log the requests https with the datetime, I used morgan (HTTP request logger middleware for node.js).

With the next configuration we can get the datetime and others data.

import logger from 'morgan';

logger.format('customformat', '[:date[iso]] ":method :url" :status :res[content-length] - :response-time ms');

app.use(logger('customformat'));

I hoppe that its be useful for someone

Thanks al lot!

Fernando Arbelo
  • 185
  • 2
  • 14