[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,13 +72,15 @@ const char *getTypeToken(Value::ValueType type) {
} }
static void logInvalidTokenError(char *in, const std::string &exp, OpenDDLParser::logCallback callback) { static void logInvalidTokenError(char *in, const std::string &exp, OpenDDLParser::logCallback callback) {
std::stringstream stream; if (callback) {
stream << "Invalid token \"" << *in << "\"" std::string full(in);
<< " expected \"" << exp << "\"" << std::endl; std::string part(full.substr(0, 50));
std::string full(in); std::stringstream stream;
std::string part(full.substr(0, 50)); stream << "Invalid token \"" << *in << "\" "
stream << part; << "(expected \"" << exp << "\") "
callback(ddl_error_msg, stream.str()); << "in: \"" << part << "\"";
callback(ddl_error_msg, stream.str());
}
} }
static bool isIntegerType(Value::ValueType integerType) { static bool isIntegerType(Value::ValueType integerType) {
@ -111,26 +113,8 @@ static DDLNode *createDDLNode(Text *id, OpenDDLParser *parser) {
return node; 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() : OpenDDLParser::OpenDDLParser() :
m_logCallback(logMessage), m_logCallback(nullptr),
m_buffer(), m_buffer(),
m_stack(), m_stack(),
m_context(nullptr) { m_context(nullptr) {
@ -138,7 +122,7 @@ OpenDDLParser::OpenDDLParser() :
} }
OpenDDLParser::OpenDDLParser(const char *buffer, size_t len) : 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) { if (0 != len) {
setBuffer(buffer, len); setBuffer(buffer, len);
} }
@ -149,13 +133,8 @@ OpenDDLParser::~OpenDDLParser() {
} }
void OpenDDLParser::setLogCallback(logCallback callback) { void OpenDDLParser::setLogCallback(logCallback callback) {
if (nullptr != callback) { // install user-specific log callback; null = no log callback
// install user-specific log callback m_logCallback = callback;
m_logCallback = callback;
} else {
// install default log callback
m_logCallback = &logMessage;
}
} }
OpenDDLParser::logCallback OpenDDLParser::getLogCallback() const { OpenDDLParser::logCallback OpenDDLParser::getLogCallback() const {