I've some problem with Boost.Log: this is a snipet:

#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
#include <boost/log/utility/setup/file.hpp>

int main()
{
    namespace logging = boost::log;
    namespace src = boost::log::sources;
    namespace expr = boost::log::expressions;
    namespace keywords = boost::log::keywords;
    namespace sinks = boost::log::sinks;

    logging::add_file_log (
        keywords::file_name = "sample_%N.log",
        keywords::rotation_size = 10 * 1024 * 1024,
        keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),
        keywords::format = "%TimeStamp% [%Uptime%] (%LineID%) <%Severity%>: %Message%"
     );

   BOOST_LOG_TRIVIAL( trace ) << "Message";

   return 0;

}

I've the following output:

[] () <>: Message

Seems that the format doesn't work... whay am I wrong?

有帮助吗?

解决方案

Although your question is incomplete my guess is that you're missing the attribute definition, i.e. try adding something like this after setting up the log file:

logging::add_common_attributes();

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top