133 if ((
int)msg.size() <= lineWidth) {
137 size_t nextLineBreak = msg.find(
'\n');
138 size_t spaceAfterLine = msg.find(
' ', lineWidth);
139 while (spaceAfterLine != std::string::npos) {
140 if (nextLineBreak == std::string::npos || nextLineBreak > spaceAfterLine) {
141 msg = msg.replace(spaceAfterLine, 1,
"\n");
142 pos = spaceAfterLine + 1;
144 pos = nextLineBreak + 1;
146 spaceAfterLine = msg.find(
' ', pos + lineWidth);
147 nextLineBreak = msg.find(
'\n', pos);
163 msg =
build(msg, addType);
175 msg =
build(msg, addType);
178 i->inform(msg,
true);
217 inform(
toString(i.second) +
" total messages of type: " + i.first);
284 _putenv_s(
"LANGUAGE", locale.data());
286 setenv(
"LANGUAGE", locale.data(),
true);
289 if (!setlocale(LC_MESSAGES,
"")) {
292 const char* sumoPath = getenv(
"SUMO_HOME");
293 if (sumoPath ==
nullptr) {
294 if (!bindtextdomain(
"sumo",
nullptr)) {
295 WRITE_WARNING(
TL(
"Environment variable SUMO_HOME is not set, could not find localized messages."));
299 const std::string path = sumoPath + std::string(
"/data/locale/");
300 if (!bindtextdomain(
"sumo", path.data())) {
305 bind_textdomain_codeset(
"sumo",
"UTF-8");
323 if (oc.
getBool(
"no-warnings")) {
327 if (oc.
isSet(
"log",
false)) {
330 if (!oc.
getBool(
"no-warnings")) {
334 if (oc.
getBool(
"log.timestamps")) {
337 if (oc.
getBool(
"log.processid")) {
341 if (oc.
isSet(
"message-log",
false)) {
345 if (oc.
isSet(
"error-log",
false)) {
375 std::stringstream prefix;
376 const std::chrono::system_clock::time_point now_timestamp = std::chrono::system_clock::now();
377 const auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now_timestamp.time_since_epoch()) % 1000;
378 const std::time_t now_time_t = std::chrono::system_clock::to_time_t(now_timestamp);
381 std::strftime(timeString, 21,
"[%F %T", std::localtime(&now_time_t));
382 prefix << timeString <<
'.' << std::setfill(
'0') << std::setw(3) << milliseconds.count() <<
"] ";
389 std::stringstream prefix;
392 prefix << GetCurrentProcessId();
402 myType(type), myWasInformed(false), myAggregationThreshold(-1) {
#define WRITE_WARNINGF(...)
#define WRITE_WARNING(msg)
#define UNUSED_PARAMETER(x)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
virtual void addRetriever(OutputDevice *retriever)
Adds a further retriever to the instance responsible for a certain msg type.
std::vector< std::string > myInitialMessages
storage for initial messages
static MsgHandler * getGLDebugInstance()
Returns the instance to add GLdebug to.
bool wasInformed() const
Returns the information whether any messages were added.
std::string buildProcessIdPrefix(void) const
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
std::string buildTimestampPrefix(void) const
static void enableDebugGLMessages(bool enable)
enable/disable gl-debug messages
static MsgHandler * myGLDebugInstance
The instance to handle glDebug.
static std::string insertLineBreaks(std::string msg, int lineWidth)
reformats a long string to contain newline after a certain line length in px (depending on the curren...
virtual void endProcessMsg(std::string msg)
Ends a process information.
std::string build(const std::string &msg, bool addType)
Builds the string which includes the mml-message type.
static Factory myFactory
The function to call for new MsgHandlers, nullptr means use default constructor.
bool myWasInformed
information whether an output occurred at all
static bool myWriteTimestamps
Whether to prefix every message with a time stamp.
static void setupI18n(const std::string &locale="")
set up gettext stuff
static void initOutputOptions()
init output options
static MsgHandler * myErrorInstance
The instance to handle errors.
static MsgHandler * getDebugInstance()
Returns the instance to add debug to.
static MsgHandler * myMessageInstance
The instance to handle normal messages.
bool isRetriever(OutputDevice *retriever) const
Returns whether the given output device retrieves messages from the handler.
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
std::map< const std::string, int > myAggregationCount
count for messages of the same type
static void enableDebugMessages(bool enable)
enable/disable debug messages
static bool myAmProcessingProcess
Information whether a process information is printed to cout.
std::vector< OutputDevice * > myRetrievers
The list of retrievers that shall be informed about new messages or errors.
MsgHandler *(* Factory)(MsgType)
virtual ~MsgHandler()
destructor
virtual void clear(bool resetInformed=true)
Clears information whether an error occurred previously and print aggregated message summary.
static MsgHandler * myDebugInstance
The instance to handle debug.
void setAggregationThreshold(const int thresh)
static MsgHandler * myWarningInstance
The instance to handle warnings.
virtual void endProcessMsg2(bool success, long duration=-1)
Ends a process information with predefined messages.
virtual void beginProcessMsg(std::string msg, bool addType=true)
Begins a process information.
static bool myWriteDebugMessages
Flag to enable or disable debug output.
static bool myWriteDebugGLMessages
Flag to enable or disable GL specific debug output.
static std::string myWarningPrefix
The possibly translated warning prefix (mainly for speedup)
static bool myWriteProcessId
Whether to prefix every message with the process id.
static void cleanupOnEnd()
Removes pending handler.
static std::string myErrorPrefix
The possibly translated error prefix (mainly for speedup)
static void removeRetrieverFromAllInstances(OutputDevice *out)
ensure that that given output device is no longer used as retriever by any instance
virtual void removeRetriever(OutputDevice *retriever)
Removes the retriever from the handler.
int myAggregationThreshold
do not output more messages of the same type if the count exceeds this threshold
@ MT_GLDEBUG
The message is GL debug output.
@ MT_DEBUG
The message is debug output.
@ MT_MESSAGE
The message is only something to show.
@ MT_ERROR
The message is an error.
@ MT_WARNING
The message is a warning.
MsgHandler(MsgType type)
standard constructor
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
A storage for options typed value containers)
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
static OutputDevice & getDevice(const std::string &name, bool usePrefix=true)
Returns the described OutputDevice.