Separate Errors and warning in Stderr Pipe

Hello everyone,

I want to know if there is a way to separate warnings and errors that are captured by cmd.StderrPipe function ? So i’m running a JS script using Go and i need to capture all the logs (info, warning, errors) separately. StdoutPipe and StderrPipe are very useful to capture the logs but i could not find a way to separate warnings and errors in the StderrPipe.

Thank you

There are no “subpipes” within a pipe that distinguish between warnings or errors. It’s just data, such as reading from a file. If you can make a change to that JS script to output its messages in a more structured form like JSON, you can parse the messages out into a list of separate warning and error objects. If the script cannot be configured/modified to do that, you will need to either write some code that parses the output and separates it out into warnings or errors (e.g. maybe it’s as simple as reading each line and if it starts with “[WARNING]”, it’s a warning or “[ERROR]” means error), or perhaps someone else already wrote a package that handles parsing it out and you could just use that.

Thank you @skillian

The issue is that the logs are not tagged with [ERROR] [WARN]. I capture only the message of the log so it’s not possible to separate them. I think there is no solution for this issue.

Thank you again