Add the --logdir commandline option

To log to a different file for every sync.

This also changed a QueuedConnection to AutoConnection, that way we
directly save the log from the main thread in the file without waiting
for the event loop (so if it crashes before, the log has been writen)