23 #include "bblogger_plugin.h"
24 #include "log_thread.h"
26 #include <utils/time/time.h>
32 #include <sys/types.h>
36 using namespace fawkes;
52 std::set<std::string> ifaces;
54 std::string prefix =
"/fawkes/bblogger/";
55 std::string replay_prefix =
"/fawkes/bblogreplay/";
57 std::string scenario =
"";
59 scenario = config->
get_string((prefix +
"scenario").c_str());
61 e.
append(
"No scenario defined, configure %sscenario", prefix.c_str());
72 std::string scenario_prefix = prefix + scenario +
"/";
73 std::string ifaces_prefix = scenario_prefix +
"interfaces/";
75 std::string logdir = LOGDIR;
76 bool buffering =
true;
77 bool flushing =
false;
79 logdir = config->
get_string((scenario_prefix +
"logdir").c_str());
82 buffering = config->
get_bool((scenario_prefix +
"buffering").c_str());
85 flushing = config->
get_bool((scenario_prefix +
"flushing").c_str());
89 int err = stat(logdir.c_str(), &s);
92 Exception se (
"Cannot access logdir %s (%s)",
93 logdir.c_str(), strerror_r(errno, buf, 1024));
94 if (mkdir(logdir.c_str(), 0755) != 0) {
95 se.
append(
"Failed to create log directory (%s)",
96 strerror_r(errno, buf, 1024));
99 }
else if ( ! S_ISDIR(s.st_mode) ) {
100 throw Exception(
"Logdir path %s is not a directory", logdir.c_str());
109 struct tm *tmp = localtime(&(now.
get_timeval()->tv_sec));
110 strftime(date, 21,
"%F-%H-%M-%S", tmp);
111 std::string replay_cfg_prefix = replay_prefix + scenario +
"-" + date +
"/logs/";
115 std::string iface_name = std::string(i->
path()).substr(ifaces_prefix.length());
116 iface_name = iface_name.substr(0, iface_name.find(
"/"));
122 scenario.c_str(), &start);
125 config->
set_string((replay_cfg_prefix + iface_name +
"/file").c_str(), filename);
132 throw Exception(
"No interfaces configured for logging, aborting");
139 PLUGIN_DESCRIPTION(
"Write BlackBoard interface data to files")