From 557edecd40e73921f1ad214b11fc2c045f38cb25 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 20 Sep 2019 11:51:04 +0100 Subject: [PATCH] log: add Stack() function for debugging who calls what --- fs/log/log.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/log/log.go b/fs/log/log.go index b38facb84..60e138dd8 100644 --- a/fs/log/log.go +++ b/fs/log/log.go @@ -65,6 +65,18 @@ func Trace(o interface{}, format string, a ...interface{}) func(string, ...inter } } +// Stack logs a stack trace of callers with the o and info passed in +func Stack(o interface{}, info string) { + if fs.Config.LogLevel < fs.LogLevelDebug { + return + } + arr := [16 * 1024]byte{} + buf := arr[:] + n := runtime.Stack(buf, false) + buf = buf[:n] + fs.LogPrintf(fs.LogLevelDebug, o, "%s\nStack trace:\n%s", info, buf) +} + // InitLogging start the logging as per the command line flags func InitLogging() { flagsStr := "," + *logFormat + ","