Internal change
PiperOrigin-RevId: 502709070
This commit is contained in:
parent
088249eb36
commit
7894c92ab7
50
mediapipe/util/log_fatal_to_breakpad.cc
Normal file
50
mediapipe/util/log_fatal_to_breakpad.cc
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#include "mediapipe/util/log_fatal_to_breakpad.h"
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
#include "absl/log/log.h"
|
||||||
|
#include "absl/log/log_sink.h"
|
||||||
|
#include "absl/log/log_sink_registry.h"
|
||||||
|
#import "googlemac/iPhone/Shared/GoogleIOSBreakpad/Classes/GoogleBreakpadController.h"
|
||||||
|
|
||||||
|
namespace mediapipe {
|
||||||
|
namespace {
|
||||||
|
NSString* MakeNSString(absl::string_view str) {
|
||||||
|
return [[NSString alloc] initWithBytes:str.data()
|
||||||
|
length:str.length()
|
||||||
|
encoding:NSUTF8StringEncoding];
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
static NSString* const kFatalLogMessageKey = @"fatal_log_message";
|
||||||
|
|
||||||
|
class BreakpadFatalLogSink : public absl::LogSink {
|
||||||
|
public:
|
||||||
|
BreakpadFatalLogSink()
|
||||||
|
: breakpad_controller_([GoogleBreakpadController sharedInstance]) {}
|
||||||
|
void Send(const absl::LogEntry& entry) override {
|
||||||
|
if (entry.log_severity() != absl::LogSeverity::kFatal) return;
|
||||||
|
__block NSString* message = MakeNSString(entry.text_message_with_prefix());
|
||||||
|
[breakpad_controller_ withBreakpadRef:^(BreakpadRef breakpad) {
|
||||||
|
// NOTE: This block runs on Breakpad's background queue.
|
||||||
|
if (!breakpad) return;
|
||||||
|
BreakpadAddUploadParameter(breakpad, kFatalLogMessageKey, message);
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
GoogleBreakpadController* breakpad_controller_;
|
||||||
|
};
|
||||||
|
|
||||||
|
absl::LogSink* GetBreakpadFatalLogSink() {
|
||||||
|
static BreakpadFatalLogSink sink;
|
||||||
|
return &sink;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This log sink is automatically enabled when including this library.
|
||||||
|
static const auto kRegisterLogSink = [] {
|
||||||
|
absl::AddLogSink(GetBreakpadFatalLogSink());
|
||||||
|
return true;
|
||||||
|
}();
|
||||||
|
|
||||||
|
} // namespace mediapipe
|
15
mediapipe/util/log_fatal_to_breakpad.h
Normal file
15
mediapipe/util/log_fatal_to_breakpad.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef MEDIAPIPE_UTIL_LOG_FATAL_TO_BREAKPAD_H_
|
||||||
|
#define MEDIAPIPE_UTIL_LOG_FATAL_TO_BREAKPAD_H_
|
||||||
|
|
||||||
|
#include "absl/log/log_sink.h"
|
||||||
|
|
||||||
|
namespace mediapipe {
|
||||||
|
|
||||||
|
// Returns a singleton instance of a log sink that sends FATAL log messages to
|
||||||
|
// Breakpad. This log sink is enabled by default when this library is included
|
||||||
|
// in your binary.
|
||||||
|
absl::LogSink* GetBreakpadFatalLogSink();
|
||||||
|
|
||||||
|
} // namespace mediapipe
|
||||||
|
|
||||||
|
#endif // MEDIAPIPE_UTIL_LOG_FATAL_TO_BREAKPAD_H_
|
Loading…
Reference in New Issue
Block a user