change log file path
This commit is contained in:
parent
eec8fe18e4
commit
40b0a3597c
34
log.go
34
log.go
@ -204,7 +204,7 @@ func (log *Logger) logwrite(typ LogLevel, calldepth int, format string, v ...int
|
||||
calldepth += log.calldepth
|
||||
var (
|
||||
idstr = log.GetLogidStr(" [%s]")
|
||||
header = formatHeader(calldepth, log.skipfunc) + "$" + idstr
|
||||
header = formatHeader(calldepth, log.skipfunc) /*+ "$"*/ + idstr
|
||||
)
|
||||
|
||||
format = strings.Trim(format, "\n")
|
||||
@ -227,24 +227,25 @@ func (log *Logger) logwrite(typ LogLevel, calldepth int, format string, v ...int
|
||||
log.golog.SetPrefix("\x1b[33m" + "UNKN " + header + "\x1b[0m" + " ")
|
||||
}
|
||||
|
||||
if typ == WARNING || typ == ERROR {
|
||||
switch typ {
|
||||
case WARNING, ERROR:
|
||||
log.golog.Output(calldepth, "\x1b[31m"+fmt.Sprintf(format, v...)+"\x1b[0m")
|
||||
} else if typ == INFO || typ == DEBUG {
|
||||
case INFO, DEBUG:
|
||||
log.golog.Output(calldepth, fmt.Sprintf(format, v...))
|
||||
} else if typ == NOTICE {
|
||||
case NOTICE:
|
||||
calldepth = calldepth + 2
|
||||
log.golog.Output(calldepth, fmt.Sprintf(format, v...))
|
||||
} else if typ == FATAL {
|
||||
case FATAL:
|
||||
stackstr := strings.Replace(string(debug.Stack()), "\n", "\n== ", -1)
|
||||
stackstr = "\n== Fatal stack:\n" + str.SkipLine(stackstr, calldepth*2+1)
|
||||
log.golog.Output(calldepth, fmt.Sprintf(format, v...)+stackstr)
|
||||
os.Exit(1)
|
||||
} else if typ == PANIC {
|
||||
case PANIC:
|
||||
stackstr := strings.Replace(string(debug.Stack()), "\n", "\n== ", -1)
|
||||
stackstr = "\n== Panic stack:\n" + str.SkipLine(stackstr, calldepth*2+1)
|
||||
log.golog.Output(calldepth, fmt.Sprintf(format, v...)+stackstr)
|
||||
panic(fmt.Sprintf(format, v...))
|
||||
} else {
|
||||
default:
|
||||
panic(ErrLogLevel)
|
||||
}
|
||||
}
|
||||
@ -309,6 +310,10 @@ func formatHeader(calldepth int, skipfunc func(string) bool) string {
|
||||
if len(tempheader) > MAX_LENGTH {
|
||||
//tempheader = "…" + tempheader[len(tempheader)-MAX_LENGTH+1:]
|
||||
tempheader = tempheader[len(tempheader)-MAX_LENGTH:]
|
||||
if !strings.Contains(tempheader, " ") {
|
||||
tempheader = strings.Replace(tempheader, "/", " ", 1)
|
||||
}
|
||||
tempheader = "." + tempheader[1:]
|
||||
return nowstr + tempheader
|
||||
}
|
||||
|
||||
@ -317,6 +322,10 @@ func formatHeader(calldepth int, skipfunc func(string) bool) string {
|
||||
if len(tempheader) > MAX_LENGTH {
|
||||
//tempheader = "…" + tempheader[len(tempheader)-MAX_LENGTH+1:]
|
||||
tempheader = tempheader[len(tempheader)-MAX_LENGTH:]
|
||||
if !strings.Contains(tempheader, " ") {
|
||||
tempheader = strings.Replace(tempheader, "/", " ", 1)
|
||||
}
|
||||
tempheader = "." + tempheader[1:]
|
||||
return nowstr + tempheader
|
||||
}
|
||||
|
||||
@ -325,14 +334,21 @@ func formatHeader(calldepth int, skipfunc func(string) bool) string {
|
||||
if len(tempheader) > MAX_LENGTH {
|
||||
//tempheader = "…" + tempheader[len(tempheader)-MAX_LENGTH+1:]
|
||||
tempheader = tempheader[len(tempheader)-MAX_LENGTH:]
|
||||
if !strings.Contains(tempheader, " ") {
|
||||
tempheader = strings.Replace(tempheader, "/", " ", 1)
|
||||
}
|
||||
tempheader = "." + tempheader[1:]
|
||||
return nowstr + tempheader
|
||||
}
|
||||
|
||||
// Case 7: fallback
|
||||
tempheader = "." + tempheader[1:]
|
||||
return nowstr + tempheader
|
||||
}
|
||||
|
||||
func formatHeaderPath(file string, i, maxwidth, fullstep int) (paths string) {
|
||||
paths = ""
|
||||
startCut := false
|
||||
ii, iw, step := i, i, 1
|
||||
for i := ii; i >= 0; i-- {
|
||||
if file[i] == '/' {
|
||||
@ -342,6 +358,10 @@ func formatHeaderPath(file string, i, maxwidth, fullstep int) (paths string) {
|
||||
paths = file[i:iw+1] + paths
|
||||
} else if iw-i > maxwidth {
|
||||
// dirname lenght more then width
|
||||
if startCut == false && len(paths) > 0 && paths[0] == '/' {
|
||||
startCut = true
|
||||
paths = " " + paths[1:]
|
||||
}
|
||||
paths = file[i:i+maxwidth] + paths // paths = file[i:i+width] + "..." + paths
|
||||
} else {
|
||||
// dirname lenght less then width
|
||||
|
||||
@ -4,7 +4,4 @@ import "testing"
|
||||
|
||||
func TestLog(t *testing.T) {
|
||||
Println("aaa", 1, 3, 6)
|
||||
Fatal("aaa", 1, 3)
|
||||
Fatalf("aaa=%d", 1)
|
||||
Panicf("aaa=%d", 1)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user