refactor to only use log() and use locale converter to figure out the rest.

This commit is contained in:
Joseph Lenox 2018-11-22 23:03:10 -06:00
parent 86c776287e
commit bd9b9cc416
2 changed files with 15 additions and 20 deletions

View File

@ -19,13 +19,10 @@ static std::ostream null_log(&log_null);
std::unique_ptr<_Log> slic3r_log {_Log::make_log()}; std::unique_ptr<_Log> slic3r_log {_Log::make_log()};
_Log::_Log() : _out(std::clog), _wout(std::wclog) { _Log::_Log() : _out(std::clog) {
} }
_Log::_Log(std::ostream& out) : _out(out), _wout(std::wclog) { _Log::_Log(std::ostream& out) : _out(out) {
}
_Log::_Log(std::wostream& out) : _out(std::clog), _wout(out) {
} }
bool _Log::_has_log_level(log_t lvl) { bool _Log::_has_log_level(log_t lvl) {
@ -37,13 +34,12 @@ bool _Log::_has_log_level(log_t lvl) {
return false; return false;
} }
void _Log::fatal_error(const std::string& topic, const std::wstring& message) { void _Log::fatal_error(const std::string& topic, const std::wstring& message) { this->fatal_error(topic, this->converter.to_bytes(message)); }
// _wout << this->converter.from_bytes(topic); void _Log::error(const std::string& topic, const std::wstring& message) { this->error(topic, this->converter.to_bytes(message)); }
if (this->_has_log_level(log_t::FERR)) { void _Log::warn(const std::string& topic, const std::wstring& message) { this->warn(topic, this->converter.to_bytes(message)); }
_wout << std::setw(6) << "FERR" << ": "; void _Log::info(const std::string& topic, const std::wstring& message) { this->info(topic, this->converter.to_bytes(message)); }
_wout << message << std::endl; void _Log::debug(const std::string& topic, const std::wstring& message) { this->debug(topic, this->converter.to_bytes(message)); }
}
}
void _Log::fatal_error(const std::string& topic, const std::string& message) { void _Log::fatal_error(const std::string& topic, const std::string& message) {
this->fatal_error(topic) << message << std::endl; this->fatal_error(topic) << message << std::endl;
} }
@ -105,6 +101,7 @@ std::ostream& _Log::debug(const std::string& topic) {
void _Log::raw(const std::string& message) { void _Log::raw(const std::string& message) {
this->raw() << message << std::endl; this->raw() << message << std::endl;
} }
void _Log::raw(const std::wstring& message) { this->raw(this->converter.to_bytes(message)); }
std::ostream& _Log::raw() { std::ostream& _Log::raw() {
return _out; return _out;

View File

@ -34,25 +34,25 @@ public:
std::unique_ptr<_Log> tmp {new _Log(out)}; std::unique_ptr<_Log> tmp {new _Log(out)};
return tmp; return tmp;
} }
static std::unique_ptr<_Log> make_log(std::wostream& out) {
std::unique_ptr<_Log> tmp {new _Log(out)};
return tmp;
}
void fatal_error(const std::string& topic, const std::wstring& message);
void fatal_error(const std::string& topic, const std::string& message); 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);
void error(const std::string& topic, const std::wstring& message);
void error(const std::string& topic, const std::string& message); 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);
void info(const std::string& topic, const std::string& message); 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);
void debug(const std::string& topic, const std::string& message); 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);
void warn(const std::string& topic, const std::string& message); 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);
void raw(const std::string& message); void raw(const std::string& message);
void raw(const std::wstring& message);
std::ostream& raw(); std::ostream& raw();
template <class T> template <class T>
@ -68,10 +68,8 @@ public:
// void operator=(_Log const&) = delete; // void operator=(_Log const&) = delete;
private: private:
std::ostream& _out; std::ostream& _out;
std::wostream& _wout;
_Log(); _Log();
_Log(std::ostream& out); _Log(std::ostream& out);
_Log(std::wostream& out);
bool _inclusive_levels { true }; bool _inclusive_levels { true };
std::set<log_t> _log_level { }; std::set<log_t> _log_level { };