logging: Fix Not enough tailroom msgb_put in _output_buf callers

The function clearly specified in its documentation that the number of
bytes written to the out buffer were being returned. However, the value
returned was "the number of characters (excluding the terminating null
byte) which would have been written to the final string if enough space
had been available.", aka snprintf-style.
The 2 callers of that function were not expecting it, so if a long
enough buffer was passed, the program asserted.

Closes: OS#5383
Change-Id: I8d71bd1a0dad37606acb8302b05c2ae338112e57
diff --git a/src/logging.c b/src/logging.c
index e5c66f2..24b5553 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -601,7 +601,8 @@
 		OSMO_SNPRINTF_RET(ret, rem, offset, len);
 	}
 err:
-	buf[buf_len-1] = '\0';
+	len = OSMO_MIN(buf_len - 1, len);
+	buf[len] = '\0';
 	return len;
 }