How to deal with console logging?

75 views Asked by At

My apps logs structured (json) logs to STDOUT. When someone does something like Console.Write("Foo") it will mess up json parser and log pipeline will yell at me.

How to prevent anything but my logger output end up in STDOUT? Keep in mind that even if I remove all Console.Write occurances in my code, something may reside in one of multiple libraries I'm including in my product - debuging this is a nightmare.

I must log to the console, platform (kubernetes) requires it.

1

There are 1 answers

0
greenoldman On

IMHO dealing with it in your code is prohibitively expensive. Nobody sane would print directly to Console in library, so unless you are dealing with extreme case the author of the closed-source library died, I would simply reach out to the author and point a bug in his/her code rather than change my code around it. Fixing the issue would benefit not only you, but everybody using the library including its author.