[openddlparser] Remove default log handler and unsolicited output.

This addresses part of #3862.

- Remove default log handler.
- Log callback can now be set to nullptr, which just makes logging a no-op.
- Initial log callback is nullptr.
- Also tweaked format of token error log message and removed newline.

Assimp code that uses this may regain logging output by installing a callback and directing the output through appropriate logging facilities.
pull/3881/head
Jason C 2021-05-04 03:04:12 -04:00 committed by Jason C
parent 9a04f5d4b0
commit 558457e5bf
1 changed files with 13 additions and 34 deletions

View File

@ -72,14 +72,16 @@ const char *getTypeToken(Value::ValueType type) {
}
static void logInvalidTokenError(char *in, const std::string &exp, OpenDDLParser::logCallback callback) {
std::stringstream stream;
stream << "Invalid token \"" << *in << "\""
<< " expected \"" << exp << "\"" << std::endl;
if (callback) {
std::string full(in);
std::string part(full.substr(0, 50));
stream << part;
std::stringstream stream;
stream << "Invalid token \"" << *in << "\" "
<< "(expected \"" << exp << "\") "
<< "in: \"" << part << "\"";
callback(ddl_error_msg, stream.str());
}
}
static bool isIntegerType(Value::ValueType integerType) {
if (integerType != Value::ValueType::ddl_int8 && integerType != Value::ValueType::ddl_int16 &&
@ -111,26 +113,8 @@ static DDLNode *createDDLNode(Text *id, OpenDDLParser *parser) {
return node;
}
static void logMessage(LogSeverity severity, const std::string &msg) {
std::string log;
if (ddl_debug_msg == severity) {
log += "Debug:";
} else if (ddl_info_msg == severity) {
log += "Info :";
} else if (ddl_warn_msg == severity) {
log += "Warn :";
} else if (ddl_error_msg == severity) {
log += "Error:";
} else {
log += "None :";
}
log += msg;
std::cout << log;
}
OpenDDLParser::OpenDDLParser() :
m_logCallback(logMessage),
m_logCallback(nullptr),
m_buffer(),
m_stack(),
m_context(nullptr) {
@ -138,7 +122,7 @@ OpenDDLParser::OpenDDLParser() :
}
OpenDDLParser::OpenDDLParser(const char *buffer, size_t len) :
m_logCallback(&logMessage), m_buffer(), m_context(nullptr) {
m_logCallback(nullptr), m_buffer(), m_context(nullptr) {
if (0 != len) {
setBuffer(buffer, len);
}
@ -149,13 +133,8 @@ OpenDDLParser::~OpenDDLParser() {
}
void OpenDDLParser::setLogCallback(logCallback callback) {
if (nullptr != callback) {
// install user-specific log callback
// install user-specific log callback; null = no log callback
m_logCallback = callback;
} else {
// install default log callback
m_logCallback = &logMessage;
}
}
OpenDDLParser::logCallback OpenDDLParser::getLogCallback() const {