citrix-research / node-winston-context

Contextual logger for Winston
7 stars 4 forks source link

Why does prefix always ends with dot '.' ? #3

Open hepiyellow opened 7 years ago

hepiyellow commented 7 years ago

Hi,

I find it annoying that if my context prefix is foo.boo, and I make a log call like this: logCtx.debug('Got user from db'); Then the log message would be: foo.boo.Got user from db

It looks like the 'Got' is part of the prefix. So I guess the intended use is that every log would include a first name argument. like logCtx.debug('something', 'Got user from db'); And then the log would look like: foo.boo.something Got user from db

But what if I don't have any something to say. So it forces me to pass an empty string as the first argument of every log.

Am I missing something here? Or you think it is a good idea to make this trailing dot optional?

msiebuhr commented 7 years ago

You're on the right track - you're supposed to have something to say; ex:

 logCtx.debug('user-from-db.start', { username: 'foo', ...});
 ...
 logCtx.debug('user-from-db.done', { username: 'foo', responseTime: ..., ...});

Yes, I am quite opinionated on this. I like my log message names to be constant and machine readable. User X took Y seconds to fetch Z rows from db A is IMHO inferior to user.db-fetch user=X responseTime=Y rowCount=Z db=A - it's easily grep- and parse-able, doesn't change when adding info and allows you to easily follow program flow in log-messages.