Support for log file locking

Closes #379.

Not sure how to test failing `flock`. Any ideas?