March 2019
Intermediate to advanced
336 pages
9h 9m
English
While logging, you can log with the line number and the method name. The following code snippet shows how logging can be executed with the line number and the method name:
//main package has examples shown//in Go Data Structures and algorithms bookpackage main//importing path, runtime, fmt, log and time packagesimport( "path" "runtime" "fmt" "log" "time")//checkPoint methodfunc checkPoint() string { pc, file, line, _ := runtime.Caller(1) return fmt.Sprintf("\033[31m%v %s %s %d\x1b[0m", time.Now(), runtime.FuncForPC(pc).Name(), path.Base(file), line)}//method1func method1(){ fmt.Println(checkPoint())}//main methodfunc main() { log.SetFlags(log.LstdFlags | log.Lshortfile) log.Println("logging the time and flags") ...Read now
Unlock full access