MB-7652: Check for buffer overflow when logging messages

Change-Id: I356959257ce6263586cfd79b952695a5dab25407
Reviewed-on: http://review.couchbase.org/25074
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Reviewed-by: Jin Lim <jin@couchbase.com>
Tested-by: Michael Wiederhold <mike@couchbase.com>