mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-24 10:07:04 +02:00
Display only logging file name as opposed to path in logs (#1580)
This commit is contained in:
parent
ec44b67e9f
commit
434997e676
@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@ -55,18 +55,9 @@ func copyFields(src map[string]interface{}) map[string]interface{} {
|
|||||||
return dst
|
return dst
|
||||||
}
|
}
|
||||||
|
|
||||||
var sourceControlSites = []string{"github.com"}
|
func logCallerfilePath(loggingFilePath string) string {
|
||||||
|
parts := strings.Split(loggingFilePath, string(filepath.Separator))
|
||||||
func logCallerfilePath(filepath string) string {
|
return parts[len(parts)-1]
|
||||||
for _, v := range sourceControlSites {
|
|
||||||
if strings.Contains(filepath, v) {
|
|
||||||
parts := strings.Split(filepath, v)
|
|
||||||
if len(parts) > 0 {
|
|
||||||
return path.Join(v, parts[1])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filepath
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *defaultLogger) Log(level Level, v ...interface{}) {
|
func (l *defaultLogger) Log(level Level, v ...interface{}) {
|
||||||
@ -82,7 +73,7 @@ func (l *defaultLogger) Log(level Level, v ...interface{}) {
|
|||||||
fields["level"] = level.String()
|
fields["level"] = level.String()
|
||||||
|
|
||||||
if _, file, line, ok := runtime.Caller(l.opts.CallerSkipCount); ok {
|
if _, file, line, ok := runtime.Caller(l.opts.CallerSkipCount); ok {
|
||||||
fields["caller"] = fmt.Sprintf("%s:%d", logCallerfilePath(file), line)
|
fields["file"] = fmt.Sprintf("%s:%d", logCallerfilePath(file), line)
|
||||||
}
|
}
|
||||||
|
|
||||||
rec := dlog.Record{
|
rec := dlog.Record{
|
||||||
@ -123,7 +114,7 @@ func (l *defaultLogger) Logf(level Level, format string, v ...interface{}) {
|
|||||||
fields["level"] = level.String()
|
fields["level"] = level.String()
|
||||||
|
|
||||||
if _, file, line, ok := runtime.Caller(l.opts.CallerSkipCount); ok {
|
if _, file, line, ok := runtime.Caller(l.opts.CallerSkipCount); ok {
|
||||||
fields["caller"] = fmt.Sprintf("%s:%d", logCallerfilePath(file), line)
|
fields["file"] = fmt.Sprintf("%s:%d", logCallerfilePath(file), line)
|
||||||
}
|
}
|
||||||
|
|
||||||
rec := dlog.Record{
|
rec := dlog.Record{
|
||||||
|
Loading…
Reference in New Issue
Block a user