Improved logging

Added some helper functions for recording logging to console and files.
This also ensures that logs without error codes (i.e. error_code = 0)
are not appended with an error code