github.com/kastenhq/syft@v0.0.0-20230821225854-0710af25cdbe/internal/log/log.go (about) 1 /* 2 Package log contains the singleton object and helper functions for facilitating logging within the syft library. 3 */ 4 package log 5 6 import ( 7 "github.com/anchore/go-logger" 8 "github.com/anchore/go-logger/adapter/discard" 9 "github.com/anchore/go-logger/adapter/redact" 10 ) 11 12 var ( 13 // log is the singleton used to facilitate logging internally within 14 log = discard.New() 15 16 store = redact.NewStore() 17 18 Redactor = store.(redact.Redactor) 19 ) 20 21 func Set(l logger.Logger) { 22 log = redact.New(l, store) 23 } 24 25 func Get() logger.Logger { 26 return log 27 } 28 29 func Redact(values ...string) { 30 store.Add(values...) 31 } 32 33 // Errorf takes a formatted template string and template arguments for the error logging level. 34 func Errorf(format string, args ...interface{}) { 35 log.Errorf(format, args...) 36 } 37 38 // Error logs the given arguments at the error logging level. 39 func Error(args ...interface{}) { 40 log.Error(args...) 41 } 42 43 // Warnf takes a formatted template string and template arguments for the warning logging level. 44 func Warnf(format string, args ...interface{}) { 45 log.Warnf(format, args...) 46 } 47 48 // Warn logs the given arguments at the warning logging level. 49 func Warn(args ...interface{}) { 50 log.Warn(args...) 51 } 52 53 // Infof takes a formatted template string and template arguments for the info logging level. 54 func Infof(format string, args ...interface{}) { 55 log.Infof(format, args...) 56 } 57 58 // Info logs the given arguments at the info logging level. 59 func Info(args ...interface{}) { 60 log.Info(args...) 61 } 62 63 // Debugf takes a formatted template string and template arguments for the debug logging level. 64 func Debugf(format string, args ...interface{}) { 65 log.Debugf(format, args...) 66 } 67 68 // Debug logs the given arguments at the debug logging level. 69 func Debug(args ...interface{}) { 70 log.Debug(args...) 71 } 72 73 // Tracef takes a formatted template string and template arguments for the trace logging level. 74 func Tracef(format string, args ...interface{}) { 75 log.Tracef(format, args...) 76 } 77 78 // Trace logs the given arguments at the trace logging level. 79 func Trace(args ...interface{}) { 80 log.Trace(args...) 81 } 82 83 // WithFields returns a message logger with multiple key-value fields. 84 func WithFields(fields ...interface{}) logger.MessageLogger { 85 return log.WithFields(fields...) 86 } 87 88 // Nested returns a new logger with hard coded key-value pairs 89 func Nested(fields ...interface{}) logger.Logger { 90 return log.Nested(fields...) 91 }