github.com/nextlinux/gosbom@v0.81.1-0.20230627115839-1ff50c281391/internal/log/log.go (about)

     1  /*
     2  Package log contains the singleton object and helper functions for facilitating logging within the gosbom library.
     3  */
     4  package log
     5  
     6  import (
     7  	"github.com/anchore/go-logger"
     8  	"github.com/anchore/go-logger/adapter/discard"
     9  )
    10  
    11  // Log is the singleton used to facilitate logging internally within gosbom
    12  var Log logger.Logger = discard.New()
    13  
    14  // Errorf takes a formatted template string and template arguments for the error logging level.
    15  func Errorf(format string, args ...interface{}) {
    16  	Log.Errorf(format, args...)
    17  }
    18  
    19  // Error logs the given arguments at the error logging level.
    20  func Error(args ...interface{}) {
    21  	Log.Error(args...)
    22  }
    23  
    24  // Warnf takes a formatted template string and template arguments for the warning logging level.
    25  func Warnf(format string, args ...interface{}) {
    26  	Log.Warnf(format, args...)
    27  }
    28  
    29  // Warn logs the given arguments at the warning logging level.
    30  func Warn(args ...interface{}) {
    31  	Log.Warn(args...)
    32  }
    33  
    34  // Infof takes a formatted template string and template arguments for the info logging level.
    35  func Infof(format string, args ...interface{}) {
    36  	Log.Infof(format, args...)
    37  }
    38  
    39  // Info logs the given arguments at the info logging level.
    40  func Info(args ...interface{}) {
    41  	Log.Info(args...)
    42  }
    43  
    44  // Debugf takes a formatted template string and template arguments for the debug logging level.
    45  func Debugf(format string, args ...interface{}) {
    46  	Log.Debugf(format, args...)
    47  }
    48  
    49  // Debug logs the given arguments at the debug logging level.
    50  func Debug(args ...interface{}) {
    51  	Log.Debug(args...)
    52  }
    53  
    54  // Tracef takes a formatted template string and template arguments for the trace logging level.
    55  func Tracef(format string, args ...interface{}) {
    56  	Log.Tracef(format, args...)
    57  }
    58  
    59  // Trace logs the given arguments at the trace logging level.
    60  func Trace(args ...interface{}) {
    61  	Log.Trace(args...)
    62  }
    63  
    64  // WithFields returns a message logger with multiple key-value fields.
    65  func WithFields(fields ...interface{}) logger.MessageLogger {
    66  	return Log.WithFields(fields...)
    67  }
    68  
    69  // Nested returns a new logger with hard coded key-value pairs
    70  func Nested(fields ...interface{}) logger.Logger {
    71  	return Log.Nested(fields...)
    72  }