make logger safe and encode before database. Fixes #424