]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common/dout: escape formatting string for crimson
authorKefu Chai <kchai@redhat.com>
Thu, 10 Sep 2020 12:53:03 +0000 (20:53 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 10 Sep 2020 13:21:39 +0000 (21:21 +0800)
crimson uses seastar logging facility for logging. and the latter uses
fmt::format(). currently, we collect the log message into a string and
pass it to log(fmt,...) as "fmt", but seastar/core/sstring.hh defines
the operator<<(ostream&, const vector<T>&) which is a better match than
our the operator<<(ostream&, const vector<T, Allocator>&). and seastar's
operator<<(ostream&, const vector<T>&) uses "{" and "}" to mark the
begin and end of a vector when printing it. and "{}" is also used by
libfmt to enclose its replacement fields. see
https://fmt.dev/latest/syntax.html. so when a vector is printed using
logging facility in crimson, libfmt chokes when trying to parse it as a
format string. so we have some options, like:

- disable seastar's operator<< implementation
- escape the "{}" when writing the vector to the output stream
- print the message as the args, and use "{}" as the fmt.

the 3rd one is the most straightforward, and probably more performant.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/dout.h

index c7c08182e5390354a94166e6e8e5e9cb6662d5a5..b8f762991dbaedbb58e963ce544225f496201177 100644 (file)
@@ -129,7 +129,7 @@ struct is_dynamic<dynamic_marker_t<T>> : public std::true_type {};
 #define dendl_impl                              \
      "";                                        \
       _logger.log(crimson::to_log_level(_lv),   \
-                  _out.str().c_str());          \
+                  "{}", _out.str().c_str());    \
     }                                           \
   } while (0)
 #elif defined(WITH_SEASTAR) && defined(WITH_ALIEN)