How can I log edits to the hosts file?
Open terminal and run this command.
sudo fs_usage | grep hosts

Files that read / write / modify that should be logged clearly. Look at the last entry on the right for the program name. If you see nothing, in another window try these two commands. An edit implies a write to that file.
tail -2 /etc/hosts
cat /etc/hosts

As commented very clearly, if you can’t catch the change, you may have to set up a script to save the contents of the file periodically and then narrow down what can run during the time when it’s being messed with.