For inspiration, look at how the syslog api works. You want to make each log message a 3-tuple (timestamp, sender, message-text) and log that somewhere. Be it a csv-file, database table, stderr or whatever. If you are thinking about complicating it more, e.g by introducing additional fields to the 3-tuple, then remember that the logs doesn't have to be 100% perfect. As long as they are consistent enough for the user who is grepping them.
Logging error codes is not a good idea since they add a layer of indirection. The text "file not found" is always clearer than "error code: 412".
Another thing to keep in mind is to make your log messages distinct. If a user reports the error "Connection reset by peer" and there are 28 places in your code which can cause that message, then that is harder to debug than if the error only can be logged from exactly one location.