Some fixes to stdin/out parsing, support API version 4
Fixed test compability on python3
Moved logging to correct place