Slic3r::Log: Add multiline flag to all of the stream interfaces with a default so that the stream can be reused w/o outputting the header information again and again (but still get treated properly for purposes of topic)

This commit is contained in:
Joseph Lenox 2020-01-27 00:19:01 -06:00
parent 44455c8cb4
commit 54a31eed20
2 changed files with 32 additions and 23 deletions

View File

@ -52,9 +52,10 @@ void _Log::debug(const std::string& topic, const std::wstring& message) { this->
void _Log::fatal_error(const std::string& topic, const std::string& message) {
this->fatal_error(topic) << message << std::endl;
}
std::ostream& _Log::fatal_error(const std::string& topic) {
std::ostream& _Log::fatal_error(const std::string& topic, bool multiline) {
if (this->_has_log_level(log_t::FERR) && this->_has_topic(topic)) {
_out << topic << std::setfill(' ') << std::setw(6) << "FERR" << ": ";
if (!multiline)
_out << topic << std::setfill(' ') << std::setw(6) << "FERR" << ": ";
return _out;
}
return null_log;
@ -63,9 +64,10 @@ std::ostream& _Log::fatal_error(const std::string& topic) {
void _Log::error(const std::string& topic, const std::string& message) {
this->error(topic) << message << std::endl;
}
std::ostream& _Log::error(const std::string& topic) {
std::ostream& _Log::error(const std::string& topic, bool multiline) {
if (this->_has_log_level(log_t::ERR) && this->_has_topic(topic)) {
_out << topic << std::setfill(' ') << std::setw(6) << "ERR" << ": ";
if (!multiline)
_out << topic << std::setfill(' ') << std::setw(6) << "ERR" << ": ";
return _out;
}
return null_log;
@ -75,9 +77,10 @@ void _Log::info(const std::string& topic, const std::string& message) {
this->info(topic) << message << std::endl;
}
std::ostream& _Log::info(const std::string& topic) {
std::ostream& _Log::info(const std::string& topic, bool multiline) {
if (this->_has_log_level(log_t::INFO) && this->_has_topic(topic)) {
_out << topic << std::setfill(' ') << std::setw(6) << "INFO" << ": ";
if (!multiline)
_out << topic << std::setfill(' ') << std::setw(6) << "INFO" << ": ";
return _out;
}
return null_log;
@ -87,9 +90,10 @@ void _Log::warn(const std::string& topic, const std::string& message) {
this->warn(topic) << message << std::endl;
}
std::ostream& _Log::warn(const std::string& topic) {
std::ostream& _Log::warn(const std::string& topic, bool multiline) {
if (this->_has_log_level(log_t::WARN) && this->_has_topic(topic)) {
_out << topic << std::setfill(' ') << std::setw(6) << "WARN" << ": ";
if (!multiline)
_out << topic << std::setfill(' ') << std::setw(6) << "WARN" << ": ";
return _out;
}
return null_log;
@ -99,9 +103,10 @@ void _Log::debug(const std::string& topic, const std::string& message) {
this->debug(topic) << message << std::endl;
}
std::ostream& _Log::debug(const std::string& topic) {
std::ostream& _Log::debug(const std::string& topic, bool multiline) {
if (this->_has_log_level(log_t::DEBUG) && this->_has_topic(topic)) {
_out << topic << std::setfill(' ') << std::setw(6) << "DEBUG" << ": ";
if (!multiline)
_out << topic << std::setfill(' ') << std::setw(6) << "DEBUG" << ": ";
return _out;
}
return null_log;

View File

@ -42,21 +42,21 @@ public:
}
void fatal_error(const std::string& topic, const std::string& message);
void fatal_error(const std::string& topic, const std::wstring& message);
std::ostream& fatal_error(const std::string& topic);
std::ostream& fatal_error(const std::string& topic, bool multiline = false);
void error(const std::string& topic, const std::string& message);
void error(const std::string& topic, const std::wstring& message);
std::ostream& error(const std::string& topic);
std::ostream& error(const std::string& topic, bool multiline = false);
void info(const std::string& topic, const std::string& message);
void info(const std::string& topic, const std::wstring& message);
std::ostream& info(const std::string& topic);
std::ostream& info(const std::string& topic, bool multiline = false);
void debug(const std::string& topic, const std::string& message);
void debug(const std::string& topic, const std::wstring& message);
std::ostream& debug(const std::string& topic);
std::ostream& debug(const std::string& topic, bool multiline = false);
void warn(const std::string& topic, const std::string& message);
void warn(const std::string& topic, const std::wstring& message);
std::ostream& warn(const std::string& topic);
std::ostream& warn(const std::string& topic, bool multiline = false);
void raw(const std::string& message);
void raw(const std::wstring& message);
std::ostream& raw();
@ -159,32 +159,36 @@ public:
/// Logs an error message with Slic3r.
/// \param topic [in] file or heading for message
/// \param multiline [in] Is this a following part of a multline output (default False)
/// \return reference to output ostream for << chaining.
/// \note Developer is expected to add newlines.
static std::ostream& error(std::string topic) {
return slic3r_log->error(topic);
static std::ostream& error(std::string topic, bool multiline = false) {
return slic3r_log->error(topic, multiline);
}
/// Logs a debugging message with Slic3r.
/// \param topic [in] file or heading for message
/// \param multiline [in] Is this a following part of a multline output (default False)
/// \return reference to output ostream for << chaining.
/// \note Developer is expected to add newlines.
static std::ostream& debug(std::string topic) {
return slic3r_log->debug(topic);
static std::ostream& debug(std::string topic, bool multiline = false) {
return slic3r_log->debug(topic, multiline);
}
/// Logs a warning message with Slic3r.
/// \param topic [in] file or heading for message
/// \param multiline [in] Is this a following part of a multline output (default False)
/// \return reference to output ostream for << chaining.
/// \note Developer is expected to add newlines.
static std::ostream& warn(std::string topic) {
return slic3r_log->warn(topic);
static std::ostream& warn(std::string topic, bool multiline = false) {
return slic3r_log->warn(topic, multiline);
}
/// Logs an informational message with Slic3r.
/// \param topic [in] file or heading for message
/// \param multiline [in] Is this a following part of a multline output (default False)
/// \return reference to output ostream for << chaining.
/// \note Developer is expected to add newlines.
static std::ostream& info(std::string topic) {
return slic3r_log->info(topic);
static std::ostream& info(std::string topic, bool multiline = false) {
return slic3r_log->info(topic, multiline);
}
/// Unadorned ostream output for multiline constructions.