github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/log/util.go (about)

     1  /* For license and copyright information please see LEGAL file in repository */
     2  
     3  package log
     4  
     5  import (
     6  	"runtime"
     7  
     8  	"github.com/GeniusesGroup/libgo/protocol"
     9  )
    10  
    11  func CheckLevelEnabled(level protocol.LogType) bool {
    12  	return protocol.LogMode&level != 0 
    13  }
    14  
    15  func CallerInfo(calldepth int) (file string, line int) {
    16  	var ok bool
    17  	_, file, line, ok = runtime.Caller(calldepth)
    18  	if !ok {
    19  		file = "?"
    20  		line = 0
    21  	}
    22  	return
    23  }
    24  
    25  // FatalError use as log.FatalError(function()) and not check return error from function.
    26  // It will just panic error not exit app and return to OS, Because all goroutine without any notify will terminate and can't recover in any way.
    27  // So we just panic it and wait to some logic recover it or let app close in main function.
    28  func FatalError(err protocol.Error) {
    29  	if err != nil {
    30  		// os.Exit(125)
    31  		panic(err)
    32  	}
    33  }