From eff14d6532ba5ef5bfceb7c9269252bc34f063f1 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 16 Nov 2020 22:28:09 -0800 Subject: [PATCH] trying logrus --- go.sum | 1 + pkg/driver/controllerserver.go | 14 +++++++------- pkg/driver/driver.go | 8 ++++---- pkg/driver/identityserver.go | 4 ++-- pkg/driver/mount_util.go | 12 ++++++------ pkg/driver/mounter.go | 12 ++++++------ pkg/driver/mounter_seaweedfs.go | 6 +++--- pkg/driver/nodeserver.go | 10 +++++----- pkg/driver/server.go | 10 +++++----- pkg/driver/utils.go | 8 ++++---- 10 files changed, 43 insertions(+), 42 deletions(-) diff --git a/go.sum b/go.sum index 358700b..7c85f5f 100644 --- a/go.sum +++ b/go.sum @@ -171,6 +171,7 @@ github.com/chrislusf/seaweedfs v0.0.0-20200724171345-d40de39e7556 h1:N4he/kL8zRq github.com/chrislusf/seaweedfs v0.0.0-20200724171345-d40de39e7556/go.mod h1:VSpNjD5Q751xYkxwW8tlkpgNuqVx4AK5m1XZH3Ie/7Y= github.com/chrislusf/seaweedfs v0.0.0-20201012192625-f022aff289d5 h1:QS9gachXA5Md4WBWlAbvbdVaxMTL/9ZSgv8pqdNkn2s= github.com/chrislusf/seaweedfs v0.0.0-20201012192625-f022aff289d5/go.mod h1:Tj0ISSpp9TNYaCGFw8qDmuQuhsOS/j3mbBj4Yd/UXJc= +github.com/chrislusf/seaweedfs v0.0.0-20201117035708-9add554feb53 h1:ucfzNGokLenvuhjbPap7vMQMFi5jJHgYggxU47NQ8Uk= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= diff --git a/pkg/driver/controllerserver.go b/pkg/driver/controllerserver.go index 3ca456c..95aadf2 100644 --- a/pkg/driver/controllerserver.go +++ b/pkg/driver/controllerserver.go @@ -8,7 +8,7 @@ import ( "io" "strings" - "github.com/chrislusf/seaweedfs/weed/glog" + "github.com/chrislusf/seaweedfs/weed/util/log" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/container-storage-interface/spec/lib/go/csi" "google.golang.org/grpc/codes" @@ -26,7 +26,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol volumeId := sanitizeVolumeId(req.GetName()) if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME); err != nil { - glog.V(3).Infof("invalid create volume req: %v", req) + log.Tracef("invalid create volume req: %v", req) return nil, err } @@ -39,7 +39,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol } params := req.GetParameters() - glog.V(4).Info("params:%v", params) + log.Trace("params:%v", params) capacity := req.GetCapacityRange().GetRequiredBytes() capacityGB := capacity >> 30 if capacityGB == 0 { @@ -54,7 +54,7 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol return nil, fmt.Errorf("Error setting bucket metadata: %v", err) } - glog.V(4).Infof("create volume %s", volumeId) + log.Tracef("create volume %s", volumeId) return &csi.CreateVolumeResponse{ Volume: &csi.Volume{ @@ -75,10 +75,10 @@ func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol } if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME); err != nil { - glog.V(3).Infof("Invalid delete volume req: %v", req) + log.Tracef("Invalid delete volume req: %v", req) return nil, err } - glog.V(4).Infof("Deleting volume %s", volumeId) + log.Tracef("Deleting volume %s", volumeId) if err := filer_pb.Remove(cs.Driver, "/buckets", volumeId, true, true, true, false, nil); err != nil { return nil, fmt.Errorf("Error setting bucket metadata: %v", err) @@ -151,7 +151,7 @@ func (cs *ControllerServer) GetCapacity(ctx context.Context, req *csi.GetCapacit // ControllerGetCapabilities implements the default GRPC callout. // Default supports all capabilities func (cs *ControllerServer) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) { - glog.V(3).Infof("Using default ControllerGetCapabilities") + log.Tracef("Using default ControllerGetCapabilities") return &csi.ControllerGetCapabilitiesResponse{ Capabilities: cs.Driver.cscap, diff --git a/pkg/driver/driver.go b/pkg/driver/driver.go index 4e3b808..9415c8c 100644 --- a/pkg/driver/driver.go +++ b/pkg/driver/driver.go @@ -9,7 +9,7 @@ import ( "github.com/chrislusf/seaweedfs/weed/security" "github.com/chrislusf/seaweedfs/weed/util" "github.com/container-storage-interface/spec/lib/go/csi" - "github.com/chrislusf/seaweedfs/weed/glog" + "github.com/chrislusf/seaweedfs/weed/util/log" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -41,7 +41,7 @@ type SeaweedFsDriver struct { func NewSeaweedFsDriver(filer, nodeID, endpoint string) *SeaweedFsDriver { - glog.Infof("Driver: %v version: %v", driverName, version) + log.Infof("Driver: %v version: %v", driverName, version) n := &SeaweedFsDriver{ endpoint: endpoint, @@ -87,7 +87,7 @@ func (n *SeaweedFsDriver) Run() { func (n *SeaweedFsDriver) AddVolumeCapabilityAccessModes(vc []csi.VolumeCapability_AccessMode_Mode) []*csi.VolumeCapability_AccessMode { var vca []*csi.VolumeCapability_AccessMode for _, c := range vc { - glog.Infof("Enabling volume access mode: %v", c.String()) + log.Infof("Enabling volume access mode: %v", c.String()) vca = append(vca, &csi.VolumeCapability_AccessMode{Mode: c}) } n.vcap = vca @@ -98,7 +98,7 @@ func (n *SeaweedFsDriver) AddControllerServiceCapabilities(cl []csi.ControllerSe var csc []*csi.ControllerServiceCapability for _, c := range cl { - glog.Infof("Enabling controller service capability: %v", c.String()) + log.Infof("Enabling controller service capability: %v", c.String()) csc = append(csc, NewControllerServiceCapability(c)) } diff --git a/pkg/driver/identityserver.go b/pkg/driver/identityserver.go index 7d0fab7..ce492b6 100644 --- a/pkg/driver/identityserver.go +++ b/pkg/driver/identityserver.go @@ -2,7 +2,7 @@ package driver import ( "github.com/container-storage-interface/spec/lib/go/csi" - "github.com/chrislusf/seaweedfs/weed/glog" + "github.com/chrislusf/seaweedfs/weed/util/log" "golang.org/x/net/context" ) @@ -25,7 +25,7 @@ func (ids *IdentityServer) Probe(ctx context.Context, req *csi.ProbeRequest) (*c } func (ids *IdentityServer) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) { - glog.V(4).Infof("Using default capabilities") + log.Tracef("Using default capabilities") return &csi.GetPluginCapabilitiesResponse{ Capabilities: []*csi.PluginCapability{ { diff --git a/pkg/driver/mount_util.go b/pkg/driver/mount_util.go index 2f45597..718577a 100644 --- a/pkg/driver/mount_util.go +++ b/pkg/driver/mount_util.go @@ -10,7 +10,7 @@ import ( "time" "github.com/mitchellh/go-ps" - "github.com/chrislusf/seaweedfs/weed/glog" + "github.com/chrislusf/seaweedfs/weed/util/log" "k8s.io/utils/mount" ) @@ -20,7 +20,7 @@ func waitForProcess(p *os.Process, backoff int) error { } cmdLine, err := getCmdLine(p.Pid) if err != nil { - glog.Warningf("Error checking cmdline of PID %v, assuming it is dead: %s", p.Pid, err) + log.Warnf("Error checking cmdline of PID %v, assuming it is dead: %s", p.Pid, err) return nil } if cmdLine == "" { @@ -31,10 +31,10 @@ func waitForProcess(p *os.Process, backoff int) error { return nil } if err := p.Signal(syscall.Signal(0)); err != nil { - glog.Warningf("Fuse process does not seem active or we are unprivileged: %s", err) + log.Warnf("Fuse process does not seem active or we are unprivileged: %s", err) return nil } - glog.Infof("Fuse process with PID %v still active, waiting...", p.Pid) + log.Infof("Fuse process with PID %v still active, waiting...", p.Pid) time.Sleep(time.Duration(backoff*100) * time.Millisecond) return waitForProcess(p, backoff+1) } @@ -66,11 +66,11 @@ func findFuseMountProcess(path string) (*os.Process, error) { for _, p := range processes { cmdLine, err := getCmdLine(p.Pid()) if err != nil { - glog.Errorf("Unable to get cmdline of PID %v: %s", p.Pid(), err) + log.Errorf("Unable to get cmdline of PID %v: %s", p.Pid(), err) continue } if strings.Contains(cmdLine, path) { - glog.Infof("Found matching pid %v on path %s", p.Pid(), path) + log.Infof("Found matching pid %v on path %s", p.Pid(), path) return os.FindProcess(p.Pid()) } } diff --git a/pkg/driver/mounter.go b/pkg/driver/mounter.go index f18fa3c..7c7a492 100644 --- a/pkg/driver/mounter.go +++ b/pkg/driver/mounter.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/chrislusf/seaweedfs/weed/glog" + "github.com/chrislusf/seaweedfs/weed/util/log" "os/exec" "k8s.io/utils/mount" ) @@ -25,11 +25,11 @@ func newMounter(bucketName string, filer string) (Mounter, error) { func fuseMount(path string, command string, args []string) error { cmd := exec.Command(command, args...) - glog.V(0).Infof("Mounting fuse with command: %s and args: %s", command, args) + log.Infof("Mounting fuse with command: %s and args: %s", command, args) err := cmd.Start() if err != nil { - glog.Errorf("running weed mount: %v", err) + log.Errorf("running weed mount: %v", err) return fmt.Errorf("Error fuseMount command: %s\nargs: %s\nerror: %v", command, args, err) } @@ -43,14 +43,14 @@ func fuseUnmount(path string) error { // as fuse quits immediately, we will try to wait until the process is done process, err := findFuseMountProcess(path) if err != nil { - glog.Errorf("Error getting PID of fuse mount: %s", err) + log.Errorf("Error getting PID of fuse mount: %s", err) return nil } if process == nil { - glog.Warningf("Unable to find PID of fuse mount %s, it must have finished already", path) + log.Warnf("Unable to find PID of fuse mount %s, it must have finished already", path) return nil } - glog.Infof("Found fuse pid %v of mount %s, checking if it still runs", process.Pid, path) + log.Infof("Found fuse pid %v of mount %s, checking if it still runs", process.Pid, path) return waitForProcess(process, 1) } diff --git a/pkg/driver/mounter_seaweedfs.go b/pkg/driver/mounter_seaweedfs.go index edd3c9d..a8f7957 100644 --- a/pkg/driver/mounter_seaweedfs.go +++ b/pkg/driver/mounter_seaweedfs.go @@ -3,7 +3,7 @@ package driver import ( "fmt" - "github.com/chrislusf/seaweedfs/weed/glog" + "github.com/chrislusf/seaweedfs/weed/util/log" ) // Implements Mounter @@ -24,7 +24,7 @@ func newSeaweedFsMounter(bucketName string, filer string) (Mounter, error) { } func (seaweedFs *seaweedFsMounter) Mount(target string) error { - glog.V(0).Infof("mounting %s%s to %s", seaweedFs.filerUrl, seaweedFs.bucketName, target) + log.Infof("mounting %s%s to %s", seaweedFs.filerUrl, seaweedFs.bucketName, target) args := []string{ "mount", @@ -37,7 +37,7 @@ func (seaweedFs *seaweedFsMounter) Mount(target string) error { } err := fuseMount(target, seaweedFsCmd, args) if err != nil { - glog.Errorf("mount %s%s to %s: %s", seaweedFs.filerUrl, seaweedFs.bucketName, target, err) + log.Errorf("mount %s%s to %s: %s", seaweedFs.filerUrl, seaweedFs.bucketName, target, err) } return err } diff --git a/pkg/driver/nodeserver.go b/pkg/driver/nodeserver.go index 82e1aed..9f84570 100644 --- a/pkg/driver/nodeserver.go +++ b/pkg/driver/nodeserver.go @@ -5,7 +5,7 @@ import ( "os" "strings" - "github.com/chrislusf/seaweedfs/weed/glog" + "github.com/chrislusf/seaweedfs/weed/util/log" "github.com/container-storage-interface/spec/lib/go/csi" "google.golang.org/grpc/codes" @@ -25,7 +25,7 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis // mount the fs here targetPath := req.GetTargetPath() - glog.V(0).Infof("NodePublishVolume volume %s to %s", volumeID, targetPath) + log.Infof("NodePublishVolume volume %s to %s", volumeID, targetPath) // Check arguments if req.GetVolumeCapability() == nil { @@ -69,7 +69,7 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis return nil, status.Error(codes.Internal, err.Error()) } - glog.V(0).Infof("volume %s successfully mounted to %s", volumeID, targetPath) + log.Infof("volume %s successfully mounted to %s", volumeID, targetPath) return &csi.NodePublishVolumeResponse{}, nil } @@ -95,7 +95,7 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu } func (ns *NodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) { - glog.V(3).Infof("Using default NodeGetInfo: nodeID %s", ns.Driver.nodeID) + log.Tracef("Using default NodeGetInfo: nodeID %s", ns.Driver.nodeID) return &csi.NodeGetInfoResponse{ NodeId: ns.Driver.nodeID, @@ -103,7 +103,7 @@ func (ns *NodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoReque } func (ns *NodeServer) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) { - glog.V(3).Infof("Using default NodeGetCapabilities") + log.Tracef("Using default NodeGetCapabilities") return &csi.NodeGetCapabilitiesResponse{ Capabilities: []*csi.NodeServiceCapability{ diff --git a/pkg/driver/server.go b/pkg/driver/server.go index 7e22079..21810d1 100644 --- a/pkg/driver/server.go +++ b/pkg/driver/server.go @@ -5,7 +5,7 @@ import ( "os" "sync" - "github.com/chrislusf/seaweedfs/weed/glog" + "github.com/chrislusf/seaweedfs/weed/util/log" "google.golang.org/grpc" "github.com/container-storage-interface/spec/lib/go/csi" @@ -58,19 +58,19 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, c proto, addr, err := ParseEndpoint(endpoint) if err != nil { - glog.Fatal(err.Error()) + log.Fatal(err.Error()) } if proto == "unix" { addr = "/" + addr if err := os.Remove(addr); err != nil && !os.IsNotExist(err) { - glog.Fatalf("Failed to remove %s, error: %s", addr, err.Error()) + log.Fatalf("Failed to remove %s, error: %s", addr, err.Error()) } } listener, err := net.Listen(proto, addr) if err != nil { - glog.Fatalf("Failed to listen: %v", err) + log.Fatalf("Failed to listen: %v", err) } opts := []grpc.ServerOption{ @@ -89,7 +89,7 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, c csi.RegisterNodeServer(server, ns) } - glog.Infof("Listening for connections on address: %#v", listener.Addr()) + log.Infof("Listening for connections on address: %#v", listener.Addr()) server.Serve(listener) diff --git a/pkg/driver/utils.go b/pkg/driver/utils.go index b783f99..f75c684 100644 --- a/pkg/driver/utils.go +++ b/pkg/driver/utils.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/container-storage-interface/spec/lib/go/csi" - "github.com/chrislusf/seaweedfs/weed/glog" + "github.com/chrislusf/seaweedfs/weed/util/log" "golang.org/x/net/context" "google.golang.org/grpc" ) @@ -50,11 +50,11 @@ func ParseEndpoint(ep string) (string, string, error) { } func logGRPC(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - glog.V(3).Infof("GRPC %s request %+v", info.FullMethod, req) + log.Tracef("GRPC %s request %+v", info.FullMethod, req) resp, err := handler(ctx, req) if err != nil { - glog.Errorf("GRPC error: %v", err) + log.Errorf("GRPC error: %v", err) } - glog.V(3).Infof("GRPC %s response %+v", info.FullMethod, resp) + log.Tracef("GRPC %s response %+v", info.FullMethod, resp) return resp, err }