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 >'
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
#include
#include
#include
#include
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.