| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- package logger
- import (
- "context"
- "fmt"
- "os"
- "git.shuncheng.lu/bigthing/gocommon/pkg/trace"
- )
- /**
- 业务日志暴露接口
- */
- var (
- Fatal = func(s string) {
- err := _fileLogWriter.Log(LevelFatal).Output(LevelFatal, s)
- if err != nil {
- consoleLogger.Errorf("write Fatal log to file fail, err: %s", err.Error())
- }
- os.Exit(1)
- }
- Fatalf = func(format string, v ...interface{}) {
- err := _fileLogWriter.Log(LevelFatal).Output(LevelFatal, fmt.Sprintf(format, v...))
- if err != nil {
- consoleLogger.Errorf("write Fatalf log to file fail, err: %s", err.Error())
- }
- os.Exit(1)
- }
- Fatalc = func(ctx context.Context, format string, v ...interface{}) {
- err := _fileLogWriter.Log(LevelFatal).Output(LevelFatal, fmt.Sprintf(fmt.Sprintf("[trace_id=%v] %s", GetTraceId(ctx), format), v...))
- if err != nil {
- consoleLogger.Errorf("write Fatalc log to file fail, err: %s", err.Error())
- }
- os.Exit(1)
- }
- Error = func(s string) {
- err := _fileLogWriter.Log(LevelError).Output(LevelError, s)
- if err != nil {
- consoleLogger.Errorf("write Error log to file fail, err: %s", err.Error())
- }
- }
- Errorf = func(format string, v ...interface{}) {
- err := _fileLogWriter.Log(LevelError).Output(LevelError, fmt.Sprintf(format, v...))
- if err != nil {
- consoleLogger.Errorf("write Errorf log to file fail, err: %s", err.Error())
- }
- }
- Errorc = func(ctx context.Context, format string, v ...interface{}) {
- out := fmt.Sprintf(format, v...)
- trace.GinLogError(ctx, out)
- err := _fileLogWriter.Log(LevelError).Output(LevelError, "[trace_id="+GetTraceId(ctx)+"] "+out)
- if err != nil {
- consoleLogger.Errorf("write Errorc log to file fail, err: %s", err.Error())
- }
- }
- Warn = func(s string) {
- err := _fileLogWriter.Log(LevelWarning).Output(LevelWarning, s)
- if err != nil {
- consoleLogger.Errorf("write Warn log to file fail, err: %s", err.Error())
- }
- }
- Warnf = func(format string, v ...interface{}) {
- err := _fileLogWriter.Log(LevelWarning).Output(LevelWarning, fmt.Sprintf(format, v...))
- if err != nil {
- consoleLogger.Errorf("write Warnf log to file fail, err: %s", err.Error())
- }
- }
- Warnc = func(ctx context.Context, format string, v ...interface{}) {
- out := fmt.Sprintf(format, v...)
- //trace.GinLogInfo(ctx, out)
- err := _fileLogWriter.Log(LevelWarning).Output(LevelWarning, "[trace_id="+GetTraceId(ctx)+"] "+out)
- if err != nil {
- consoleLogger.Errorf("write Warnc log to file fail, err: %s", err.Error())
- }
- }
- Info = func(s string) {
- err := _fileLogWriter.Log(LevelInfo).Output(LevelInfo, s)
- if err != nil {
- consoleLogger.Errorf("write Info log to file fail, err: %s", err.Error())
- }
- }
- Infof = func(format string, v ...interface{}) {
- err := _fileLogWriter.Log(LevelInfo).Output(LevelInfo, fmt.Sprintf(format, v...))
- if err != nil {
- consoleLogger.Errorf("write Infof log to file fail, err: %s", err.Error())
- }
- }
- Infoc = func(ctx context.Context, format string, v ...interface{}) {
- out := fmt.Sprintf(format, v...)
- //trace.GinLogInfo(ctx, out) // 由于整个数据体传递信息记录成本太高,所有info不做记录
- err := _fileLogWriter.Log(LevelInfo).Output(LevelInfo, "[trace_id="+GetTraceId(ctx)+"] "+out)
- if err != nil {
- consoleLogger.Errorf("write Infoc log to file fail, err: %s", err.Error())
- }
- }
- Debug = func(s string) {
- err := _fileLogWriter.Log(LevelDebug).Output(LevelDebug, s)
- if err != nil {
- consoleLogger.Errorf("write Debug log to file fail, err: %s", err.Error())
- }
- }
- Debugf = func(format string, v ...interface{}) {
- err := _fileLogWriter.Log(LevelDebug).Output(LevelDebug, fmt.Sprintf(format, v...))
- if err != nil {
- consoleLogger.Errorf("write Debugf log to file fail, err: %s", err.Error())
- }
- }
- Debugc = func(ctx context.Context, format string, v ...interface{}) {
- err := _fileLogWriter.Log(LevelDebug).Output(LevelDebug, fmt.Sprintf(fmt.Sprintf("[trace_id=%v] %s", GetTraceId(ctx), format), v...))
- if err != nil {
- consoleLogger.Errorf("write Debugc log to file fail, err: %s", err.Error())
- }
- }
- )
|