Skip to content

Commit

Permalink
调整:日志显示方式
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Apr 7, 2024
1 parent 1b9f6b0 commit 1102cdb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
14 changes: 6 additions & 8 deletions flog/compositionLogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,31 @@ func (r *CompositionLogger) Trace(contents ...any) {
}

func (r *CompositionLogger) Tracef(format string, a ...any) {
r.log(newLogData(eumLogLevel.Trace, fmt.Sprintf(format, a...), ""))
r.Trace(fmt.Sprintf(format, a...))
}

func (r *CompositionLogger) Debug(contents ...any) {
r.log(newLogData(eumLogLevel.Debug, fmt.Sprint(contents...), ""))
}

func (r *CompositionLogger) Debugf(format string, a ...any) {
r.log(newLogData(eumLogLevel.Debug, fmt.Sprintf(format, a...), ""))
r.Debug(fmt.Sprintf(format, a...))
}

func (r *CompositionLogger) Info(contents ...any) {
r.log(newLogData(eumLogLevel.Information, fmt.Sprint(contents...), ""))
}

func (r *CompositionLogger) Infof(format string, a ...any) {
r.log(newLogData(eumLogLevel.Information, fmt.Sprintf(format, a...), ""))
r.Info(fmt.Sprintf(format, a...))
}

func (r *CompositionLogger) Warning(contents ...any) {
r.log(newLogData(eumLogLevel.Warning, fmt.Sprint(contents...), ""))
}

func (r *CompositionLogger) Warningf(format string, a ...any) {
r.log(newLogData(eumLogLevel.Warning, fmt.Sprintf(format, a...), ""))
r.Warning(fmt.Sprintf(format, a...))
}

func (r *CompositionLogger) Error(contents ...any) error {
Expand All @@ -59,17 +59,15 @@ func (r *CompositionLogger) Error(contents ...any) error {
}

func (r *CompositionLogger) Errorf(format string, a ...any) error {
log := newLogData(eumLogLevel.Error, fmt.Sprintf(format, a...), "")
r.log(log)
return fmt.Errorf(TextFormatter{}.Formatter(log))
return r.Error(fmt.Sprintf(format, a...))
}

func (r *CompositionLogger) Critical(contents ...any) {
r.log(newLogData(eumLogLevel.Critical, fmt.Sprint(contents...), ""))
}

func (r *CompositionLogger) Criticalf(format string, a ...any) {
r.log(newLogData(eumLogLevel.Critical, fmt.Sprintf(format, a...), ""))
r.Criticalf(fmt.Sprintf(format, a...))
}

func (r *CompositionLogger) Log(logLevel eumLogLevel.Enum, content string, component string, newLine bool) {
Expand Down
5 changes: 0 additions & 5 deletions flog/consoleProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package flog
import (
"fmt"
"github.com/farseer-go/fs/core/eumLogLevel"
"github.com/farseer-go/fs/trace"
)

// ConsoleProvider 控制台打印
Expand All @@ -24,10 +23,6 @@ func (r *consoleLoggerPersistent) IsEnabled(logLevel eumLogLevel.Enum) bool {
}

func (r *consoleLoggerPersistent) Log(LogLevel eumLogLevel.Enum, log *LogData, exception error) {
if LogLevel == eumLogLevel.Error {
file, funcName, line := trace.GetCallerInfo()
fmt.Printf("%s:%s %s \n", file, Blue(line), funcName)
}
if log.newLine {
fmt.Println(r.formatter.Formatter(log))
} else {
Expand Down
22 changes: 16 additions & 6 deletions flog/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/farseer-go/fs/core"
"github.com/farseer-go/fs/core/eumLogLevel"
"github.com/farseer-go/fs/trace"
)

// log 日志
Expand All @@ -16,7 +17,7 @@ func Trace(contents ...any) {

// Tracef 打印Trace日志
func Tracef(format string, a ...any) {
log.Tracef(format, a...)
log.Trace(fmt.Sprintf(format, a...))
}

// Debug 打印Debug日志
Expand All @@ -26,7 +27,7 @@ func Debug(contents ...any) {

// Debugf 打印Debug日志
func Debugf(format string, a ...any) {
log.Debugf(format, a...)
log.Debug(fmt.Sprintf(format, a...))
}

// Info 打印Info日志
Expand All @@ -36,7 +37,7 @@ func Info(contents ...any) {

// Infof 打印Info日志
func Infof(format string, a ...any) {
log.Infof(format, a...)
log.Info(fmt.Sprintf(format, a...))
}

// Warning 打印Warning日志
Expand All @@ -46,11 +47,14 @@ func Warning(contents ...any) {

// Warningf 打印Warning日志
func Warningf(format string, a ...any) {
log.Warningf(format, a...)
log.Warning(fmt.Sprintf(format, a...))
}

// Error 打印Error日志
func Error(contents ...any) error {
if file, funcName, line := trace.GetCallerInfo(); file != "" {
Printf("%s:%s %s \n", file, Blue(line), funcName)
}
return log.Error(contents...)
}

Expand All @@ -59,12 +63,18 @@ func ErrorIfExists(err error) {
if err == nil {
return
}
if file, funcName, line := trace.GetCallerInfo(); file != "" {
Printf("%s:%s %s \n", file, Blue(line), funcName)
}
_ = log.Error(err)
}

// Errorf 打印Error日志
func Errorf(format string, a ...any) error {
return log.Errorf(format, a...)
if file, funcName, line := trace.GetCallerInfo(); file != "" {
Printf("%s:%s %s \n", file, Blue(line), funcName)
}
return log.Error(fmt.Sprintf(format, a...))
}

// Critical 打印Critical日志
Expand All @@ -74,7 +84,7 @@ func Critical(contents ...any) {

// Criticalf 打印Critical日志
func Criticalf(format string, a ...any) {
log.Criticalf(format, a...)
log.Critical(fmt.Sprintf(format, a...))
}

// Panic 打印Error日志并panic
Expand Down

0 comments on commit 1102cdb

Please sign in to comment.