Skip to content

Instantly share code, notes, and snippets.

@nicewook
Created June 14, 2019 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicewook/2e9209b0d59a0bc00970179e636d590d to your computer and use it in GitHub Desktop.
Save nicewook/2e9209b0d59a0bc00970179e636d590d to your computer and use it in GitHub Desktop.
package main
import (
// "fmt"
"log"
"os"
"runtime"
)
var fileLogger *log.Logger
func cd1(f *os.File) {
cd2(f)
}
func cd2(f *os.File) {
cd3(f)
}
func cd3(f *os.File) {
fileLogger.Output(1, "I am cd3")
fileLogger.Output(2, "I am cd3")
fileLogger.Output(3, "I am cd3")
}
func main() {
runtime.GOMAXPROCS(1)
log.Println("Call depth test...")
fn := "calldepth.log"
f, err := os.OpenFile(fn, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
defer f.Close()
if err != nil {
log.Fatal(err)
}
fileLogger = log.New(f, "", log.Llongfile)
cd1(f)
}
// calldepth.log
// D:/golang/src/github.com/nicewook/calldepth/main.go:21: I am cd3
// D:/golang/src/github.com/nicewook/calldepth/main.go:17: I am cd3
// D:/golang/src/github.com/nicewook/calldepth/main.go:13: I am cd3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment