11 #include <fmt/printf.h>
12 #include <fmt/ranges.h>
18 [](
const std::string &msg) { std::cout << msg <<
std::endl; };
20 Logger::Logger() : impl_(new Logger::Impl()) {
21 impl_->print_fcn_ = Logger::Impl::console_print_fcn_;
22 impl_->verbosity_level_ = VerbosityLevel::Info;
30 void Logger::VError [[noreturn]] (
const char *file,
33 const std::string &message)
const {
34 std::string err_msg =
fmt::format(
"[ Error] ({}) {}:{}: {}\n",
function,
36 err_msg = impl_->ColorString(err_msg, TextColor::Red, 1);
40 throw std::runtime_error(err_msg);
43 void Logger::VWarning(
const char *file,
46 const std::string &message)
const {
47 std::string err_msg =
fmt::format(
"[CloudViewer WARNING] {}", message);
48 err_msg = impl_->ColorString(err_msg, TextColor::Yellow, 1);
49 impl_->print_fcn_(err_msg);
52 void Logger::VInfo(
const char *file,
55 const std::string &message)
const {
56 std::string err_msg =
fmt::format(
"[CloudViewer INFO] {}", message);
57 impl_->print_fcn_(err_msg);
60 void Logger::VDebug(
const char *file,
63 const std::string &message)
const {
64 std::string err_msg =
fmt::format(
"[CloudViewer DEBUG] {}", message);
65 impl_->print_fcn_(err_msg);
68 void Logger::SetPrintFunction(
69 std::function<
void(
const std::string &)> print_fcn) {
70 impl_->print_fcn_ = print_fcn;
73 const std::function<void(
const std::string &)> Logger::GetPrintFunction() {
74 return impl_->print_fcn_;
77 void Logger::ResetPrintFunction() {
78 impl_->print_fcn_ = impl_->console_print_fcn_;
82 impl_->verbosity_level_ = verbosity_level;
86 return impl_->verbosity_level_;
97 ConsoleProgressBar::ConsoleProgressBar(
size_t expected_count,
98 const std::string &progress_info,
100 reset(expected_count, progress_info, active);
103 void ConsoleProgressBar::reset(
size_t expected_count,
104 const std::string &progress_info,
106 expected_count_ = expected_count;
107 current_count_ =
static_cast<size_t>(-1);
108 progress_info_ = progress_info;
115 setCurrentCount(current_count_ + 1);
119 void ConsoleProgressBar::setCurrentCount(
size_t n) {
124 if (current_count_ >= expected_count_) {
125 fmt::print(
"{}[{}] 100%\n", progress_info_,
126 std::string(resolution_,
'='));
128 size_t new_progress_pixel =
129 int(current_count_ * resolution_ / expected_count_);
130 if (new_progress_pixel > progress_pixel_) {
131 progress_pixel_ = new_progress_pixel;
132 int percent = int(current_count_ * 100 / expected_count_);
133 fmt::print(
"{}[{}>{}] {:d}%\r", progress_info_,
134 std::string(progress_pixel_,
'='),
135 std::string(resolution_ - 1 - progress_pixel_,
' '),
filament::Texture::InternalFormat format
Logger class should be used as a global singleton object (GetInstance()).
QTextStream & endl(QTextStream &stream)
ccGuiPythonInstance * GetInstance() noexcept
void SetVerbosityLevel(VerbosityLevel level)
VerbosityLevel GetVerbosityLevel()
Get global verbosity level of CloudViewer.
Generic file read and write utility for python interface.
static std::function< void(const std::string &)> console_print_fcn_