github.com/aavshr/aws-sdk-go@v1.41.3/aws/logger.go (about) 1 package aws 2 3 import ( 4 "log" 5 "os" 6 ) 7 8 // A LogLevelType defines the level logging should be performed at. Used to instruct 9 // the SDK which statements should be logged. 10 type LogLevelType uint 11 12 // LogLevel returns the pointer to a LogLevel. Should be used to workaround 13 // not being able to take the address of a non-composite literal. 14 func LogLevel(l LogLevelType) *LogLevelType { 15 return &l 16 } 17 18 // Value returns the LogLevel value or the default value LogOff if the LogLevel 19 // is nil. Safe to use on nil value LogLevelTypes. 20 func (l *LogLevelType) Value() LogLevelType { 21 if l != nil { 22 return *l 23 } 24 return LogOff 25 } 26 27 // Matches returns true if the v LogLevel is enabled by this LogLevel. Should be 28 // used with logging sub levels. Is safe to use on nil value LogLevelTypes. If 29 // LogLevel is nil, will default to LogOff comparison. 30 func (l *LogLevelType) Matches(v LogLevelType) bool { 31 c := l.Value() 32 return c&v == v 33 } 34 35 // AtLeast returns true if this LogLevel is at least high enough to satisfies v. 36 // Is safe to use on nil value LogLevelTypes. If LogLevel is nil, will default 37 // to LogOff comparison. 38 func (l *LogLevelType) AtLeast(v LogLevelType) bool { 39 c := l.Value() 40 return c >= v 41 } 42 43 const ( 44 // LogOff states that no logging should be performed by the SDK. This is the 45 // default state of the SDK, and should be use to disable all logging. 46 LogOff LogLevelType = iota * 0x1000 47 48 // LogDebug state that debug output should be logged by the SDK. This should 49 // be used to inspect request made and responses received. 50 LogDebug 51 ) 52 53 // Debug Logging Sub Levels 54 const ( 55 // LogDebugWithSigning states that the SDK should log request signing and 56 // presigning events. This should be used to log the signing details of 57 // requests for debugging. Will also enable LogDebug. 58 LogDebugWithSigning LogLevelType = LogDebug | (1 << iota) 59 60 // LogDebugWithHTTPBody states the SDK should log HTTP request and response 61 // HTTP bodys in addition to the headers and path. This should be used to 62 // see the body content of requests and responses made while using the SDK 63 // Will also enable LogDebug. 64 LogDebugWithHTTPBody 65 66 // LogDebugWithRequestRetries states the SDK should log when service requests will 67 // be retried. This should be used to log when you want to log when service 68 // requests are being retried. Will also enable LogDebug. 69 LogDebugWithRequestRetries 70 71 // LogDebugWithRequestErrors states the SDK should log when service requests fail 72 // to build, send, validate, or unmarshal. 73 LogDebugWithRequestErrors 74 75 // LogDebugWithEventStreamBody states the SDK should log EventStream 76 // request and response bodys. This should be used to log the EventStream 77 // wire unmarshaled message content of requests and responses made while 78 // using the SDK Will also enable LogDebug. 79 LogDebugWithEventStreamBody 80 ) 81 82 // A Logger is a minimalistic interface for the SDK to log messages to. Should 83 // be used to provide custom logging writers for the SDK to use. 84 type Logger interface { 85 Log(...interface{}) 86 } 87 88 // A LoggerFunc is a convenience type to convert a function taking a variadic 89 // list of arguments and wrap it so the Logger interface can be used. 90 // 91 // Example: 92 // s3.New(sess, &aws.Config{Logger: aws.LoggerFunc(func(args ...interface{}) { 93 // fmt.Fprintln(os.Stdout, args...) 94 // })}) 95 type LoggerFunc func(...interface{}) 96 97 // Log calls the wrapped function with the arguments provided 98 func (f LoggerFunc) Log(args ...interface{}) { 99 f(args...) 100 } 101 102 // NewDefaultLogger returns a Logger which will write log messages to stdout, and 103 // use same formatting runes as the stdlib log.Logger 104 func NewDefaultLogger() Logger { 105 return &defaultLogger{ 106 logger: log.New(os.Stdout, "", log.LstdFlags), 107 } 108 } 109 110 // A defaultLogger provides a minimalistic logger satisfying the Logger interface. 111 type defaultLogger struct { 112 logger *log.Logger 113 } 114 115 // Log logs the parameters to the stdlib logger. See log.Println. 116 func (l defaultLogger) Log(args ...interface{}) { 117 l.logger.Println(args...) 118 }