Local time?
Hi there
If I want to log with the local time instead of UTC, what is the easiest way to reconfigure that through options? That information seems to be missing in the README ...
Don't. Just don't. Dealing with data in local tz is nothing but trouble.
If you want to see local time, I would rather think about showing it when you display data, not when you store it. Does bunyan support custom formatters? I guess not, but it would be nice to see it.
Definitely would be nice to have custom formatters. I need to get there, but haven't gotten time for that for a while now. Yah, agree with @rlidwka that I'd prefer local time be on the display side of things, i.e. in the bunyan CLI.
good points fellas. i'd welcome a custom formatter too for viewing the bunyan logs in local time.
I'd also add my vote for this too. I think in the CLI would be ideal.
+1 to viewing the output from bunyan CLI translated into local time.
I think there should be two options:
- translated to local time
- Translated to "x seconds ago" or "y minutes ago" or "z hours ago"
Why no answer?
+1 to custom timezone formatter in Bunyan CLI. Need this really bad to debug through my logs!
the very dirty solution of me:
// /usr/local/bin/bunyan:725 --version 1.2.1
var logTime = new Date(rec.time);
var expectedTimezoneOffset = 480; // compare with UTC time, unit: min
var localTimezoneOffset = logTime.getTimezoneOffset();
var deltaOffset = localTimezoneOffset + expectedTimezoneOffset;
logTime.setTime(logTime.getTime() + deltaOffset * 60 * 1000);
var expectedTimezoneTime = logTime;
function formatTime(time) {
return time.getFullYear() + '-' +
("0" + (time.getMonth() + 1)).slice(-2) + '-' +
("0" + (time.getDate())).slice(-2) + ' ' +
("0" + time.getHours()).slice(-2) + ':' +
("0" + time.getMinutes()).slice(-2) + ':' +
("0" + time.getSeconds()).slice(-2);
}
rec.time = formatTime(expectedTimezoneTime);
/*
* We assume the Date is formatted according to ISO8601, in which
* case we can safely chop off the date information.
*/
if (short && rec.time[10] == 'T') {
+1, I see the data in UTC but I live in UTC-3 so I have to do a bit of math for every entry I see, which can get annoying. I want to store the data in UTC, but I just would like to display it in UTC-3
@yicone Thanks for showing some code!
This'll be in bunyan 1.3.0 when I release that (soonish). Cheers.
@trentm coooool, so what now? what configuration changes are needed to show up local times?
@binarykitchen Per the discussion above it is just for the rendered "pretty" output that the bunyan CLI provides. Use the -L option..
ok, thx!
Just a quick question, can the cli tool use the TZ environment variable that node uses? This scenario happens to me all the time:
Server in cloud: UTC - 5 Dates stored in: UTC Client from which we log in: UTC -3
If it uses the timezone in the server, if we uploaded to a server say in amazon, but we are from any other country, we will get the dates with amazon's timezone. Can we somehow specify which timezone we want? Or set TZ env variable for that matter?
@arg20: Unintentionally yes it does, at least for me:
$ cat foo.log | ./bin/bunyan
[2015-01-26T06:06:31.747Z] INFO: foo/68824 on grape.local: hi
$ cat foo.log | ./bin/bunyan -L
[2015-01-25T22:06:31.747Z] INFO: foo/68824 on grape.local: hi
$ cat foo.log | TZ=GMT-5 ./bin/bunyan -L
[2015-01-26T11:06:31.747Z] INFO: foo/68824 on grape.local: hi
$ cat foo.log | TZ=GMT-4 ./bin/bunyan -L
[2015-01-26T10:06:31.747Z] INFO: foo/68824 on grape.local: hi
This is the function being used (docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset):
$ node -e 'console.log((new Date()).getTimezoneOffset())'
480
$ TZ=EST+5 node -e 'console.log((new Date()).getTimezoneOffset())'
300
@trentm Great! (Sorry I just got to read this), then it's perfect for me.
+1 local time is necessary for read
YSK that -L is not working in the 1.8.0 version. Bug report entered here. Unless I'm doing something wrong that I don't see.
I forked bunyan to show local time in logs, you can use that when piping logs
https://github.com/mohammadranjbar/node-bunyan (You can pass time moment format in environment variable to show with your time format)
npm i -g bunyan-adanic
cat foo.log | bunyan-adanic
does rotating file supports local time now?