node-bunyan icon indicating copy to clipboard operation
node-bunyan copied to clipboard

Local time?

Open binarykitchen opened this issue 13 years ago • 22 comments

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 ...

binarykitchen avatar Oct 08 '13 23:10 binarykitchen

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.

rlidwka avatar Oct 09 '13 04:10 rlidwka

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.

trentm avatar Oct 09 '13 05:10 trentm

good points fellas. i'd welcome a custom formatter too for viewing the bunyan logs in local time.

binarykitchen avatar Oct 09 '13 07:10 binarykitchen

I'd also add my vote for this too. I think in the CLI would be ideal.

damomurf avatar May 27 '14 04:05 damomurf

+1 to viewing the output from bunyan CLI translated into local time.

I think there should be two options:

  1. translated to local time
  2. Translated to "x seconds ago" or "y minutes ago" or "z hours ago"

djensen47 avatar Aug 08 '14 22:08 djensen47

Why no answer?

chinakungfu avatar Aug 12 '14 07:08 chinakungfu

+1 to custom timezone formatter in Bunyan CLI. Need this really bad to debug through my logs!

abhinavrastogi avatar Sep 10 '14 06:09 abhinavrastogi

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') {

yicone avatar Oct 26 '14 14:10 yicone

+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

gabzim avatar Jan 05 '15 04:01 gabzim

@yicone Thanks for showing some code!

This'll be in bunyan 1.3.0 when I release that (soonish). Cheers.

trentm avatar Jan 17 '15 06:01 trentm

@trentm coooool, so what now? what configuration changes are needed to show up local times?

binarykitchen avatar Jan 18 '15 09:01 binarykitchen

@binarykitchen Per the discussion above it is just for the rendered "pretty" output that the bunyan CLI provides. Use the -L option..

trentm avatar Jan 19 '15 04:01 trentm

ok, thx!

binarykitchen avatar Jan 19 '15 05:01 binarykitchen

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?

gabzim avatar Jan 22 '15 17:01 gabzim

@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 avatar Jan 26 '15 06:01 trentm

@trentm Great! (Sorry I just got to read this), then it's perfect for me.

gabzim avatar Feb 03 '15 21:02 gabzim

+1 local time is necessary for read

chaosforfun avatar Jul 02 '15 02:07 chaosforfun

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.

jcollum avatar Mar 29 '16 14:03 jcollum

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

mohammadranjbarz avatar Aug 03 '20 10:08 mohammadranjbarz

does rotating file supports local time now?

OhnkytaBlabdey avatar Nov 15 '20 01:11 OhnkytaBlabdey