0

I'm trying unsuccessfully to use the macro BOOST_LOG_NAMED_SCOPE with no hard-coding (e.g no BOOST_LOG_NAMED_SCOPE("bla"), but BOOST_LOG_NAMED_SCOPE(some_variable); this macro uses inside a boost::log::string_literal that have no C'tor for std::string or char*. The only thing it accepts is const char[] (NOT const char*) - which doesn't help me at all because I can't hard-code it - this value must be retrieved from a function.

So, I need to find a way to construct boost::log::string_literal with std::string or char*, or somehow to edit const char[]... (I tried also to create a char[] and cast it to const char[], but failed)

4

1 回答 1

0

嗯。“字符串文字”说明了一切。它只适用于文字,并且那些根据定义(在标准中,即)char const[]

这种设计决策(使名称在编译时已知并固定)可能有几个原因。从概念上讲,它将使日志记录“可预测”(如果范围名称不同,您将如何解释日志?),并且可能与性能有关(它甚至可以用于基于范围名称静态禁用某些日志记录,但是根据编译器的不同,输出格式等其他内容可能会提高性能)。

因此,您可以不希望对事物进行硬编码,但不希望在这样做时使用需要字符串文字的宏。

现在,您可以使用extern适当类型的变量 ( extern char const some_scope_name[]),我想这至少可以让您有机会在另一个翻译单元中定义值。

于 2014-06-02T20:27:20.277 回答