-
Notifications
You must be signed in to change notification settings - Fork 194
B&B logs deduplication #1352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
B&B logs deduplication #1352
Changes from all commits
a7f5121
27f2973
501220b
9672194
8367299
b865ae9
6d7f0f5
e5ea499
da1015f
87cdf92
6c04ed4
f79029f
ffdc469
e47c61f
5eb9730
739aab2
3b9f99c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ | |
| #include <cstdarg> | ||
| #include <cstdio> | ||
| #include <cstring> | ||
| #include <format> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is a very heavy heade in terms of compilation times in most c++ implementations. I'd be in favor of keeping it out of common headers and only use it in the TUs where it is required
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not notice a significant increase in compilation time by including or using the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, we can skip the compile-time checks of |
||
| #include <utility> | ||
|
|
||
|
nguidotti marked this conversation as resolved.
|
||
| namespace cuopt::linear_programming::dual_simplex { | ||
|
|
||
|
|
@@ -84,6 +86,27 @@ class logger_t { | |
| } | ||
| } | ||
|
|
||
| template <typename... Args> | ||
| void print_format(std::format_string<Args...> fmt, Args&&... args) | ||
| { | ||
| if (log) { | ||
| std::string msg = std::format(fmt, std::forward<Args&&>(args)...); | ||
| if (log_to_console) { | ||
| #ifdef CUOPT_LOG_ACTIVE_LEVEL | ||
| std::string_view msg_view = msg.ends_with("\n") ? msg.substr(0, msg.size() - 1) : msg; | ||
| CUOPT_LOG_INFO("%s%s", log_prefix.c_str(), msg.c_str()); | ||
| #else | ||
| std::printf("%s", msg.c_str()); | ||
| fflush(stdout); | ||
| #endif | ||
| } | ||
| if (log_to_file && log_file != nullptr) { | ||
| std::fprintf(log_file, "%s", msg.c_str()); | ||
| fflush(log_file); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void debug([[maybe_unused]] const char* fmt, ...) | ||
| { | ||
| if (log) { | ||
|
|
@@ -118,6 +141,27 @@ class logger_t { | |
| } | ||
| } | ||
|
|
||
| template <typename... Args> | ||
| void debug_format(std::format_string<Args...> fmt, Args&&... args) | ||
| { | ||
| if (log) { | ||
| std::string msg = std::format(fmt, std::forward<Args&&>(args)...); | ||
| if (log_to_console) { | ||
| #ifdef CUOPT_LOG_ACTIVE_LEVEL | ||
| std::string_view msg_view = msg.ends_with("\n") ? msg.substr(0, msg.size() - 1) : msg; | ||
| CUOPT_LOG_TRACE("%s%s", log_prefix.c_str(), msg_view.c_str()); | ||
| #else | ||
| std::printf("%s", msg.c_str()); | ||
| fflush(stdout); | ||
| #endif | ||
| } | ||
| if (log_to_file && log_file != nullptr) { | ||
| std::fprintf(log_file, "%s", msg.c_str()); | ||
| fflush(log_file); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| bool log; | ||
| bool log_to_console; | ||
| std::string log_prefix; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this significantly harder to read and understand than the printf format string. It's very easy to read a printf format string and understand the width and precision of each number printed out. I.e. %12.6e means to use a width of 12 with 6 digits of precision after the decimal. The following code is very difficult to read because I now must look up the width from the constants. Also it tells me nothing about the precision after the decimal point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can revert the changes with the constants, so it easier to read.
This specifically is just for the header of the table (so no precision). For the actual formatting for float, it is quite similar actually with the standard C formatting, e.g.,
{:>12.6f}is right-aligned, width 12 and precision 6. The main advantage here is to avoid manually setting the spacing for each log line and aligning to right/center/left. The syntax is the same that Python.