xpl / ololog

A better console.log for the log-driven debugging junkies
https://www.npmjs.com/package/ololog
The Unlicense
215 stars 8 forks source link

Define timezone for timestamps #19

Closed baaswietse closed 4 years ago

baaswietse commented 4 years ago

Is there any way to define your current timezone or an offset? Right now the timestamps from the logger are 2 hours behind.

I couldn't find this in the docs.

Thanks.

xpl commented 4 years ago

@baaswietse Now you can, I just added it:

log.configure ({
    time: {
        yes: true,
        format: 'locale',
        locale: 'en-US',
        options: { timeZone: 'America/Denver' }
    }
})

It is the same options as described in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat

Time zones can be looked up here: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

P.S. You can also provide a custom printer, if the built-in formatter doesn't do the exact thing you need:

log.configure ({ time: { yes: true, print: date => { /* format the date as needed */ }})
baaswietse commented 4 years ago

Thank you so much for the quick response! Works like a charm :)

Just one side note, when defining the locale: 'be-NL' (I'm from Belgium). The time string is formatted correctly but the date string isn't, we use this format: DD/MM/YYY, while in the logs it stays as MM/DD/YYY

xpl commented 4 years ago

we use this format: DD/MM/YYY, while in the logs it stays as MM/DD/YYY

@baaswietse Try nl-BE instead of be-NL :)

baaswietse commented 4 years ago

Oh wow, thank you sir!