introduced log writing to db