What is the datadog doing?

If you use Winston and Datadog, you are probably logging level when you emit JSON structured logs. You can configure Datadog to respect level, but sometimes its nice to use its defaults instead.

Datadog uses severity as an equivalent to level. Here’s how you can config the field name of level to just use severity instead.

  const jsonFormat = winston.format.combine(
    winston.format((info) => {
      info["severity"] = info.level;
      delete info.level;
      return info;
    })(),
    winston.format.json()
  );

Here, we are setting info["severity"] to whatever the level would have been. Then right after, we remove the level from the info object.

Follow me on Mastodon @ryanmr@mastodon.cloud.

Follow me on Twitter @ryanmr.