node-server-sdk
node-server-sdk copied to clipboard
Log is at ERROR level and should be at INFO level
Is this a support request? No
Describe the bug We're getting this log every single time we initialize the app:
ERROR info: [LaunchDarkly] Opened LaunchDarkly stream connection
Note this is at the ERROR level and should be at the INFO level.
This is causing great concern for our developers!
To reproduce Initialize node sdk. Observe this "error".
Expected behavior Log at INFO.
Logs See above.
SDK version The version of this SDK that you are using. 6.4.0
Language version, developer tools Typescript
OS/platform Mac
Additional context Add any other context about the problem here.
Hello @kdhillon,
The log levels, and the log writing mechanism, are independent, and currently when you use the default logger it will report all levels to console.error
. The info:
here denotes that it is an info level message.
But with the default logger all the messages go to console.error
If you want to use console.info/warn/error/etc, then you can provide a logger in the options.
const options = {
logger: {
error: (...args) => console.error(...args),
warn: (...args) => console.warn(...args),
info: (...args) => console.info(...args),
debug: (...args) => console.error(...args),
}
}
You you may want to direct these to whatever application level logging mechanism you are using.
There is also a basic logger, which allows control of level and destination, which if suitable for plain text logging.
const ld = require('launchdarkly-node-server-sdk');
const options = {
logger: ld.basicLogger({
level: 'info',
destination: myLogWritter // This is a method that takes a string.
}),
};
There is more information here: https://docs.launchdarkly.com/sdk/features/logging#nodejs-server-side
Thank you, Ryan
A little further context: the definition of console.error
in Node is not "write an error message", it is "write a message to the standard error stream (stderr)". It's common in Linux-like OSes to use stderr for logging in general, not just error messages.
The ERROR
prefix you're seeing on those lines is not added by our code, and it's not added by Node normally. It sounds like some other component being used in your environment is making assumptions about what stderr means, and adding that misleading ERROR
prefix. I'm fairly sure about that, because when I just check out https://github.com/launchdarkly/hello-node-server and do npm install
followed by node index.js
, no such prefix is logged (i.e. your "to reproduce" steps by themselves do not reproduce the behavior; I can't be sure we're using the same version of Node since you didn't mention the Node version under "Language version", but I don't think the behavior of console.error
has changed in that regard).
This info was helpful to me! If anyone else is coming across this, I ended up using basicLogger
to only enable logs for warn
and error
level logs since I wasn't worried about the info
or debug
level messages. This cleared up my logs significantly and made other developers less scared that errors were constantly being thrown at them, haha.
...
logger: LaunchDarkly.basicLogger({
// https://launchdarkly.github.io/node-server-sdk/modules/_launchdarkly_node_server_sdk_.html#LDLogLevel
level: 'warn',
}),
...
Thanks for the insight! I'll use the basic logger and close the issue.
On Thu, Jun 9, 2022 at 9:54 AM Eli Bishop @.***> wrote:
A little further context: the definition of console.error in Node is not "write an error message", it is "write a message to the standard error stream (stderr)". It's common in Linux-like OSes to use stderr for logging in general, not just error messages.
The ERROR prefix you're seeing on those lines is not added by our code, and it's not added by Node normally. It sounds like some other component being used in your environment is making assumptions about what stderr means, and adding that misleading ERROR prefix. I'm fairly sure about that, because when I just check out https://github.com/launchdarkly/hello-node-server and do npm install followed by node index.js, no such prefix is logged (i.e. your "to reproduce" steps by themselves do not reproduce the behavior; I can't be sure we're using the same version of Node since you didn't mention the Node version under "Language version", but I don't think the behavior of console.error has changed in that regard).
— Reply to this email directly, view it on GitHub https://github.com/launchdarkly/node-server-sdk/issues/251#issuecomment-1151370936, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJWMIGXHXBOZTWFPLNNALDVOIOUFANCNFSM5YD25LTQ . You are receiving this because you were mentioned.Message ID: @.***>