34 #ifndef FMT_HEADER_ONLY 35 #define FMT_HEADER_ONLY 1 37 #ifndef FMT_STRING_ALIAS 38 #define FMT_STRING_ALIAS 1 40 #include <fmt/format.h> 41 #include <fmt/printf.h> 42 #include <fmt/ranges.h> 44 #define DEFAULT_IO_BUFFER_SIZE 1024 84 void operator=(
Logger const &) =
delete;
91 void VError [[noreturn]] (
const char *
format, fmt::format_args args)
const {
92 std::string err_msg = fmt::vformat(format, args);
93 err_msg =
fmt::format(
"[Open3D ERROR] {}", err_msg);
94 err_msg = ColorString(err_msg, TextColor::Red, 1);
95 throw std::runtime_error(err_msg);
98 void VWarning(
const char *format, fmt::format_args args)
const {
100 std::string err_msg = fmt::vformat(format, args);
101 err_msg =
fmt::format(
"[Open3D WARNING] {}", err_msg);
102 err_msg = ColorString(err_msg, TextColor::Yellow, 1);
107 void VInfo(
const char *format, fmt::format_args args)
const {
109 std::string err_msg = fmt::vformat(format, args);
110 err_msg =
fmt::format(
"[Open3D INFO] {}", err_msg);
115 void VDebug(
const char *format, fmt::format_args args)
const {
117 std::string err_msg = fmt::vformat(format, args);
118 err_msg =
fmt::format(
"[Open3D DEBUG] {}", err_msg);
123 template <
typename... Args>
124 void Error [[noreturn]] (
const char *
format,
const Args &... args)
const {
125 VError(format, fmt::make_format_args(args...));
128 template <
typename... Args>
129 void Warning(
const char *format,
const Args &... args)
const {
130 VWarning(format, fmt::make_format_args(args...));
133 template <
typename... Args>
134 void Info(
const char *format,
const Args &... args)
const {
135 VInfo(format, fmt::make_format_args(args...));
138 template <
typename... Args>
139 void Debug(
const char *format,
const Args &... args)
const {
140 VDebug(format, fmt::make_format_args(args...));
149 void ChangeConsoleColor(
TextColor text_color,
int highlight_text)
const;
150 void ResetConsoleColor()
const;
152 std::string ColorString(
const std::string &text,
154 int highlight_text)
const;
158 std::function<void(const std::string &)> print_fcn_ =
159 [](
const std::string &msg) { std::cout << msg << std::endl; };
175 template <
typename... Args>
180 template <
typename... Args>
181 inline void LogWarning(
const char *format,
const Args &... args) {
185 template <
typename... Args>
186 inline void LogInfo(
const char *format,
const Args &... args) {
190 template <
typename... Args>
191 inline void LogDebug(
const char *format,
const Args &... args) {
214 const std::string &progress_info,
215 bool active =
false) {
216 reset(expected_count, progress_info, active);
220 const std::string &progress_info,
222 expected_count_ = expected_count;
223 current_count_ =
static_cast<size_t>(-1);
224 progress_info_ = progress_info;
235 if (current_count_ >= expected_count_) {
236 fmt::print(
"{}[{}] 100%\n", progress_info_,
237 std::string(resolution_,
'='));
239 size_t new_progress_pixel =
240 int(current_count_ * resolution_ / expected_count_);
241 if (new_progress_pixel > progress_pixel_) {
242 progress_pixel_ = new_progress_pixel;
243 int percent =
int(current_count_ * 100 / expected_count_);
244 fmt::print(
"{}[{}>{}] {:d}%\r", progress_info_,
245 std::string(progress_pixel_,
'='),
246 std::string(resolution_ - 1 - progress_pixel_,
' '),
255 const size_t resolution_ = 40;
256 size_t expected_count_;
257 size_t current_count_;
258 std::string progress_info_;
259 size_t progress_pixel_;
267 const std::string &option,
272 const std::string &option,
277 const std::string &option,
283 const std::string &option,
284 const Eigen::VectorXd
default_value = Eigen::VectorXd::Zero(0));
290 const std::vector<std::string> &options);
void VError(const char *format, fmt::format_args args) const
Definition: Console.h:91
std::string GetProgramOptionAsString(int argc, char **argv, const std::string &option, const std::string &default_value)
Definition: Console.cpp:104
void Info(const char *format, const Args &... args) const
Definition: Console.h:134
Definition: Console.h:195
VerbosityContextManager(VerbosityLevel level)
Definition: Console.h:197
void exit()
Definition: Console.h:204
double GetProgramOptionAsDouble(int argc, char **argv, const std::string &option, const double default_value)
Definition: Console.cpp:137
ConsoleProgressBar & operator++()
Definition: Console.h:230
Logger()
Definition: Console.h:82
void LogError(const char *format, const Args &... args)
Definition: Console.h:176
void LogWarning(const char *format, const Args &... args)
Definition: Console.h:181
void Debug(const char *format, const Args &... args) const
Definition: Console.h:139
bool ProgramOptionExistsAny(int argc, char **argv, const std::vector< std::string > &options)
Definition: Console.cpp:189
void VWarning(const char *format, fmt::format_args args) const
Definition: Console.h:98
TextColor
Definition: Console.h:71
void VInfo(const char *format, fmt::format_args args) const
Definition: Console.h:107
void LogDebug(const char *format, const Args &... args)
Definition: Console.h:191
std::string GetCurrentTimeStamp()
Definition: Console.cpp:99
VerbosityLevel GetVerbosityLevel()
Get global verbosity level of Open3D.
Definition: Console.h:171
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c int
Definition: K4aPlugin.cpp:476
int GetProgramOptionAsInt(int argc, char **argv, const std::string &option, const int default_value)
Definition: Console.cpp:116
VerbosityLevel
Definition: Console.h:49
void enter()
Definition: Console.h:199
void SetVerbosityLevel(VerbosityLevel level)
Definition: Console.h:166
Definition: PinholeCameraIntrinsic.cpp:35
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c k4a_image_t image_handle uint8_t image_handle image_handle image_handle image_handle image_handle timestamp_usec white_balance image_handle k4a_device_configuration_t config device_handle char size_t serial_number_size bool int32_t int32_t int32_t int32_t default_value
Definition: K4aPlugin.cpp:645
void Warning(const char *format, const Args &... args) const
Definition: Console.h:129
ConsoleProgressBar(size_t expected_count, const std::string &progress_info, bool active=false)
Definition: Console.h:213
filament::Texture::InternalFormat format
Definition: FilamentResourceManager.cpp:191
static Logger & i()
Definition: Console.h:86
void VDebug(const char *format, fmt::format_args args) const
Definition: Console.h:115
void reset(size_t expected_count, const std::string &progress_info, bool active)
Definition: Console.h:219
Eigen::VectorXd GetProgramOptionAsEigenVectorXd(int argc, char **argv, const std::string &option, const Eigen::VectorXd default_value)
Definition: Console.cpp:156
Definition: Console.h:211
VerbosityLevel verbosity_level_
Definition: Console.h:157
bool ProgramOptionExists(int argc, char **argv, const std::string &option)
Definition: Console.cpp:185
void LogInfo(const char *format, const Args &... args)
Definition: Console.h:186