A deadlock is a kind of serialization error: you didn't do anything forbidden, it just so happened that there was an interaction with other active transactions that prevented your transaction from being completed. Your reaction is the correct one: retry the transaction. There is absolutely no need to wait before retrying.
I concur that with a sufficiently ...
Database logging is the wrong end to handle the problem, since the database does not have the required information.
You will have to write your client application so that it logs the information you need whenever it receives a database error.