clarkie / dynogels

DynamoDB data mapper for node.js. Originally forked from https://github.com/ryanfitz/vogels
Other
490 stars 110 forks source link

Log Format #121

Closed jkav77 closed 6 years ago

jkav77 commented 6 years ago

I feel like I have seen someone bring this up before but I couldn't find it in a search.

I'm using Winston for a logger, and the format of the logs is suboptimal. I'm not sure if it's just me or if this is what others are seeing too. If anyone else is interested I will do a pull request to fix it.

The log format I am seeing in AWS CloudWatch:

{
    "0": "d",
    "1": "y",
    "2": "n",
    "3": "o",
    "4": "g",
    "5": "e",
    "6": "l",
    "7": "s",
    "8": " ",
    "9": "%",
    "10": "s",
    "11": " ",
    "12": "r",
    "13": "e",
    "14": "s",
    "15": "p",
    "16": "o",
    "17": "n",
    "18": "s",
    "19": "e",
    "20": " ",
    "21": "-",
    "22": " ",
    "23": "%",
    "24": "s",
    "25": "m",
    "26": "s",
    "level": "info",
    "message": {
        "data": {}
    }
}
cdhowie commented 6 years ago

This looks like a string that's been augmented with level and message attributes. From where are you obtaining these messages?

jkav77 commented 6 years ago

I just use Winston and add it to the Dynogels config as described in the documentation. I see the above output in AWS CloudWatch logs.

const winston = require('winston')
const logger = winston.createLogger()

const dynogels = require('dynogels')
dynogels.AWS.config.update({ region: 'us-east-1' })
dynogels.log = logger

The offending code is from table.js line 71:

self.log.info({ data: data }, 'dynogels %s response - %sms', method.toUpperCase(), elapsed);

This isn't really the right syntax for Winston. I think it should be:

self.log.info({
  message: `Dynogels ${method.toUpperCase()} response - ${elapsed}ms`,
  data: data
})
jkav77 commented 6 years ago

The above log calls expect the output to be parsed with util.format which winston does not do by default. You can create a custom format for winston to make it use util.format but it is substantially different from what is described in the documentation. I think bunyan does this by default. I will test that out later...

jkav77 commented 6 years ago

I have played around with this a bit and couldn't get Winston working. I switched to Bunyan and it worked out of the box. Has anyone used Winston with dynogels successfully?