Skip to content

Commit

Permalink
Update slog.go
Browse files Browse the repository at this point in the history
  • Loading branch information
UndefinedSy committed Dec 23, 2020
1 parent d5df5ed commit 0e90a7d
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/slog/slog.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package slog

import (
"fmt"
"log"
"strings"
"runtime"
_"reflect"
"path/filepath"
"fmt"
"log"
"strings"
"runtime"
_"reflect"
"path/filepath"
)

type LogLevel int
Expand Down Expand Up @@ -34,13 +34,13 @@ func Log(logLevel LogLevel, formating string, args ...interface{}) {
if logLevel <= currentLogLevel {
var funcname string
pc, filename, line, ok := runtime.Caller(1)
// fmt.Println(reflect.TypeOf(pc), reflect.ValueOf(pc))

if ok {
funcname = runtime.FuncForPC(pc).Name() // main.(*MyStruct).foo
funcname = filepath.Ext(funcname) // .foo
funcname = strings.TrimPrefix(funcname, ".") // foo
funcname = runtime.FuncForPC(pc).Name()
funcname = filepath.Ext(funcname)
funcname = strings.TrimPrefix(funcname, ".")

filename = filepath.Base(filename) // /full/path/basename.go => basename.go
filename = filepath.Base(filename)

log.Printf("%s - %s:%d(%s): %s\n", logLevelString, filename, line, funcname, fmt.Sprintf(formating, args...))
} else {
Expand Down

0 comments on commit 0e90a7d

Please sign in to comment.