Boost logo

Boost Users :

Subject: [Boost-users] BOOST.LOG inti_from_setting core dumped
From: list_mailing_at_[hidden]
Date: 2011-03-31 06:01:00


Hello to all,
Using init_from_settings method I get a core dump.
./test_logging
Filename:log.log
terminate called after throwing an instance of 'boost::exception_detail::
clone_impl<boost::exception_detail::error_info_injector<boost::log_mt_posix::
missing_value> >'
  what(): File name is not specified
Aborted (core dumped)
As you can read, the Filename value is correctly set.
Any suggestion to fix it?

Below the source code for the program test_logging:

#include <string>
#include <sstream>
#include <ostream>
#include <fstream>
#include <boost/any.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/init/from_settings.hpp>
#include <boost/log/attributes.hpp>

#include <sensor_options.hpp>

using namespace boost::log;
namespace src = boost::log::sources;
using namespace std;

ostream* stream_null = new ofstream("/dev/null");

class MyClass {
public:
MyClass(): _a(0), _b(0){};
void incrementA(){++_a;};
void incrementB(){++_b;};
void logParam1(src::logger& lg, trivial::severity_level lvl)
{
stringstream s;
s << "A: " << _a << ", B:" << _b;
BOOST_LOG_FUNCTION();
BOOST_LOG_SEV(lg, lvl) << s.str();
}
void logParam2(trivial::severity_level lvl)
{
BOOST_LOG_FUNCTION();
stringstream s;
s << "A: " << _a << ", B:" << _b;
switch(lvl) {
case trivial::trace:
BOOST_LOG_TRIVIAL(trace) << s.str();
break;
case trivial::debug:
BOOST_LOG_TRIVIAL(debug) << s.str();
break;
case trivial::warning:
BOOST_LOG_TRIVIAL(warning) << s.str();
break;
case trivial::info:
BOOST_LOG_TRIVIAL(info) << s.str();
break;
case trivial::error:
BOOST_LOG_TRIVIAL(error) << s.str();
break;
case trivial::fatal:
BOOST_LOG_TRIVIAL(fatal) << s.str();
break;
}
}
private:
int _a;
int _b;
};

int main()
{
SensorOptions so;
    char* data[3];
    int nparams = 3;
    char path[255];
    memset(path, 0, 255);
    getcwd(path, 255);
    string cmd_line("./sensor -c ");
    cmd_line += path;
    cmd_line += "/data/ludmilla.conf";

istringstream iss(cmd_line);
string token;
int i = 0;

while (getline(iss, token, ' ')) {
if (i >= nparams) return 0;
data[i] = new char[255];
if (!data[i]) return 0;
memcpy(data[i], token.c_str(), token.size());
data[i][token.size()] = '\0';
++i;
}

src::logger lg;
    if (!so.parse(nparams, data, stream_null))
    std::cout << "Configuration parsing failed\n";
boost::any filename = so.loggingConfig["Sink:File"]["FileName"];
if (boost::any_cast<string>(&filename) == NULL) {
std::cout << " Filename empty\n";
return 0;
}
std::cout << " Filename:" << *(boost::any_cast<string>(&filename)) << endl;
    init_from_settings(so.loggingConfig);
    std::cout<< "dopo init\n";
    MyClass mc;
    mc.incrementA();
    mc.incrementB();
    mc.logParam1(lg, trivial::warning);
    mc.logParam2(trivial::warning);
    mc.incrementA();
    mc.incrementB();
    mc.logParam1(lg, trivial::info);
    mc.logParam2(trivial::info);
    return 1;
}
and that's the result of its running.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net