unjs / consola

🐨 Elegant Console Logger for Node.js and Browser
Other
6.12k stars 175 forks source link

Consola default log object does not contain message property #107

Closed atinux closed 3 years ago

atinux commented 3 years ago

Reproduction link : https://repl.it/@gkatsans/Consola#index.js

The consola contrib repository doesnt seem to have a lot of activity in the issue tracker hence my posting here.

Reported in https://github.com/nuxt/nuxt.js/issues/8712

pi0 commented 3 years ago

Hi @gkatsanos. As Daniel mentioned in https://github.com/nuxt/nuxt.js/issues/8712#issuecomment-770625561, it is up to reporters to concatenate args into message (if we do pre-formatting, handling objects like Error is impossible for a reporter that needs to for example format stacktrace)

Also docs is correct. Consola accepts message/additional for logObject that adds it to args array before passing to reporters.

You may use args.join(' ') for a simple formatter in custom repoter.

gkatsanos commented 3 years ago

Also docs is correct. Consola accepts message/additional for logObject that adds it to args array before passing to reporters. aha, now I get it. : https://repl.it/@gkatsans/Consola-2#index.js

message is a property that can be included in the object to be logged by consola, and anything within message will be passed in the args array.

If one wants a prop message to be in the output, they need a custom reporter that will fish out the message from the args array and place it in the object directly or elsewhere.

pi0 commented 3 years ago

If one wants a prop message to be in the output, they need a custom reporter that will fish out the message from the args array and place it in the object directly or elsewhere.

Precisely :) Consola is mostly like a console middleware with built-in reporters. Reporters can connect it to a real logging infra like winston or sentry etc

gkatsanos commented 3 years ago

If one wants a prop message to be in the output, they need a custom reporter that will fish out the message from the args array and place it in the object directly or elsewhere.

Precisely :) Consola is mostly like a middleware with built-in reporters. Reporters can connect it to a real logging infra like winston or sentry etc

In that case I guess I need winston, or the datadog logging library