unjs / consola

🐨 Elegant Console Logger for Node.js and Browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support Datadog log level in JSONReporter

nicolaspayot opened this issue · comments

Describe the feature

Hi! We're using consola in our Nuxt 3 applications and send logs to Datadog.

When using the JSONReporter, json logs have a level property that maps to a number (enum LogLevel) and a type property that maps to a string (type logType).

It seems that Datadog uses the level property to classify the logs between error, warn, log, etc, but only when it's mapped to string types such as error, warn, log, etc. It's not working when using numbers and most logs are interpreted as error.

I've implemented a custom JSONReporter to use the level property as a string:

log(logObj: ConsolaReporterLogObject) {
    const newLogObj = {
        level: logObject.type,
        tag: logObject.tag,
        args: logObject.args,
        date: logObject.date,
    }
    this.stream.write(JSON.stringify(newLogObj) + '\n');
}

Would that make sense for the built-in JSONReporter to support this feature out of the box?

Additional information

  • Would you be willing to help implement this feature?

Hi and sorry for late response. Consola v3 has no built-in json reporter. You can implement one for your self with expected JSON format.