Move logging to sqlite db; generalized