mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-15 22:56:48 +00:00
GODT-1672: Forward QML log to bridge.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -26,10 +26,11 @@ package grpc; // ignored by Go, used as namespace name in C++.
|
||||
|
||||
//**********************************************************************************************************************
|
||||
// Service Declaration
|
||||
//**********************************************************************************************************************
|
||||
//**********************************************************************************************************************≠––
|
||||
service Bridge {
|
||||
|
||||
// App related calls
|
||||
rpc AddLogEntry(AddLogEntryRequest) returns (google.protobuf.Empty);
|
||||
rpc GuiReady (google.protobuf.Empty) returns (google.protobuf.Empty);
|
||||
rpc Quit (google.protobuf.Empty) returns (google.protobuf.Empty);
|
||||
rpc Restart (google.protobuf.Empty) returns (google.protobuf.Empty);
|
||||
@ -103,6 +104,28 @@ service Bridge {
|
||||
// RPC calls requests and replies messages
|
||||
//**********************************************************************************************************************
|
||||
|
||||
//**********************************************************
|
||||
// Log related message
|
||||
//**********************************************************
|
||||
enum LogLevel {
|
||||
PANIC = 0;
|
||||
FATAL = 1;
|
||||
ERROR = 2;
|
||||
WARN = 3;
|
||||
INFO = 4;
|
||||
DEBUG = 5;
|
||||
TRACE = 6;
|
||||
}
|
||||
|
||||
message AddLogEntryRequest {
|
||||
LogLevel level = 1;
|
||||
string package = 2; // package is Go lingo but it identifies the component responsible for the log entry
|
||||
string message = 3;
|
||||
};
|
||||
|
||||
//**********************************************************
|
||||
// Bug reporting related messages.
|
||||
//**********************************************************
|
||||
message ReportBugRequest {
|
||||
string osType = 1;
|
||||
string osVersion = 2;
|
||||
@ -114,6 +137,9 @@ message ReportBugRequest {
|
||||
}
|
||||
|
||||
// login related messages
|
||||
//**********************************************************
|
||||
// Login related messages
|
||||
//**********************************************************
|
||||
|
||||
message LoginRequest {
|
||||
string username = 1;
|
||||
@ -125,7 +151,7 @@ message LoginAbortRequest {
|
||||
}
|
||||
|
||||
//**********************************************************
|
||||
// Cache on disk related messages
|
||||
// Cache on disk related message
|
||||
//**********************************************************
|
||||
message ChangeLocalCacheRequest {
|
||||
bool enableDiskCache = 1;
|
||||
@ -133,7 +159,7 @@ message ChangeLocalCacheRequest {
|
||||
}
|
||||
|
||||
//**********************************************************
|
||||
// Cache on disk related messages
|
||||
// Port related message
|
||||
//**********************************************************
|
||||
message ChangePortsRequest {
|
||||
int32 imapPort = 1;
|
||||
@ -141,7 +167,7 @@ message ChangePortsRequest {
|
||||
}
|
||||
|
||||
//**********************************************************
|
||||
// Cache on disk related messages
|
||||
// Keychain related message
|
||||
//**********************************************************
|
||||
message AvailableKeychainsResponse {
|
||||
repeated string keychains = 1;
|
||||
|
||||
@ -25,6 +25,7 @@ const _ = grpc.SupportPackageIsVersion7
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type BridgeClient interface {
|
||||
// App related calls
|
||||
AddLogEntry(ctx context.Context, in *AddLogEntryRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
|
||||
GuiReady(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error)
|
||||
Quit(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error)
|
||||
Restart(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error)
|
||||
@ -95,6 +96,15 @@ func NewBridgeClient(cc grpc.ClientConnInterface) BridgeClient {
|
||||
return &bridgeClient{cc}
|
||||
}
|
||||
|
||||
func (c *bridgeClient) AddLogEntry(ctx context.Context, in *AddLogEntryRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
|
||||
out := new(emptypb.Empty)
|
||||
err := c.cc.Invoke(ctx, "/grpc.Bridge/AddLogEntry", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *bridgeClient) GuiReady(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error) {
|
||||
out := new(emptypb.Empty)
|
||||
err := c.cc.Invoke(ctx, "/grpc.Bridge/GuiReady", in, out, opts...)
|
||||
@ -600,6 +610,7 @@ func (c *bridgeClient) StopEventStream(ctx context.Context, in *emptypb.Empty, o
|
||||
// for forward compatibility
|
||||
type BridgeServer interface {
|
||||
// App related calls
|
||||
AddLogEntry(context.Context, *AddLogEntryRequest) (*emptypb.Empty, error)
|
||||
GuiReady(context.Context, *emptypb.Empty) (*emptypb.Empty, error)
|
||||
Quit(context.Context, *emptypb.Empty) (*emptypb.Empty, error)
|
||||
Restart(context.Context, *emptypb.Empty) (*emptypb.Empty, error)
|
||||
@ -667,6 +678,9 @@ type BridgeServer interface {
|
||||
type UnimplementedBridgeServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedBridgeServer) AddLogEntry(context.Context, *AddLogEntryRequest) (*emptypb.Empty, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method AddLogEntry not implemented")
|
||||
}
|
||||
func (UnimplementedBridgeServer) GuiReady(context.Context, *emptypb.Empty) (*emptypb.Empty, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GuiReady not implemented")
|
||||
}
|
||||
@ -839,6 +853,24 @@ func RegisterBridgeServer(s grpc.ServiceRegistrar, srv BridgeServer) {
|
||||
s.RegisterService(&Bridge_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _Bridge_AddLogEntry_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AddLogEntryRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(BridgeServer).AddLogEntry(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/grpc.Bridge/AddLogEntry",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(BridgeServer).AddLogEntry(ctx, req.(*AddLogEntryRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _Bridge_GuiReady_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(emptypb.Empty)
|
||||
if err := dec(in); err != nil {
|
||||
@ -1803,6 +1835,10 @@ var Bridge_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "grpc.Bridge",
|
||||
HandlerType: (*BridgeServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "AddLogEntry",
|
||||
Handler: _Bridge_AddLogEntry_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GuiReady",
|
||||
Handler: _Bridge_GuiReady_Handler,
|
||||
|
||||
@ -40,6 +40,32 @@ import (
|
||||
|
||||
var ErrNotImplemented = status.Errorf(codes.Unimplemented, "Not implemented")
|
||||
|
||||
func (s *Service) AddLogEntry(_ context.Context, request *AddLogEntryRequest) (*emptypb.Empty, error) {
|
||||
entry := s.log
|
||||
if len(request.Package) > 0 {
|
||||
entry = entry.WithField("pkg", request.Package)
|
||||
}
|
||||
|
||||
level := logrusLevelFromGrpcLevel(request.Level)
|
||||
|
||||
// we do a special case for Panic and Fatal as using logrus.Entry.Log will not panic nor exit respectively.
|
||||
if level == logrus.PanicLevel {
|
||||
entry.Panic(request.Message)
|
||||
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
||||
if level == logrus.FatalLevel {
|
||||
entry.Fatal(request.Message)
|
||||
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
||||
entry.Log(level, request.Message)
|
||||
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
||||
// GuiReady implement the GuiReady gRPC service call.
|
||||
func (s *Service) GuiReady(context.Context, *emptypb.Empty) (*emptypb.Empty, error) {
|
||||
s.log.Info("GuiReady")
|
||||
|
||||
@ -22,6 +22,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/ProtonMail/proton-bridge/v2/internal/frontend/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -71,3 +72,25 @@ func grpcUserFromBridge(user types.User) *User {
|
||||
Addresses: user.GetAddresses(),
|
||||
}
|
||||
}
|
||||
|
||||
// logrusLevelFromGrpcLevel converts a gRPC log level to a logrus log level.
|
||||
func logrusLevelFromGrpcLevel(level LogLevel) logrus.Level {
|
||||
switch level {
|
||||
case LogLevel_PANIC:
|
||||
return logrus.PanicLevel
|
||||
case LogLevel_FATAL:
|
||||
return logrus.FatalLevel
|
||||
case LogLevel_ERROR:
|
||||
return logrus.ErrorLevel
|
||||
case LogLevel_WARN:
|
||||
return logrus.WarnLevel
|
||||
case LogLevel_INFO:
|
||||
return logrus.InfoLevel
|
||||
case LogLevel_DEBUG:
|
||||
return logrus.DebugLevel
|
||||
case LogLevel_TRACE:
|
||||
return logrus.TraceLevel
|
||||
default:
|
||||
return logrus.ErrorLevel
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user