Can I trap output to stderr?

16 Jan 2011

Quite a number of the available libraries apparently output messages (perhaps to stderr). As I'm also using serial on USB, this is woven into my own communications.

Is there a convenient means to trap stderr or route it to the bit-bucket for those times I don't want it?

If, on the other hand, these libraries are simply printing and cannot be separated, then perhaps a standardized log error mechanism could be developed?

Dave

16 Jan 2011

Hi David,

You can actually use freopen to redirect things like stdout and stderr, so with a bit of thought you should be able to do some experiments to come up with something you are happy with. There is no /dev/null device as it stands, and you are in uncharted territory, but for some hints, see:

Not sure whether the various libraries you are actually are actually using the stderr, but I think you are right that it would be good to make sure it is more of a convention for debug output.

We do have the function error(fmt, ...) which basically maps to fprintf(stderr, fmt, ...); exit(1) i.e. it is a fatal error. Perhaps we could also have debug(fmt, ...) which would map to fprintf(stderr, fmt, ...), and could be a more standard way of outputting debug warnings.

Simon