You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using HiGHS as a library and I am trying to integrate it into the existing logging framework via setCallback(), but the callback is never called unless I also set a log file and enable the output flag (for which I found no documentation).
The without file test fails, the with file test passes. The with file test creates a log file, but it is empty.
I am not quite sure how this is supposed to work, but I would suggest something like the following. This makes my new tests pass and the log output also appears in the log file. Note that this change makes unit_tests print lots of Hs to the console, so... something is off, I guess?
diff --git a/src/io/HighsIO.cpp b/src/io/HighsIO.cpp
index 96c990495..05ac26828 100644
--- a/src/io/HighsIO.cpp+++ b/src/io/HighsIO.cpp@@ -95,8 +95,14 @@ std::array<char, 32> highsDoubleToString(const double val,
void highsLogUser(const HighsLogOptions& log_options_, const HighsLogType type,
const char* format, ...) {
- if (!*log_options_.output_flag ||- (log_options_.log_stream == NULL && !*log_options_.log_to_console))+ if (!*log_options_.output_flag)+ return;++ const bool log_stream = log_options_.log_stream != NULL || *log_options_.log_to_console;+ const bool use_log_callback =+ log_options_.user_log_callback ||+ (log_options_.user_callback && log_options_.user_callback_active);+ if (!log_stream && !use_log_callback)
return;
// highsLogUser should not be passed HighsLogType::kDetailed or
// HighsLogType::kVerbose
@@ -107,11 +113,8 @@ void highsLogUser(const HighsLogOptions& log_options_, const HighsLogType type,
va_list argptr;
va_start(argptr, format);
const bool flush_streams = true;
- const bool use_log_callback =- log_options_.user_log_callback ||- (log_options_.user_callback && log_options_.user_callback_active);- if (!use_log_callback) {+ if (log_stream) {
// Write to log file stream unless it is NULL
if (log_options_.log_stream) {
if (prefix)
@@ -127,7 +130,8 @@ void highsLogUser(const HighsLogOptions& log_options_, const HighsLogType type,
vfprintf(stdout, format, argptr);
if (flush_streams) fflush(stdout);
}
- } else {+ }+ if (use_log_callback) {
size_t len = 0;
std::array<char, kIoBufferSize> msgbuffer = {};
if (prefix) {
The above was done with current git master, which is v1.9.0-1-gbdf95f2e0
The text was updated successfully, but these errors were encountered:
Thanks for flagging this up. I'll look at it in due course. All the "H" characters you see are due to a unit test for the original logging callback that is deprecated, and activated if log_options_.user_log_callback is true
Hi there,
I am using HiGHS as a library and I am trying to integrate it into the existing logging framework via
setCallback()
, but the callback is never called unless I also set a log file and enable the output flag (for which I found no documentation).Reproducer:
The
without file
test fails, thewith file
test passes. Thewith file
test creates a log file, but it is empty.I am not quite sure how this is supposed to work, but I would suggest something like the following. This makes my new tests pass and the log output also appears in the log file. Note that this change makes
unit_tests
print lots ofH
s to the console, so... something is off, I guess?The above was done with current git master, which is
v1.9.0-1-gbdf95f2e0
The text was updated successfully, but these errors were encountered: