Skip to content

Commit

Permalink
Add ability to set loglevel
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Hallgren <[email protected]>
  • Loading branch information
thallgren committed May 1, 2023
1 parent a7b2c3a commit 727607c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 25 deletions.
14 changes: 13 additions & 1 deletion pkg/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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()

Expand All @@ -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()
Expand Down
59 changes: 35 additions & 24 deletions rpc/fuseftp.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions rpc/fuseftp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 727607c

Please sign in to comment.