libpng by default prints error messages to stderr. But you can supply your own replacement error handler to do whatever you want with the error messages. See the explanation (look for "user_error_fn) in the libpng-manual.txt file that is distributed with libpng.
You don't need to rebuild libpng to do that; simply put your replacement handler in your own source code along with a pointer to it in your png_create_read_struct() call.