Skip to content

Commit

Permalink
Slic3r::Log: Add multiline flag to all of the stream interfaces with …
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
lordofhyphens committed Jan 27, 2020
1 parent 44455c8 commit 54a31ee
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
25 changes: 15 additions & 10 deletions xs/src/libslic3r/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
30 changes: 17 additions & 13 deletions xs/src/libslic3r/Log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ class _Log {
}
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();
Expand Down Expand Up @@ -159,32 +159,36 @@ class Log {

/// 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.
Expand Down

0 comments on commit 54a31ee

Please sign in to comment.