Created
June 14, 2019 08:04
-
-
Save nicewook/2e9209b0d59a0bc00970179e636d590d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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