Flexible Logging
Current behaviour:
- ScenarioEngine logs to std::cout
- When running the ScenarioEngine in a Simulator (which does some specific logging) the log output to the console is mixed: The logging from the simulator has a specific format (i.e. with timestamps). The logging of the engine is just the plain string. This does not match
- ScenarioEngine provides no mechansim to inject a custom logging functionality
Expected behaviour:
- ScenarioEngine provides a default logging mechansim (as it is currently, just log to std::cout)
- ScenarioEngine can be customized how to log
Proposed solution:
- ScenarioEngine implements and provides logging functions, i.e. Info(...), Warn(...) and Error(...)
- The ScenarioEngine provides a SetInfoLogger(...), SetWarnLogger(...), SetErrorLogger(...), which takes in a lambda (= the custom way how to do logging).
- The logging functions call the logging lambda. The default lambda logs to std::cout
- If the lambda was set the logging functions call the custom logging.
// Pseudo c++ code:
ScenarioEngine::info_log_func_ = [](const std::string& message){
std::cout << "Info: " << message << std::endl;
}
ScenarioEngine::SetInfoLogger(std::function<void(const std::string&)> log_func)
{
info_log_func_ = log_func;
}
ScenarioEngine::Info(const std::string& message)
{
info_log_func_(message);
}
// ...
auto log_func = [this](const std::string& message)
{
CustomInfoLog(message);
}
engine->SetInfoLogger(log_func);