[WIP] Refactor ssh logging

See #222. This is currently php5 only but with some changes we can get this ready for master.