23 #include "bblogger_plugin.h"
25 #include "log_thread.h"
28 #include <sys/types.h>
29 #include <utils/time/time.h>
51 std::set<std::string> ifaces;
53 std::string prefix =
"/fawkes/bblogger/";
54 std::string replay_prefix =
"/fawkes/bblogreplay/";
56 std::string scenario =
"";
60 e.
append(
"No scenario defined, configure %sscenario", prefix.c_str());
71 std::string scenario_prefix = prefix + scenario +
"/";
72 std::string ifaces_prefix = scenario_prefix +
"interfaces/";
74 std::string logdir = LOGDIR;
75 bool buffering =
true;
76 bool flushing =
false;
82 buffering =
config->
get_bool((scenario_prefix +
"buffering").c_str());
86 flushing =
config->
get_bool((scenario_prefix +
"flushing").c_str());
91 int err = stat(logdir.c_str(), &s);
94 Exception se(
"Cannot access logdir %s (%s)", logdir.c_str(), strerror_r(errno, buf, 1024));
95 if (mkdir(logdir.c_str(), 0755) != 0) {
96 se.
append(
"Failed to create log directory (%s)", 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(
"/"));
120 i->
get_string().c_str(), logdir.c_str(), buffering, flushing, scenario.c_str(), &start);
123 config->
set_string((replay_cfg_prefix + iface_name +
"/file").c_str(), filename);
130 throw Exception(
"No interfaces configured for logging, aborting");
137 PLUGIN_DESCRIPTION(
"Write BlackBoard interface data to files")