github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/logger/single_context_logger.go (about)

     1  package logger
     2  
     3  import (
     4  	"golang.org/x/net/context"
     5  )
     6  
     7  // SingleContextLogger logs everything in the same context. Useful for adding context-logging
     8  // into code that doesn't yet support it.
     9  type SingleContextLogger struct {
    10  	ctx    context.Context
    11  	logger Logger
    12  }
    13  
    14  func NewSingleContextLogger(ctx context.Context, l Logger) *SingleContextLogger {
    15  	return &SingleContextLogger{ctx: ctx, logger: l}
    16  }
    17  
    18  var _ Logger = (*SingleContextLogger)(nil)
    19  
    20  func (s *SingleContextLogger) Debug(format string, args ...interface{}) {
    21  	s.logger.CloneWithAddedDepth(1).CDebugf(s.ctx, format, args...)
    22  }
    23  func (s *SingleContextLogger) CDebugf(ctx context.Context, format string, args ...interface{}) {
    24  	s.logger.CloneWithAddedDepth(1).CDebugf(ctx, format, args...)
    25  }
    26  func (s *SingleContextLogger) Info(format string, args ...interface{}) {
    27  	s.logger.CloneWithAddedDepth(1).CInfof(s.ctx, format, args...)
    28  }
    29  func (s *SingleContextLogger) CInfof(ctx context.Context, format string, args ...interface{}) {
    30  	s.logger.CloneWithAddedDepth(1).CInfof(ctx, format, args...)
    31  }
    32  func (s *SingleContextLogger) Notice(format string, args ...interface{}) {
    33  	s.logger.CloneWithAddedDepth(1).CNoticef(s.ctx, format, args...)
    34  }
    35  func (s *SingleContextLogger) CNoticef(ctx context.Context, format string, args ...interface{}) {
    36  	s.logger.CloneWithAddedDepth(1).CNoticef(ctx, format, args...)
    37  }
    38  func (s *SingleContextLogger) Warning(format string, args ...interface{}) {
    39  	s.logger.CloneWithAddedDepth(1).CWarningf(s.ctx, format, args...)
    40  }
    41  func (s *SingleContextLogger) CWarningf(ctx context.Context, format string, args ...interface{}) {
    42  	s.logger.CloneWithAddedDepth(1).CWarningf(ctx, format, args...)
    43  }
    44  func (s *SingleContextLogger) Error(format string, args ...interface{}) {
    45  	s.logger.CloneWithAddedDepth(1).CErrorf(s.ctx, format, args...)
    46  }
    47  func (s *SingleContextLogger) Errorf(format string, args ...interface{}) {
    48  	s.logger.CloneWithAddedDepth(1).CErrorf(s.ctx, format, args...)
    49  }
    50  func (s *SingleContextLogger) CErrorf(ctx context.Context, format string, args ...interface{}) {
    51  	s.logger.CloneWithAddedDepth(1).CErrorf(ctx, format, args...)
    52  }
    53  func (s *SingleContextLogger) Critical(format string, args ...interface{}) {
    54  	s.logger.CloneWithAddedDepth(1).CCriticalf(s.ctx, format, args...)
    55  }
    56  func (s *SingleContextLogger) CCriticalf(ctx context.Context, format string, args ...interface{}) {
    57  	s.logger.CloneWithAddedDepth(1).CCriticalf(ctx, format, args...)
    58  }
    59  func (s *SingleContextLogger) Fatalf(format string, args ...interface{}) {
    60  	s.logger.CloneWithAddedDepth(1).CFatalf(s.ctx, format, args...)
    61  }
    62  func (s *SingleContextLogger) CFatalf(ctx context.Context, format string, args ...interface{}) {
    63  	s.logger.CloneWithAddedDepth(1).CFatalf(ctx, format, args...)
    64  }
    65  func (s *SingleContextLogger) Profile(fmts string, arg ...interface{}) {
    66  	s.logger.CloneWithAddedDepth(1).Profile(fmts, arg...)
    67  }
    68  func (s *SingleContextLogger) Configure(style string, debug bool, filename string) {
    69  	s.logger.Configure(style, debug, filename)
    70  }
    71  func (s *SingleContextLogger) CloneWithAddedDepth(depth int) Logger {
    72  	return &SingleContextLogger{
    73  		ctx:    s.ctx,
    74  		logger: s.logger.CloneWithAddedDepth(depth),
    75  	}
    76  }
    77  func (s *SingleContextLogger) SetExternalHandler(handler ExternalHandler) {
    78  	s.logger.SetExternalHandler(handler)
    79  }