Skip to content

Update index.js#98

Closed
lijason1121 wants to merge 5 commits intoexpressjs:masterfrom
lijason1121:master
Closed

Update index.js#98
lijason1121 wants to merge 5 commits intoexpressjs:masterfrom
lijason1121:master

Conversation

@lijason1121
Copy link

add 'locale' format by :date[locale]

add local date format in date token by :date[local]
@dougwilson
Copy link
Contributor

Hi @lijason1121, thanks for your pull request! I have a few comments on this so far:

  1. There are no tests; please add complete tests for your feature.
  2. There is no documentation; please add documentation fro your feature in the README.
  3. I''m not sure what this "local" format maps to. It seems to be date/month/year hour:mins:secs +0000. What format is this? What makes this a "local" format, especially when many people consider "local" dates to be month/date/year, like myself?

@lijason1121
Copy link
Author

hi @dougwilson
thank you for your feedback
I have completed the test and updated README doc.
'locale' just for local time. For me, I am in Beijing. So I want to log by GMT +8 time string, not UTC time:).
Although I can use custome token for date to get my wanted result, I think it is would better to have the 'locale' option for :date[format].

@dougwilson
Copy link
Contributor

Hi @lijason1121, it looks like the contents of the pull request are very different now :)

The date formats has always been a form on debate here, and in reality, we only provide the ones that access log analyzers can read out of the box and recommend you simply define the token for the format you want, which is the whole point of the token method:

var morgan = require('morgan')

morgan.token('date', function () {
  var dateTime = new Date()
  var date = dateTime.getDate()
  var hour = dateTime.getHours()
  var mins = dateTime.getMinutes()
  var secs = dateTime.getSeconds()
  var year = dateTime.getFullYear()
  var month = dateTime.getMonth() + 1;

  return year + '-' + pad2(month) + '-' + pad2(date)
    + ' ' + pad2(hour) + ':' + pad2(mins) + ':' + pad2(secs) 
})

@dougwilson dougwilson closed this Mar 9, 2016
@dougwilson dougwilson self-assigned this Mar 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants