Adding logging and returning status of write()