tSimplify logging/fname. - tordam - A library for peer discovery inside the Tor network (HTM) git clone https://git.parazyd.org/tordam (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit 439ac37956e6fdd745aa9de01011b4775628eeae (DIR) parent b28b13a0285e5459b23fc0b2ee42262f75efbf1a (HTM) Author: parazyd <parazyd@dyne.org> Date: Sun, 21 Mar 2021 12:18:15 +0100 Simplify logging/fname. Diffstat: M logging.go | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) --- (DIR) diff --git a/logging.go b/logging.go t@@ -20,9 +20,8 @@ package tordam import ( "log" "os" - "path/filepath" + "path" "runtime" - "strings" ) var ( t@@ -35,25 +34,18 @@ var ( // It should be called from programs using the library, with something like: // tordam.LogInit(os.Stdout) func LogInit(f *os.File) { - inte = log.New(f, "(tordam) INTERNAL ERROR: ", log.Ldate|log.Ltime|log.Lshortfile) - warn = log.New(f, "(tordam) WARNING: ", log.Ldate|log.Ltime) - info = log.New(f, "(tordam) INFO: ", log.Ldate|log.Ltime) + inte = log.New(f, "INTERNAL ERROR: ", log.Ldate|log.Ltime|log.Lshortfile) + warn = log.New(f, "WARNING: ", log.Ldate|log.Ltime) + info = log.New(f, "INFO: ", log.Ldate|log.Ltime) } func fname() string { pc, _, _, _ := runtime.Caller(2) - fn := runtime.FuncForPC(pc) - - var fnName string - - if fn == nil { - fnName = "?()" + if fn := runtime.FuncForPC(pc); fn != nil { + return path.Base(fn.Name()) + "()" } else { - dotName := filepath.Ext(fn.Name()) - fnName = strings.TrimLeft(dotName, ".") + "()" + return "?()" } - - return fnName } func rpcWarn(msg string) {