summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--absl/log/internal/globals.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/absl/log/internal/globals.cc b/absl/log/internal/globals.cc
index 863b047f..9ba997d5 100644
--- a/absl/log/internal/globals.cc
+++ b/absl/log/internal/globals.cc
@@ -16,6 +16,9 @@
#include <atomic>
#include <cstdio>
+#if defined(__EMSCRIPTEN__)
+#include <emscripten/console.h>
+#endif
#include "absl/base/attributes.h"
#include "absl/base/config.h"
@@ -55,9 +58,21 @@ void SetInitialized() {
}
void WriteToStderr(absl::string_view message, absl::LogSeverity severity) {
+#if defined(__EMSCRIPTEN__)
+ // In WebAssembly, bypass filesystem emulation via fwrite.
+ // TODO(b/282811932): Avoid this copy if these emscripten functions can
+ // be updated to accept size directly.
+ std::string null_terminated_message(message);
+ if (!null_terminated_message.empty() &&
+ null_terminated_message.back() == '\n') {
+ null_terminated_message.pop_back();
+ }
+ _emscripten_err(null_terminated_message.c_str());
+#else
// Avoid using std::cerr from this module since we may get called during
// exit code, and cerr may be partially or fully destroyed by then.
std::fwrite(message.data(), message.size(), 1, stderr);
+#endif
#if defined(_WIN64) || defined(_WIN32) || defined(_WIN16)
// C99 requires stderr to not be fully-buffered by default (7.19.3.7), but