github.com/xmplusdev/xmcore@v1.8.11-0.20240412132628-5518b55526af/common/singbridge/logger.go (about)

     1  package singbridge
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/sagernet/sing/common/logger"
     7  	"github.com/xmplusdev/xmcore/common/errors"
     8  	"github.com/xmplusdev/xmcore/common/session"
     9  )
    10  
    11  var _ logger.ContextLogger = (*XrayLogger)(nil)
    12  
    13  type XrayLogger struct {
    14  	newError func(values ...any) *errors.Error
    15  }
    16  
    17  func NewLogger(newErrorFunc func(values ...any) *errors.Error) *XrayLogger {
    18  	return &XrayLogger{
    19  		newErrorFunc,
    20  	}
    21  }
    22  
    23  func (l *XrayLogger) Trace(args ...any) {
    24  }
    25  
    26  func (l *XrayLogger) Debug(args ...any) {
    27  	l.newError(args...).AtDebug().WriteToLog()
    28  }
    29  
    30  func (l *XrayLogger) Info(args ...any) {
    31  	l.newError(args...).AtInfo().WriteToLog()
    32  }
    33  
    34  func (l *XrayLogger) Warn(args ...any) {
    35  	l.newError(args...).AtWarning().WriteToLog()
    36  }
    37  
    38  func (l *XrayLogger) Error(args ...any) {
    39  	l.newError(args...).AtError().WriteToLog()
    40  }
    41  
    42  func (l *XrayLogger) Fatal(args ...any) {
    43  }
    44  
    45  func (l *XrayLogger) Panic(args ...any) {
    46  }
    47  
    48  func (l *XrayLogger) TraceContext(ctx context.Context, args ...any) {
    49  }
    50  
    51  func (l *XrayLogger) DebugContext(ctx context.Context, args ...any) {
    52  	l.newError(args...).AtDebug().WriteToLog(session.ExportIDToError(ctx))
    53  }
    54  
    55  func (l *XrayLogger) InfoContext(ctx context.Context, args ...any) {
    56  	l.newError(args...).AtInfo().WriteToLog(session.ExportIDToError(ctx))
    57  }
    58  
    59  func (l *XrayLogger) WarnContext(ctx context.Context, args ...any) {
    60  	l.newError(args...).AtWarning().WriteToLog(session.ExportIDToError(ctx))
    61  }
    62  
    63  func (l *XrayLogger) ErrorContext(ctx context.Context, args ...any) {
    64  	l.newError(args...).AtError().WriteToLog(session.ExportIDToError(ctx))
    65  }
    66  
    67  func (l *XrayLogger) FatalContext(ctx context.Context, args ...any) {
    68  }
    69  
    70  func (l *XrayLogger) PanicContext(ctx context.Context, args ...any) {
    71  }