Did you know that the ๐ก๐ผ๐ฑ๐ฒ๐ท๐ console module provides a ๐๐ผ๐ป๐๐ผ๐น๐ฒ class, unlike the browser?
This is how the default global console object is defined under the hood:
๐ป๐ฒ๐ ๐๐ผ๐ป๐๐ผ๐น๐ฒ({ ๐๐๐ฑ๐ผ๐๐: ๐ฝ๐ฟ๐ผ๐ฐ๐ฒ๐๐.๐๐๐ฑ๐ผ๐๐, ๐๐๐ฑ๐ฒ๐ฟ๐ฟ: ๐ฝ๐ฟ๐ผ๐ฐ๐ฒ๐๐.๐๐๐ฑ๐ฒ๐ฟ๐ฟ });
What most people don't know is that you can configure the console to write to files instead of the standard output and error streams.
This allows you create pure and configurable ๐ก๐ผ๐ฑ๐ฒ๐ท๐ loggers; zero dependencies required.
The constructor options include:
๐๐๐ฑ๐ผ๐๐: Writable output stream.
๐๐๐ฑ๐ฒ๐ฟ๐ฟ: Writable error stream
๐ถ๐ด๐ป๐ผ๐ฟ๐ฒ๐๐ฟ๐ฟ๐ผ๐ฟ๐: Enabled by default
๐ฐ๐ผ๐น๐ผ๐ฟ๐ ๐ผ๐ฑ๐ฒ: Default is auto
๐ถ๐ป๐๐ฝ๐ฒ๐ฐ๐๐ข๐ฝ๐๐ถ๐ผ๐ป๐: Passed to ๐๐๐ถ๐น.๐ถ๐ป๐๐ฝ๐ฒ๐ฐ๐()
๐ด๐ฟ๐ผ๐๐ฝ๐๐ป๐ฑ๐ฒ๐ป๐๐ฎ๐๐ถ๐ผ๐ป: Default is 2
Check the snap below to see how it can be used.
Did you learn something new today?
Like and share this post, and follow me for more!
Top comments (0)