23 #include "bblogger_plugin.h" 24 #include "log_thread.h" 26 #include <utils/time/time.h> 32 #include <sys/types.h> 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")
const timeval * get_timeval() const
Obtain the timeval where the time is stored.
BlackBoardLoggerPlugin(fawkes::Configuration *config)
Constructor.
const char * get_filename() const
Get filename.
Fawkes library namespace.
virtual bool get_bool(const char *path)=0
Get value from configuration which is of type bool.
virtual ValueIterator * search(const char *path)=0
Iterator with search results.
A class for handling time.
virtual bool next()=0
Check if there is another element and advance to this if possible.
BlackBoard logger thread.
BlackBoard logger plugin.
Base class for exceptions in Fawkes.
ThreadList thread_list
Thread list member.
virtual std::string get_string() const =0
Get string value.
virtual const char * path() const =0
Path of value.
void set_threadlist(fawkes::ThreadList &thread_list)
Set threadlist and master status.
void push_back(Thread *thread)
Add thread to the end.
Iterator interface to iterate over config values.
Interface for configuration handling.
virtual void set_string(const char *path, std::string &s)=0
Set new value in configuration of type string.
void append(const char *format,...)
Append messages to the message list.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.