diff --git a/pkg/main/main.go b/pkg/main/main.go index 7b5bb10..732059c 100644 --- a/pkg/main/main.go +++ b/pkg/main/main.go @@ -12,11 +12,13 @@ import ( "sync" "time" + "github.com/sirupsen/logrus" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/emptypb" + "github.com/datawire/dlib/dlog" "github.com/datawire/go-fuseftp/pkg/fs" "github.com/datawire/go-fuseftp/rpc" ) @@ -52,6 +54,16 @@ func addrPort(ap *rpc.AddressAndPort) (netip.AddrPort, error) { } func (s *service) Mount(_ context.Context, rq *rpc.MountRequest) (*rpc.MountIdentifier, error) { + logger := logrus.New() + if rq.LogLevel != "" { + lvl, err := logrus.ParseLevel(rq.LogLevel) + if err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) + } + logger.SetLevel(lvl) + } + ctx := dlog.WithLogger(s.ctx, dlog.WrapLogrus(logger)) + s.Lock() defer s.Unlock() @@ -65,7 +77,7 @@ func (s *service) Mount(_ context.Context, rq *rpc.MountRequest) (*rpc.MountIden if err != nil { return nil, err } - ctx, cancel := context.WithCancel(s.ctx) + ctx, cancel := context.WithCancel(ctx) fi, err := fs.NewFTPClient(ctx, ap, rq.Directory, rq.ReadTimeout.AsDuration()) if err != nil { cancel() diff --git a/rpc/fuseftp.pb.go b/rpc/fuseftp.pb.go index 5bf1228..aa4e257 100644 --- a/rpc/fuseftp.pb.go +++ b/rpc/fuseftp.pb.go @@ -239,6 +239,8 @@ type MountRequest struct { ReadTimeout *durationpb.Duration `protobuf:"bytes,3,opt,name=read_timeout,json=readTimeout,proto3" json:"read_timeout,omitempty"` // The directory on the FTP server that gets mounted Directory string `protobuf:"bytes,4,opt,name=directory,proto3" json:"directory,omitempty"` + // The logrus log level + LogLevel string `protobuf:"bytes,5,opt,name=log_level,json=logLevel,proto3" json:"log_level,omitempty"` } func (x *MountRequest) Reset() { @@ -301,6 +303,13 @@ func (x *MountRequest) GetDirectory() string { return "" } +func (x *MountRequest) GetLogLevel() string { + if x != nil { + return x.LogLevel + } + return "" +} + var File_rpc_fuseftp_proto protoreflect.FileDescriptor var file_rpc_fuseftp_proto_rawDesc = []byte{ @@ -326,7 +335,7 @@ var file_rpc_fuseftp_proto_rawDesc = []byte{ 0x0a, 0x66, 0x74, 0x70, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x64, 0x61, 0x74, 0x61, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x66, 0x75, 0x73, 0x65, 0x66, 0x74, 0x70, 0x2e, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x41, 0x6e, 0x64, 0x50, - 0x6f, 0x72, 0x74, 0x52, 0x09, 0x66, 0x74, 0x70, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x22, 0xcc, + 0x6f, 0x72, 0x74, 0x52, 0x09, 0x66, 0x74, 0x70, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x22, 0xe9, 0x01, 0x0a, 0x0c, 0x4d, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x50, 0x6f, 0x69, 0x6e, 0x74, @@ -339,29 +348,31 @@ var file_rpc_fuseftp_proto_rawDesc = []byte{ 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x72, 0x65, 0x61, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x79, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x09, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x79, 0x32, 0xac, 0x02, - 0x0a, 0x07, 0x46, 0x75, 0x73, 0x65, 0x46, 0x54, 0x50, 0x12, 0x40, 0x0a, 0x07, 0x56, 0x65, 0x72, - 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1d, 0x2e, 0x64, - 0x61, 0x74, 0x61, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x66, 0x75, 0x73, 0x65, 0x66, 0x74, 0x70, 0x2e, - 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x4a, 0x0a, 0x05, 0x4d, - 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1e, 0x2e, 0x64, 0x61, 0x74, 0x61, 0x77, 0x69, 0x72, 0x65, 0x2e, - 0x66, 0x75, 0x73, 0x65, 0x66, 0x74, 0x70, 0x2e, 0x4d, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x64, 0x61, 0x74, 0x61, 0x77, 0x69, 0x72, 0x65, 0x2e, - 0x66, 0x75, 0x73, 0x65, 0x66, 0x74, 0x70, 0x2e, 0x4d, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x65, - 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x12, 0x44, 0x0a, 0x07, 0x55, 0x6e, 0x6d, 0x6f, 0x75, - 0x6e, 0x74, 0x12, 0x21, 0x2e, 0x64, 0x61, 0x74, 0x61, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x66, 0x75, - 0x73, 0x65, 0x66, 0x74, 0x70, 0x2e, 0x4d, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, - 0x69, 0x66, 0x69, 0x65, 0x72, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x4d, 0x0a, - 0x0c, 0x53, 0x65, 0x74, 0x46, 0x74, 0x70, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x25, 0x2e, - 0x64, 0x61, 0x74, 0x61, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x66, 0x75, 0x73, 0x65, 0x66, 0x74, 0x70, - 0x2e, 0x53, 0x65, 0x74, 0x46, 0x74, 0x70, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x24, 0x5a, 0x22, - 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x61, 0x74, 0x61, 0x77, - 0x69, 0x72, 0x65, 0x2f, 0x67, 0x6f, 0x2d, 0x66, 0x75, 0x73, 0x65, 0x66, 0x74, 0x70, 0x2f, 0x72, - 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x28, 0x09, 0x52, 0x09, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x1b, 0x0a, + 0x09, 0x6c, 0x6f, 0x67, 0x5f, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x08, 0x6c, 0x6f, 0x67, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x32, 0xac, 0x02, 0x0a, 0x07, 0x46, + 0x75, 0x73, 0x65, 0x46, 0x54, 0x50, 0x12, 0x40, 0x0a, 0x07, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, + 0x6e, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x1d, 0x2e, 0x64, 0x61, 0x74, 0x61, + 0x77, 0x69, 0x72, 0x65, 0x2e, 0x66, 0x75, 0x73, 0x65, 0x66, 0x74, 0x70, 0x2e, 0x56, 0x65, 0x72, + 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x4a, 0x0a, 0x05, 0x4d, 0x6f, 0x75, 0x6e, + 0x74, 0x12, 0x1e, 0x2e, 0x64, 0x61, 0x74, 0x61, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x66, 0x75, 0x73, + 0x65, 0x66, 0x74, 0x70, 0x2e, 0x4d, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x21, 0x2e, 0x64, 0x61, 0x74, 0x61, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x66, 0x75, 0x73, + 0x65, 0x66, 0x74, 0x70, 0x2e, 0x4d, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, + 0x66, 0x69, 0x65, 0x72, 0x12, 0x44, 0x0a, 0x07, 0x55, 0x6e, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, + 0x21, 0x2e, 0x64, 0x61, 0x74, 0x61, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x66, 0x75, 0x73, 0x65, 0x66, + 0x74, 0x70, 0x2e, 0x4d, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, + 0x65, 0x72, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x4d, 0x0a, 0x0c, 0x53, 0x65, + 0x74, 0x46, 0x74, 0x70, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x25, 0x2e, 0x64, 0x61, 0x74, + 0x61, 0x77, 0x69, 0x72, 0x65, 0x2e, 0x66, 0x75, 0x73, 0x65, 0x66, 0x74, 0x70, 0x2e, 0x53, 0x65, + 0x74, 0x46, 0x74, 0x70, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x24, 0x5a, 0x22, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x64, 0x61, 0x74, 0x61, 0x77, 0x69, 0x72, 0x65, + 0x2f, 0x67, 0x6f, 0x2d, 0x66, 0x75, 0x73, 0x65, 0x66, 0x74, 0x70, 0x2f, 0x72, 0x70, 0x63, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/rpc/fuseftp.proto b/rpc/fuseftp.proto index 2808b8a..ed3f714 100644 --- a/rpc/fuseftp.proto +++ b/rpc/fuseftp.proto @@ -54,4 +54,7 @@ message MountRequest { // The directory on the FTP server that gets mounted string directory = 4; + + // The logrus log level + string log_level = 5; }