Bug fix: buffer_size should not be set to 0 after _do_flush. It should be subtracted the length of flushed log.
Avoid log string copy when _do_flush
1. Add _flush_lock and _flush_unlock for readability.
2. Fix a error in a test case