Good article!
And good timing as far as I'm concerned :)
I'm writing an API and outputting to console.log/console.error and was wondering if it was better/recommended to write a log function early and use it everywhere or keep my output to the stdout.
I was supposed to research that tonight so you saved me time!
I would definitely use a function, since you will need to timestamp and tag your logs, log structured data, etc.
And what if you want to extract part of the application into an internal library?Libraries shouldn't touch IO, they can only accept a logger injection.
And what if you want to use the code in a frontend web application? Who will route your logs there?
So yeah, always use a function/library, just don't try to connect to the logging server instead of stdout yourself, especially in a stateless deployment.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Good article!
And good timing as far as I'm concerned :)
I'm writing an API and outputting to console.log/console.error and was wondering if it was better/recommended to write a log function early and use it everywhere or keep my output to the stdout.
I was supposed to research that tonight so you saved me time!
I would definitely use a function, since you will need to timestamp and tag your logs, log structured data, etc.
And what if you want to extract part of the application into an internal library?Libraries shouldn't touch IO, they can only accept a logger injection.
And what if you want to use the code in a frontend web application? Who will route your logs there?
So yeah, always use a function/library, just don't try to connect to the logging server instead of stdout yourself, especially in a stateless deployment.