-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
logsink: fix multiple issues with LogSink::ToString() #852
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #852 +/- ##
==========================================
+ Coverage 73.17% 73.21% +0.04%
==========================================
Files 17 17
Lines 3277 3282 +5
==========================================
+ Hits 2398 2403 +5
Misses 879 879
|
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.
Thank you for the PR. Looks mostly good to me. However, it would be great if you can clarify why write
is expected to be defined as a macro by MSVC. I'm not confident this is actually right.
src/logging.cc
Outdated
#ifdef _MSC_VER | ||
#pragma push_macro("write") | ||
#undef write | ||
#endif // _MSC_VER |
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.
Can you elaborate why this is suddenly necessary? I'm not seeing any warnings issued by Github runners.
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.
The error was
'_write': is not a member of 'std::ostringstream
https://buildkite.com/bazel/google-logging/builds/2869#01829651-f13d-4665-9c42-dfd29c8ac36a
The source of the problem is
src/windows/port.h:87:#define write _write
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.
Thanks. Instead of undefing the macro, you can prevent its expansion by protecting the write
calls as follows:
(stream.write)(message, static_cast<std::streamsize>(message_len));
Please also add a comment for the reason why macro expansion is prevented.
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.
OK, thank you. That would require redefining write
macro with three parameters.
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.
Good point. I missed that.
1. Initializing std::ostringstream with a string makes no sense, as the string becomes an initial value of an underlying buffer; seek-to-end is not performed, so the initial value gets completely overwritten by subsequent writing. 2. Flag `log_year_in_prefix` should be considered, as if formatting a regular logging message. 3. Writing a buffer to std::ostream is better expressed with write(s,n).
Initializing
std::ostringstream
with a string makes no sense, as the string becomes an initial value of an underlying buffer; seek-to-end is not performed, so the initial value gets completely overwritten by subsequent writing.Flag
log_year_in_prefix
should be considered, as if formatting a regular logging message.Writing a buffer to
std::ostream
is better expressed withstream.write(s,n)
.