Modify sql query to create logs table