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