Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2628)

Unified Diff: services/flog/flog_logger_impl.cc

Issue 2084083003: FLOG: Add examples/flog_viewer and always show MOJO_DLOG messages (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/flog/flog_logger_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/flog/flog_logger_impl.cc
diff --git a/services/flog/flog_logger_impl.cc b/services/flog/flog_logger_impl.cc
index 6941e0dc9c6752689176efd29d757c6cf1113326..d870f99c1b73b87ec98f932dc8d092c194bf1574 100644
--- a/services/flog/flog_logger_impl.cc
+++ b/services/flog/flog_logger_impl.cc
@@ -2,12 +2,50 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <iomanip>
+#include <iostream>
+
#include "base/logging.h"
#include "services/flog/flog_logger_impl.h"
namespace mojo {
namespace flog {
+namespace {
+
+struct AsMicroseconds {
+ explicit AsMicroseconds(uint64_t time_us) : time_us_(time_us) {}
+ uint64_t time_us_;
+};
+
+std::ostream& operator<<(std::ostream& os, AsMicroseconds value) {
+ return os << std::setfill('0') << std::setw(6) << value.time_us_ % 1000000ull;
+}
+
+struct AsLogLevel {
+ explicit AsLogLevel(uint32_t level) : level_(level) {}
+ uint32_t level_;
+};
+
+std::ostream& operator<<(std::ostream& os, AsLogLevel value) {
+ switch (value.level_) {
+ case MOJO_LOG_LEVEL_VERBOSE:
+ return os << "VERBOSE";
+ case MOJO_LOG_LEVEL_INFO:
+ return os << "INFO";
+ case MOJO_LOG_LEVEL_WARNING:
+ return os << "WARNING";
+ case MOJO_LOG_LEVEL_ERROR:
+ return os << "ERROR";
+ case MOJO_LOG_LEVEL_FATAL:
+ return os << "FATAL";
+ default:
+ return os << "UNKNOWN LEVEL " << value.level_;
+ }
+}
+
+} // namespace
+
// static
std::shared_ptr<FlogLoggerImpl> FlogLoggerImpl::Create(
InterfaceRequest<FlogLogger> request,
@@ -32,6 +70,7 @@ FlogLoggerImpl::FlogLoggerImpl(InterfaceRequest<FlogLogger> request,
Environment::GetDefaultAsyncWaiter()));
router_->set_incoming_receiver(this);
router_->set_connection_error_handler([this]() { ReleaseFromOwner(); });
+ stub_.set_sink(this);
}
FlogLoggerImpl::~FlogLoggerImpl() {}
@@ -46,6 +85,12 @@ bool FlogLoggerImpl::Accept(Message* message) {
WriteData(sizeof(message_size), &message_size);
WriteData(message_size, message->data());
+ // Call the stub to output mojo logger messages to stderr. This has to
+ // happen after we write the message to the file, because deserialization
+ // mutates the message.
+ // TODO(dalesat): Provide a switch to turn this off.
+ stub_.Accept(message);
+
return true;
}
@@ -70,5 +115,24 @@ void FlogLoggerImpl::WriteData(uint32_t data_size, const void* data) {
});
}
+void FlogLoggerImpl::LogMojoLoggerMessage(int64_t time_us,
+ int32_t log_level,
+ const String& message,
+ const String& source_file,
+ uint32_t source_line) {
+ std::cerr << AsMicroseconds(time_us) << " " << AsLogLevel(log_level) << ":"
+ << source_file << "#" << source_line << " " << message << std::endl;
+}
+
+void FlogLoggerImpl::LogChannelCreation(int64_t time_us,
+ uint32_t channel_id,
+ const String& type_name) {}
+
+void FlogLoggerImpl::LogChannelMessage(int64_t time_us,
+ uint32_t channel_id,
+ mojo::Array<uint8_t> data) {}
+
+void FlogLoggerImpl::LogChannelDeletion(int64_t time_us, uint32_t channel_id) {}
+
} // namespace flog
} // namespace mojo
« no previous file with comments | « services/flog/flog_logger_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698