Skip to content

Commit

Permalink
chore(common): logging with trace log in others
Browse files Browse the repository at this point in the history
with #21965811

Signed-off-by: slasher <[email protected]>
  • Loading branch information
sejust authored and yhjiango committed Mar 18, 2024
1 parent 0c9668d commit d6c9a2c
Show file tree
Hide file tree
Showing 27 changed files with 502 additions and 568 deletions.
24 changes: 4 additions & 20 deletions blockcache/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,26 +154,10 @@ func main() {
os.Exit(1)
}

level := log.Lerror
switch strings.ToLower(logLevel) {
case "debug":
level = log.Ldebug
case "info":
level = log.Linfo
case "warn":
level = log.Lwarn
case "error":
level = log.Lerror
default:
}
log.SetOutputLevel(level)
log.SetOutputLevel(log.ParseLevel(logLevel, log.Lerror))
log.SetOutput(&lumberjack.Logger{
Filename: path.Join(logDir, module, module+".log"),
MaxSize: 1024,
MaxAge: 7,
MaxBackups: 7,
LocalTime: true,
Compress: true,
Filename: path.Join(logDir, module, module+".log"),
MaxSize: 1024, MaxAge: 7, MaxBackups: 7, LocalTime: true, Compress: true,
})

// Init output file
Expand Down Expand Up @@ -231,7 +215,7 @@ func main() {
go func() {
mainMux := http.NewServeMux()
mux := http.NewServeMux()
http.HandleFunc(log.SetLogLevelPath, log.SetLogLevel)
http.HandleFunc(log.ChangeDefaultLevelHandler())
mux.Handle("/debug/pprof", http.HandlerFunc(pprof.Index))
mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
Expand Down
8 changes: 2 additions & 6 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,8 @@ func setupCommands(cfg *cmd.Config) *cobra.Command {
func main() {
log.SetOutputLevel(log.Ldebug)
log.SetOutput(&lumberjack.Logger{
Filename: path.Join(path.Join(os.TempDir(), "cfs"), "cli", "cli.log"),
MaxSize: 128,
MaxAge: 7,
MaxBackups: 7,
LocalTime: true,
Compress: true,
Filename: path.Join(path.Join(os.TempDir(), "cfs"), "cli", "cli.log"),
MaxSize: 128, MaxAge: 7, MaxBackups: 7, LocalTime: true, Compress: true,
})

if err := runCLI(); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions client/fs/dcachev2.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (dc *Dcache) Put(info *proto.DentryInfo) {
element := dc.lruList.PushFront(info)
dc.cache[info.Name] = element
dc.Unlock()
// log.LogDebugf("Dcache put inode: inode(%v)", info.Inode)
// log.Debugf("Dcache put inode: inode(%v)", info.Inode)
}

// Get returns the inode info based on the given inode number.
Expand All @@ -86,7 +86,7 @@ func (dc *Dcache) Get(name string) *proto.DentryInfo {
info := element.Value.(*proto.DentryInfo)
if dentryExpired(info) && DisableMetaCache {
dc.RUnlock()
// log.LogDebugf("Dcache GetConnect expired: now(%v) inode(%v), expired(%d)", time.Now().Format(LogTimeFormat), info.Inode, info.Expiration())
// log.Debugf("Dcache GetConnect expired: now(%v) inode(%v), expired(%d)", time.Now().Format(LogTimeFormat), info.Inode, info.Expiration())
return nil
}
dc.RUnlock()
Expand All @@ -95,7 +95,7 @@ func (dc *Dcache) Get(name string) *proto.DentryInfo {

// Delete deletes the dentry info based on the given name(partentId+name).
func (dc *Dcache) Delete(name string) {
// log.LogDebugf("Dcache Delete: ino(%v)", ino)
// log.Debugf("Dcache Delete: ino(%v)", ino)
dc.Lock()
element, ok := dc.cache[name]
if ok {
Expand Down Expand Up @@ -125,7 +125,7 @@ func (dc *Dcache) evict(foreground bool) {
return
}

// log.LogDebugf("Dcache GetConnect expired: now(%v) inode(%v)", time.Now().Format(LogTimeFormat), info.Inode)
// log.Debugf("Dcache GetConnect expired: now(%v) inode(%v)", time.Now().Format(LogTimeFormat), info.Inode)
dc.lruList.Remove(element)
delete(dc.cache, info.Name)
count++
Expand All @@ -145,7 +145,7 @@ func (dc *Dcache) evict(foreground bool) {
if !dentryExpired(info) {
break
}
// log.LogDebugf("Dcache GetConnect expired: now(%v) inode(%v)", time.Now().Format(LogTimeFormat), info.Inode)
// log.Debugf("Dcache GetConnect expired: now(%v) inode(%v)", time.Now().Format(LogTimeFormat), info.Inode)
dc.lruList.Remove(element)
delete(dc.cache, info.Name)
count++
Expand Down
10 changes: 5 additions & 5 deletions client/fs/icache.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (ic *InodeCache) Put(info *proto.InodeInfo) {
element := ic.lruList.PushFront(info)
ic.cache[info.Inode] = element
ic.Unlock()
// log.LogDebugf("InodeCache put inode: inode(%v)", info.Inode)
// log.Debugf("InodeCache put inode: inode(%v)", info.Inode)
}

// Get returns the inode info based on the given inode number.
Expand All @@ -86,7 +86,7 @@ func (ic *InodeCache) Get(ino uint64) *proto.InodeInfo {
info := element.Value.(*proto.InodeInfo)
if inodeExpired(info) && DisableMetaCache {
ic.RUnlock()
// log.LogDebugf("InodeCache GetConnect expired: now(%v) inode(%v), expired(%d)", time.Now().Format(LogTimeFormat), info.Inode, info.Expiration())
// log.Debugf("InodeCache GetConnect expired: now(%v) inode(%v), expired(%d)", time.Now().Format(LogTimeFormat), info.Inode, info.Expiration())
return nil
}
ic.RUnlock()
Expand All @@ -95,7 +95,7 @@ func (ic *InodeCache) Get(ino uint64) *proto.InodeInfo {

// Delete deletes the inode info based on the given inode number.
func (ic *InodeCache) Delete(ino uint64) {
// log.LogDebugf("InodeCache Delete: ino(%v)", ino)
// log.Debugf("InodeCache Delete: ino(%v)", ino)
ic.Lock()
element, ok := ic.cache[ino]
if ok {
Expand Down Expand Up @@ -125,7 +125,7 @@ func (ic *InodeCache) evict(foreground bool) {
return
}

// log.LogDebugf("InodeCache GetConnect expired: now(%v) inode(%v)", time.Now().Format(LogTimeFormat), info.Inode)
// log.Debugf("InodeCache GetConnect expired: now(%v) inode(%v)", time.Now().Format(LogTimeFormat), info.Inode)
ic.lruList.Remove(element)
delete(ic.cache, info.Inode)
count++
Expand All @@ -145,7 +145,7 @@ func (ic *InodeCache) evict(foreground bool) {
if !inodeExpired(info) {
break
}
// log.LogDebugf("InodeCache GetConnect expired: now(%v) inode(%v)", time.Now().Format(LogTimeFormat), info.Inode)
// log.Debugf("InodeCache GetConnect expired: now(%v) inode(%v)", time.Now().Format(LogTimeFormat), info.Inode)
ic.lruList.Remove(element)
delete(ic.cache, info.Inode)
count++
Expand Down
58 changes: 5 additions & 53 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (

"github.com/cubefs/cubefs/authnode"
"github.com/cubefs/cubefs/blobstore/common/trace"
blog "github.com/cubefs/cubefs/blobstore/util/log"
"github.com/cubefs/cubefs/cmd/common"
"github.com/cubefs/cubefs/console"
"github.com/cubefs/cubefs/datanode"
Expand All @@ -54,8 +53,6 @@ const (
ConfigKeyRole = "role"
ConfigKeyLogDir = "logDir"
ConfigKeyLogLevel = "logLevel"
ConfigKeyLogRotateSize = "logRotateSize"
ConfigKeyLogRotateHeadRoom = "logRotateHeadRoom"
ConfigKeyProfPort = "prof"
ConfigKeyWarnLogDir = "warnLogDir"
ConfigKeyBuffersTotalLimit = "buffersTotalLimit"
Expand Down Expand Up @@ -169,15 +166,13 @@ func main() {
role := cfg.GetString(ConfigKeyRole)
logDir := cfg.GetString(ConfigKeyLogDir)
logLevel := cfg.GetString(ConfigKeyLogLevel)
logRotateSize := cfg.GetInt64(ConfigKeyLogRotateSize)
logRotateHeadRoom := cfg.GetInt64(ConfigKeyLogRotateHeadRoom)
profPort := cfg.GetString(ConfigKeyProfPort)
umpDatadir := cfg.GetString(ConfigKeyWarnLogDir)
buffersTotalLimit := cfg.GetInt64(ConfigKeyBuffersTotalLimit)
logLeftSpaceLimitStr := cfg.GetString(ConfigKeyLogLeftSpaceLimit)
logLeftSpaceLimit, err := strconv.ParseInt(logLeftSpaceLimitStr, 10, 64)
if err != nil || logLeftSpaceLimit == 0 {
log.LogErrorf("logLeftSpaceLimit is not a legal int value: %v", err.Error())
log.Errorf("logLeftSpaceLimit is not a legal int value: %v", err.Error())
logLeftSpaceLimit = log.DefaultLogLeftSpaceLimit
}
// Init server instance with specified role configuration.
Expand Down Expand Up @@ -215,56 +210,17 @@ func main() {
}

// Init logging
var (
level log.Level
blvl blog.Level
)
switch strings.ToLower(logLevel) {
case "debug":
level = log.DebugLevel
blvl = blog.Ldebug
case "info":
level = log.InfoLevel
blvl = blog.Linfo
case "warn":
level = log.WarnLevel
blvl = blog.Lwarn
case "error":
level = log.ErrorLevel
blvl = blog.Lerror
case "critical":
level = log.CriticalLevel
blvl = blog.Lfatal
default:
level = log.ErrorLevel
blvl = blog.Lerror
}
rotate := log.NewLogRotate()
if logRotateSize > 0 {
rotate.SetRotateSizeMb(logRotateSize)
}
if logRotateHeadRoom > 0 {
rotate.SetHeadRoomMb(logRotateHeadRoom)
}
_, err = log.InitLog(logDir, module, level, rotate, logLeftSpaceLimit)
if err != nil {
err = errors.NewErrorf("Fatal: failed to init log - %v", err)
fmt.Println(err)
daemonize.SignalOutcome(err)
os.Exit(1)
}
defer log.LogFlush()
if errors.SupportPanicHook() {
err = errors.AtPanic(func() {
log.LogFlush()
})
if err != nil {
log.LogErrorf("failed to hook go panic")
log.Errorf("failed to hook go panic")
err = nil
}
}
blog.SetOutputLevel(blvl)
blog.SetOutput(&lumberjack.Logger{
log.SetOutputLevel(log.ParseLevel(logLevel, log.Lerror))
log.SetOutput(&lumberjack.Logger{
Filename: path.Join(logDir, module, module+".log"),
MaxSize: 1024,
MaxAge: 7,
Expand Down Expand Up @@ -323,7 +279,6 @@ func main() {
// for multi-cpu scheduling
runtime.GOMAXPROCS(runtime.NumCPU())
if err = ump.InitUmp(role, umpDatadir); err != nil {
log.LogFlush()
err = errors.NewErrorf("Fatal: failed to init ump warnLogDir - %v", err)
syslog.Println(err)
daemonize.SignalOutcome(err)
Expand All @@ -334,7 +289,7 @@ func main() {
go func() {
mainMux := http.NewServeMux()
mux := http.NewServeMux()
http.HandleFunc(log.SetLogLevelPath, log.SetLogLevel)
http.HandleFunc(log.ChangeDefaultLevelHandler())
mux.Handle("/debug/pprof", http.HandlerFunc(pprof.Index))
mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
Expand All @@ -354,7 +309,6 @@ func main() {
mainMux.Handle("/", mainHandler)
e := http.ListenAndServe(fmt.Sprintf(":%v", profPort), mainMux)
if e != nil {
log.LogFlush()
err = errors.NewErrorf("cannot listen pprof %v err %v", profPort, e)
syslog.Println(err)
daemonize.SignalOutcome(err)
Expand All @@ -366,7 +320,6 @@ func main() {
interceptSignal(server)
err = server.Start(cfg)
if err != nil {
log.LogFlush()
err = errors.NewErrorf("Fatal: failed to start the CubeFS %s daemon err %v - ", role, err)
syslog.Println(err)
daemonize.SignalOutcome(err)
Expand All @@ -377,7 +330,6 @@ func main() {
log.LogDisableStderrOutput()
err = log.OutputPid(logDir, role)
if err != nil {
log.LogFlush()
err = errors.NewErrorf("Fatal: failed to print pid %s err %v - ", role, err)
syslog.Println(err)
daemonize.SignalOutcome(err)
Expand Down
4 changes: 2 additions & 2 deletions console/cutil/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func writeResponse(w http.ResponseWriter, code int, value interface{}, err error
}

if _, err := w.Write(responseJSON); err != nil {
log.LogWarnf("write reponse has err:[%s]", err.Error())
log.Warnf("write reponse has err:[%s]", err.Error())
}
}

Expand Down Expand Up @@ -148,7 +148,7 @@ func (h *graphqlProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
w.Header().Set("Content-Type", "application/json")
}
if _, err := w.Write(responseJSON); err != nil {
log.LogWarnf("write reponse has err:[%s]", err.Error())
log.Warnf("write reponse has err:[%s]", err.Error())
}
}

Expand Down
10 changes: 4 additions & 6 deletions console/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (c *ConsoleNode) writeError(err error, writer http.ResponseWriter) {
value = []byte("marshal rep has err")
}
if _, err := writer.Write(value); err != nil {
log.LogErrorf("write has err:[%s]", err.Error())
log.Errorf("write has err:[%s]", err.Error())
}
}

Expand All @@ -106,7 +106,7 @@ func (c ConsoleNode) Shutdown() {

func (c *ConsoleNode) Sync() {
if err := http.ListenAndServe(fmt.Sprintf(":%s", c.listen), c.server); err != nil {
log.LogErrorf("sync console has err:[%s]", err.Error())
log.Errorf("sync console has err:[%s]", err.Error())
}
}

Expand All @@ -123,19 +123,17 @@ func (c *ConsoleNode) loadConfig(cfg *config.Config) (err error) {
if match := regexp.MustCompile("^(\\d)+$").MatchString(c.listen); !match {
return fmt.Errorf("invalid listen configuration:[%s]", c.listen)
}
log.LogInfof("console loadConfig: setup config: %v(%v)", proto.ListenPort, c.listen)
log.Infof("console loadConfig: setup config: %v(%v)", proto.ListenPort, c.listen)

// parse master config
c.masters = cfg.GetStringSlice(proto.MasterAddr)
if len(c.masters) == 0 {
return config.NewIllegalConfigError(proto.MasterAddr)
}
log.LogInfof("loadConfig: setup config: %v(%v)", proto.MasterAddr, strings.Join(c.masters, ","))
log.Infof("loadConfig: setup config: %v(%v)", proto.MasterAddr, strings.Join(c.masters, ","))

c.objectNodeDomain = cfg.GetString(proto.ObjectNodeDomain)

c.server = mux.NewRouter()

return
}

Expand Down
8 changes: 5 additions & 3 deletions console/service/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ type ListFileInfo struct {
func (fs *FileService) listFile(ctx context.Context, args struct {
VolName string
Request ListFilesV1Option
}) (*ListFileInfo, error) {
},
) (*ListFileInfo, error) {
userInfo, _, err := permissions(ctx, USER|ADMIN)
if err != nil {
return nil, err
Expand Down Expand Up @@ -250,7 +251,8 @@ func (fs *FileService) signURL(ctx context.Context, args struct {
VolName string
Path string
ExpireMinutes int64
}) (*proto.GeneralResp, error) {
},
) (*proto.GeneralResp, error) {
if args.Path == "" || args.ExpireMinutes <= 0 || args.VolName == "" {
return nil, fmt.Errorf("param has err")
}
Expand Down Expand Up @@ -465,7 +467,7 @@ func (v volPerm) write() error {
func (fs *FileService) userVolPerm(ctx context.Context, userID string, vol string) volPerm {
userInfo, err := fs.userClient.GetUserInfoForLogin(ctx, userID)
if err != nil {
log.LogErrorf("found user by id:[%s] has err:[%s]", userID, err.Error())
log.Errorf("found user by id:[%s] has err:[%s]", userID, err.Error())
return none
}

Expand Down
8 changes: 4 additions & 4 deletions datanode/data_partition_repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ func (dp *DataPartition) getLocalExtentInfo(extentType uint8, tinyExtents []uint
return
}

func (dp *DataPartition) getRemoteExtentInfo(extentType uint8, tinyExtents []uint64,
target string) (extentFiles []*storage.ExtentInfo, err error) {
func (dp *DataPartition) getRemoteExtentInfo(extentType uint8, tinyExtents []uint64, target string,
) (extentFiles []*storage.ExtentInfo, err error) {
p := repl.NewPacketToGetAllWatermarks(dp.partitionID, extentType)
extentFiles = make([]*storage.ExtentInfo, 0)
if proto.IsTinyExtentType(extentType) {
Expand Down Expand Up @@ -316,7 +316,7 @@ func (dp *DataPartition) prepareRepairTasks(repairTasks []*DataPartitionRepairTa
extentInfoMap[extentID] = extentInfo
}
}
// log.LogInfof("action[prepareRepairTasks] dp %v extentid %v addr[dst %v,leader %v] info %v", dp.partitionID, extentID, repairTask.addr, repairTask.LeaderAddr, extentInfoMap[extentID])
// log.Infof("action[prepareRepairTasks] dp %v extentid %v addr[dst %v,leader %v] info %v", dp.partitionID, extentID, repairTask.addr, repairTask.LeaderAddr, extentInfoMap[extentID])
}
}
for extentID := range deleteExtents {
Expand Down Expand Up @@ -600,7 +600,7 @@ func (dp *DataPartition) streamRepairExtent(remoteExtentInfo *storage.ExtentInfo
log.Debugf("streamRepairExtent reply size %v, currFixoffset %v, reply %v ", reply.Size, currFixOffset, reply)
_, err = store.Write(uint64(localExtentInfo.FileID), int64(currFixOffset), int64(reply.Size), reply.Data, reply.CRC, wType, BufferWrite)
}
// log.LogDebugf("streamRepairExtent reply size %v, currFixoffset %v, reply %v err %v", reply.Size, currFixOffset, reply, err)
// log.Debugf("streamRepairExtent reply size %v, currFixoffset %v, reply %v err %v", reply.Size, currFixOffset, reply, err)
// write to the local extent file
if err != nil {
err = errors.Trace(err, "streamRepairExtent repair data error ")
Expand Down
Loading

0 comments on commit d6c9a2c

Please sign in to comment.