log-writer: lock the mutex as little as possible
log-writer: lock the mutex as little as possible

We've been seeing an issue where it seems like the output from the logs
of a job suddenly stop, and eventually triggers the log timeout. This
has happened on several platforms, including multiple OS-es (both Linux
and OS X), which leads me to believe the issue is in the worker.

While running some tests that sent a lot of output to the log writer, I
noticed that it was possible to get it into a locked state where the
flushing would take a long time and therefore Write() would stall on
attempting to lock the mutex. This change fixes that so even with a very
fast writer, nothing would lock (until you hit the maximum log limit).

While I'm not positive that this will fix the issue we're seeing, it
does seem like a good idea to keep the mutex locked for as little time
as possible.

henrikhodne-abandoned/worker,Acidburn0zzz/worker,solarce/worker,henrikhodne-abandoned/worker,Acidburn0zzz/worker,solarce/worker,henrikhodne-abandoned/worker,travis-ci/worker,solarce/worker,travis-ci/worker,travis-ci/worker,Acidburn0zzz/worker