Use Abseil logging for Protobuf v22 and above (fix #16).
This commit is contained in:
parent
b54c65005a
commit
93dc2b1878
1 changed files with 41 additions and 0 deletions
|
|
@ -3,6 +3,10 @@
|
||||||
#include "grpc_log.hpp"
|
#include "grpc_log.hpp"
|
||||||
|
|
||||||
#include <grpc/support/log.h>
|
#include <grpc/support/log.h>
|
||||||
|
#include <google/protobuf/stubs/common.h>
|
||||||
|
|
||||||
|
#if GOOGLE_PROTOBUF_VERSION < 4022000
|
||||||
|
|
||||||
#include <google/protobuf/stubs/logging.h>
|
#include <google/protobuf/stubs/logging.h>
|
||||||
|
|
||||||
class ProtobufLog {
|
class ProtobufLog {
|
||||||
|
|
@ -26,6 +30,43 @@ private:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <absl/log/globals.h>
|
||||||
|
#include <absl/log/initialize.h>
|
||||||
|
#include <absl/log/log_sink_registry.h>
|
||||||
|
|
||||||
|
class ProtobufLog : absl::LogSink {
|
||||||
|
public:
|
||||||
|
ProtobufLog()
|
||||||
|
{
|
||||||
|
absl::InitializeLog();
|
||||||
|
absl::AddLogSink(this);
|
||||||
|
// Disable logging to stderr
|
||||||
|
absl::SetStderrThreshold(static_cast<absl::LogSeverity>(100));
|
||||||
|
}
|
||||||
|
|
||||||
|
~ProtobufLog() override { absl::RemoveLogSink(this); }
|
||||||
|
|
||||||
|
void Send(const absl::LogEntry& entry) override
|
||||||
|
{
|
||||||
|
auto severity = entry.log_severity();
|
||||||
|
|
||||||
|
ngx_uint_t level =
|
||||||
|
severity == absl::LogSeverity::kFatal ? NGX_LOG_EMERG :
|
||||||
|
severity == absl::LogSeverity::kError ? NGX_LOG_ERR :
|
||||||
|
severity == absl::LogSeverity::kWarning ? NGX_LOG_WARN :
|
||||||
|
/*absl::LogSeverity::kInfo*/ NGX_LOG_INFO;
|
||||||
|
|
||||||
|
ngx_str_t message { entry.text_message().size(),
|
||||||
|
(u_char*)entry.text_message().data() };
|
||||||
|
|
||||||
|
ngx_log_error(level, ngx_cycle->log, 0, "OTel/protobuf: %V", &message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
class GrpcLog {
|
class GrpcLog {
|
||||||
public:
|
public:
|
||||||
GrpcLog() { gpr_set_log_function(grpcLogHandler); }
|
GrpcLog() { gpr_set_log_function(grpcLogHandler); }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue