Fixing a deadlock in handlers

format_and_encode was called under a lock,
but it may trigger a deadlock if during the repr() or str()
another call to logging is emitted
to fix this, we had to separate format_and_encode into separate methods,
format, and encode, so the formatting would be done outside the lock
and the encoding (which uses the stream's encoding) would be done inside
the lock.

We added a test that re-creates the deadlock without the fix.
Removing the deprecated RotatingFileHandlerBase
Fixing thread-safety issues in file-based handlers

Not all file-related operations were under a lock, now they are.
Merge pull request #125 from grzn/master

Fixing deadlock and thread-safety issues in handlers