public ByteBuf format(
            boolean shouldParse,
            @Nullable byte[] className,
            LogLevel level,
            @Nullable CharSequence msg,
            @Nullable Object[] args,
            @Nullable Throwable throwable) {
        int estimatedThrowableLength = 0;
        if (throwable != null) {
            int causes = ThrowableUtil.countCauses(throwable);
            estimatedThrowableLength = causes == 0
                    ? 64
                    : causes * 1024;
        }
        int estimatedLength = (msg == null
                ? 0
                : msg.length()) + ESTIMATED_PATTERN_TEXT_LENGTH + estimatedThrowableLength;
        if (args != null && shouldParse) {
            estimatedLength += args.length * 16;
        }
        ByteBuf buffer = PooledByteBufAllocator.DEFAULT.directBuffer(estimatedLength);
        try {
            return format0(buffer, shouldParse, className, level, msg, args, throwable);
        } catch (Exception e) {
            ReferenceCountUtil.safeEnsureReleased(buffer);
            throw e;
        }
    }
@implNote Note that we do NOT escape or remove non-printable characters
turms-server-common/src/main/java/im/turms/server/common/infra/logging/core/layout/TurmsTemplateLayout.java