本文整理汇总了Golang中github.com/qiniu/log.Infof函数的典型用法代码示例。如果您正苦于以下问题:Golang Infof函数的具体用法?Golang Infof怎么用?Golang Infof使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Infof函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Read
func (s *server) Read(ctx context.Context, req *pb.ReadRequest) (*pb.ReadReply, error) {
dn, fn, err := splitDiskAndFile(req.Name)
if err != nil {
log.Infof("server: read error (%v)", err)
return &pb.ReadReply{}, nil
}
d := s.Disk(dn)
if d == nil {
log.Infof("server: read error (cannot find disk %s)", dn)
return &pb.ReadReply{}, nil
}
stats.Counter("cfs_read_ops_total").Disk(dn).Add()
// TODO: reuse buffer
data := make([]byte, req.Length)
n, err := d.ReadAt(fn, data, req.Offset)
// TODO: add error
if err != nil {
log.Infof("server: read error (%v)", err)
return &pb.ReadReply{}, nil
}
reply := &pb.ReadReply{BytesRead: int64(n), Data: data}
return reply, nil
}
示例2: ReadDir
func (s *server) ReadDir(ctx context.Context, req *pb.ReadDirRequest) (*pb.ReadDirReply, error) {
reply := &pb.ReadDirReply{}
dn, fn, err := splitDiskAndFile(req.Name)
if err != nil {
log.Infof("server: readDir error (%v)", err)
return reply, nil
}
d := s.Disk(dn)
if d == nil {
log.Infof("server: readDir error (cannot find disk %s)", dn)
return reply, nil
}
stats.Counter("cfs_readdir_ops_total").Disk(dn).Add()
stats, err := d.ReadDir(fn)
if err != nil {
log.Infof("server: readDir error (%v)", err)
return reply, nil
}
reply.FileInfos = make([]*pb.FileInfo, len(stats))
for i, stat := range stats {
reply.FileInfos[i] = &pb.FileInfo{
Name: stat.Name(),
// TODO: Add size
TotalSize: stat.Size(),
IsDir: stat.IsDir(),
}
}
return reply, nil
}
示例3: Read
func (s *server) Read(ctx context.Context, req *pb.ReadRequest) (*pb.ReadReply, error) {
if !enforce.HasQuota(req.Header.ClientID) {
log.Infof("server: out of quota for client %d", req.Header.ClientID)
return &pb.ReadReply{}, nil
}
dn, fn, err := splitDiskAndFile(req.Name)
if err != nil {
log.Infof("server: read error (%v)", err)
return &pb.ReadReply{}, nil
}
d := s.Disk(dn)
if d == nil {
log.Infof("server: read error (cannot find disk %s)", dn)
return &pb.ReadReply{}, nil
}
stats.Counter(dn, "read").Client(req.Header.ClientID).Add()
// TODO: reuse buffer
data := make([]byte, req.Length)
n, err := d.ReadAt(fn, data, req.Offset)
// TODO: add error
if err == io.EOF {
log.Infof("server: read %d bytes until EOF", n)
return &pb.ReadReply{BytesRead: int64(n), Data: data[:n]}, nil
}
if err != nil {
log.Infof("server: read error (%v)", err)
return &pb.ReadReply{}, nil
}
reply := &pb.ReadReply{BytesRead: int64(n), Data: data}
return reply, nil
}
示例4: Write
func (s *server) Write(ctx context.Context, req *pb.WriteRequest) (*pb.WriteReply, error) {
if !enforce.HasQuota(req.Header.ClientID) {
log.Infof("server: out of quota for client %d", req.Header.ClientID)
return &pb.WriteReply{}, nil
}
dn, fn, err := splitDiskAndFile(req.Name)
if err != nil {
log.Infof("server: write error (%v)", err)
return &pb.WriteReply{}, nil
}
d := s.Disk(dn)
if d == nil {
log.Infof("server: write error (cannot find disk %s)", dn)
return &pb.WriteReply{}, nil
}
stats.Counter(dn, "write").Client(req.Header.ClientID).Add()
n, err := d.WriteAt(fn, req.Data, req.Offset)
// TODO: add error
if err != nil {
log.Infof("server: write error (%v)", err)
return &pb.WriteReply{}, nil
}
reply := &pb.WriteReply{BytesWritten: int64(n)}
return reply, nil
}
示例5: Mkdir
func (s *server) Mkdir(ctx context.Context, req *pb.MkdirRequest) (*pb.MkdirReply, error) {
reply := &pb.MkdirReply{}
if !enforce.HasQuota(req.Header.ClientID) {
log.Infof("server: out of quota for client %d", req.Header.ClientID)
return reply, nil
}
dn, fn, err := splitDiskAndFile(req.Name)
if err != nil {
log.Infof("server: mkdir error (%v)", err)
return reply, nil
}
d := s.Disk(dn)
if d == nil {
log.Infof("server: mkdir error (cannot find disk %s)", dn)
return reply, nil
}
stats.Counter(dn, "mkdir").Client(req.Header.ClientID).Add()
err = d.Mkdir(fn, req.All)
if err != nil {
log.Infof("server: mkdir error (%v)", err)
return reply, nil
}
return reply, nil
}
示例6: main
func main() {
configfn := "nameserver.conf"
data, err := ioutil.ReadFile(configfn)
if err != nil {
log.Fatalf("server: cannot load configuration file[%s] (%v)", configfn, err)
}
var conf config.Server
if _, err := toml.Decode(string(data), &conf); err != nil {
log.Fatalf("server: configuration file[%s] is not valid (%v)", configfn, err)
}
server := NewServer()
for i, v := range conf.Disks {
log.Infof("Adding %v to disks", v)
server.registeredDisks = append(server.registeredDisks, &conf.Disks[i])
}
log.Infof("server: starting server...")
lis, err := net.Listen("tcp", net.JoinHostPort(conf.Bind, conf.Port))
if err != nil {
log.Fatalf("server: failed to listen: %v", err)
}
log.Infof("server: listening on %s", net.JoinHostPort(conf.Bind, conf.Port))
s := grpc.NewServer()
pb.RegisterNameServer(s, server)
log.Infof("server: ready to serve clients")
s.Serve(lis)
}
示例7: Rename
func (s *server) Rename(ctx context.Context, req *pb.RenameRequest) (*pb.RenameReply, error) {
dn0, ofn, err := splitDiskAndFile(req.Oldname)
if err != nil {
log.Infof("server: rename error (%v)", err)
return &pb.RenameReply{}, nil
}
dn1, nfn, err := splitDiskAndFile(req.Newname)
if err != nil {
log.Infof("server: rename error (%v)", err)
return &pb.RenameReply{}, nil
}
if dn0 != dn1 {
log.Infof("server: rename error (%v)", "not same disk")
return &pb.RenameReply{}, nil
}
d := s.Disk(dn0)
if d == nil {
log.Infof("server: read error (cannot find disk %s)", dn0)
return &pb.RenameReply{}, nil
}
stats.Counter("cfs_rename_ops_total").Disk(dn0).Add()
err = d.Rename(ofn, nfn)
if err != nil {
log.Infof("server: rename error (%v)", err)
return &pb.RenameReply{}, nil
}
reply := &pb.RenameReply{}
return reply, nil
}
示例8: main
func main() {
configfn := flag.String("config", "default.conf", "location of configuration file")
flag.Parse()
data, err := ioutil.ReadFile(*configfn)
if err != nil {
log.Fatalf("server: cannot load configuration file[%s] (%v)", *configfn, err)
}
var conf config.Server
if _, err := toml.Decode(string(data), &conf); err != nil {
log.Fatalf("server: configuration file[%s] is not valid (%v)", *configfn, err)
}
// default is that cfs is bootstrapped using docker
cname, err := detectDockerContainer()
if err != nil {
log.Printf("server: failed to detect docker container (%v)", err)
} else {
stats.SetContainerName(cname)
log.Printf("server: detect docker container %q", cname)
}
log.Infof("server: starting server...")
lis, err := net.Listen("tcp", net.JoinHostPort(conf.Bind, conf.Port))
if err != nil {
log.Fatalf("server: failed to listen: %v", err)
}
log.Infof("server: listening on %s", net.JoinHostPort(conf.Bind, conf.Port))
cfs := NewServer()
for _, d := range conf.Disks {
err = cfs.AddDisk(d.Name, d.Root)
if err != nil {
log.Fatalf("server: failed to add disk (%v)", err)
}
}
// 0x1234 is the client ID for cfsctl, and its quota is 10 req/sec.
enforce.SetQuota(0x1234, 10)
// TODO report with influxSinker
stats.Report(nil, 3*time.Second)
s := grpc.NewServer()
pb.RegisterCfsServer(s, cfs)
pb.RegisterStatsServer(s, stats.Server())
log.Infof("server: ready to serve clients")
s.Serve(lis)
}
示例9: Start
// Start sync dir, it will loop until the Stop is called
func (s *Syncer) Start() {
log.Infof("Start sync %v/%s", s.dir, s.matchPattern)
for {
if err := s.sync(); err != nil && !os.IsNotExist(err) {
log.Errorf("Sync %s failed - %v", s.dir, err)
}
select {
case <-s.endch:
log.Infof("Stop sync %v/%s", s.dir, s.matchPattern)
return
default:
}
time.Sleep(time.Second * time.Duration(s.IntervalSecond))
}
}
示例10: initContainerManager
func initContainerManager() {
sysFs, err := sysfs.NewRealSysFs()
if err != nil {
log.Infof("stats: failed to create a system interface (%v)", err)
return
}
// TODO: support influxdb or other backend storage
cmgr, err = manager.New(memory.New(storageDuration, nil), sysFs)
if err != nil {
log.Infof("stats: failed to create a container Manager (%v)", err)
return
}
if err := cmgr.Start(); err != nil {
log.Infof("stats: failed to start container manager (%v)", err)
return
}
}
示例11: handleRename
func handleRename(ctx context.Context, c *client.Client) error {
err := c.Rename(ctx, renameOld, renameNew)
if err != nil {
log.Fatalf("Rename err (%v)", err)
}
log.Infof("rename %s into %s", renameOld, renameNew)
return nil
}
示例12: handleWrite
func handleWrite(ctx context.Context, c *client.Client) error {
n, err := c.Write(ctx, writeName, writeOffset, []byte(writeData), writeAppend)
if err != nil {
log.Fatalf("Write err (%v)", err)
}
log.Infof("%d bytes written to %s at offset %d", n, writeName, writeOffset)
return nil
}
示例13: buildCommand
// FIXME(ssx): maybe need to return error
func (p *Process) buildCommand() *kexec.KCommand {
cmd := kexec.CommandString(p.Command)
// cmd := kexec.Command(p.Command[0], p.Command[1:]...)
logDir := filepath.Join(defaultConfigDir, "log", sanitize.Name(p.Name))
if !IsDir(logDir) {
os.MkdirAll(logDir, 0755)
}
var fout io.Writer
var err error
p.OutputFile, err = os.OpenFile(filepath.Join(logDir, "output.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
log.Warn("create stdout log failed:", err)
fout = ioutil.Discard
} else {
fout = p.OutputFile
}
cmd.Stdout = io.MultiWriter(p.Stdout, p.Output, fout)
cmd.Stderr = io.MultiWriter(p.Stderr, p.Output, fout)
// config environ
cmd.Env = os.Environ() // inherit current vars
environ := map[string]string{}
if p.User != "" {
err := cmd.SetUser(p.User)
if err != nil {
log.Warnf("[%s] chusr to %s failed", p.Name, p.User)
} else {
var homeDir string
switch runtime.GOOS {
case "linux":
homeDir = "/home/" + p.User // FIXME(ssx): maybe there is a better way
case "darwin":
homeDir = "/Users/" + p.User
}
cmd.Env = append(cmd.Env, "HOME="+homeDir, "USER="+p.User)
environ["HOME"] = homeDir
environ["USER"] = p.User
}
}
cmd.Env = append(cmd.Env, p.Environ...)
mapping := func(key string) string {
val := os.Getenv(key)
if val != "" {
return val
}
return environ[key]
}
cmd.Dir = os.Expand(p.Dir, mapping)
if strings.HasPrefix(cmd.Dir, "~") {
cmd.Dir = mapping("HOME") + cmd.Dir[1:]
}
log.Infof("[%s] use dir: %s\n", p.Name, cmd.Dir)
return cmd
}
示例14: Rename
func (s *server) Rename(ctx context.Context, req *pb.RenameRequest) (*pb.RenameReply, error) {
if !enforce.HasQuota(req.Header.ClientID) {
log.Infof("server: out of quota for client %d", req.Header.ClientID)
return &pb.RenameReply{}, nil
}
dn0, ofn, err := splitDiskAndFile(req.Oldname)
if err != nil {
log.Infof("server: rename error (%v)", err)
return &pb.RenameReply{}, nil
}
dn1, nfn, err := splitDiskAndFile(req.Newname)
if err != nil {
log.Infof("server: rename error (%v)", err)
return &pb.RenameReply{}, nil
}
if dn0 != dn1 {
log.Infof("server: rename error (%v)", "not same disk")
return &pb.RenameReply{}, nil
}
d := s.Disk(dn0)
if d == nil {
log.Infof("server: read error (cannot find disk %s)", dn0)
return &pb.RenameReply{}, nil
}
stats.Counter(dn0, "rename").Client(req.Header.ClientID).Add()
err = d.Rename(ofn, nfn)
if err != nil {
log.Infof("server: rename error (%v)", err)
return &pb.RenameReply{}, nil
}
reply := &pb.RenameReply{}
return reply, nil
}
示例15: Mkdir
func (s *server) Mkdir(ctx context.Context, req *pb.MkdirRequest) (*pb.MkdirReply, error) {
reply := &pb.MkdirReply{}
dn, fn, err := splitDiskAndFile(req.Name)
if err != nil {
log.Infof("server: mkdir error (%v)", err)
return reply, nil
}
d := s.Disk(dn)
if d == nil {
log.Infof("server: mkdir error (cannot find disk %s)", dn)
return reply, nil
}
stats.Counter("cfs_mkdir_ops_total").Disk(dn).Add()
err = d.Mkdir(fn, req.All)
if err != nil {
log.Infof("server: mkdir error (%v)", err)
return reply, nil
}
return reply, nil
}