boost log file cannot create sample.log file

0

I've been struggling with boost log for a while now - I got their simple example writing to a log file (http://boost-log.sourceforge.net/libs/log/example/doc/tutorial_file.cpp).The problem is when I use this part of the code ...

void init()
{
    logging::add_file_log("sample.log");

    logging::core::get()->set_filter
    (
        logging::trivial::severity >= logging::trivial::info
    );
}

Instead of sample.log file, 00000.log file is created. And when I use this part of the code ...

void init()
{
    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%]: %Message%"
    );

    logging::core::get()->set_filter
    (
        logging::trivial::severity >= logging::trivial::info
    );
}

I get the following error message: Exception thrown at 0x00007FF787AD0393 in Boost_log_sample.exe: 0xC0000005: Access violation reading location 0x00003BBA20597184.

I'm on win10 64bit and used VS2015,boost_1_71_0.Installing Boost With NuGet (https://www.scalyr.com/blog/getting-started-quickly-c-logging/)

I don't have this problem with boost_1_66_0.

Here's my code:

#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>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>

namespace logging = boost::log;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace keywords = boost::log::keywords;

void init()
{
    logging::add_file_log
    (
        keywords::file_name = "sample_%N.log",                                        /*< file name pattern >*/
        keywords::rotation_size = 10 * 1024 * 1024,                                   /*< rotate files every 10 MiB... >*/
        keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), /*< ...or at midnight >*/
        keywords::format = "[%TimeStamp%]: %Message%"                                 /*< log record format >*/
    );

    logging::core::get()->set_filter
    (
        logging::trivial::severity >= logging::trivial::info
    );
}


int main(int, char*[])
{
    init();
    logging::add_common_attributes();

    using namespace logging::trivial;
    src::severity_logger< severity_level > lg;

    BOOST_LOG_SEV(lg, trace) << "A trace severity message";
    BOOST_LOG_SEV(lg, debug) << "A debug severity message";
    BOOST_LOG_SEV(lg, info) << "An informational severity message";
    BOOST_LOG_SEV(lg, warning) << "A warning severity message";
    BOOST_LOG_SEV(lg, error) << "An error severity message";
    BOOST_LOG_SEV(lg, fatal) << "A fatal severity message";

    return 0;
}
c++
windows
visual-studio
boost-log
asked on Stack Overflow Nov 15, 2019 by Mohsen Ghahremani Manesh • edited Nov 16, 2019 by Mohsen Ghahremani Manesh

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0