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
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 {
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 {
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 nill, will default to LogOff comparison.
30 func (l *LogLevelType) Matches(v LogLevelType) bool {
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 nill, will default
37 // to LogOff comparison.
38 func (l *LogLevelType) AtLeast(v LogLevelType) bool {
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
48 // LogDebug state that debug output should be logged by the SDK. This should
49 // be used to inspect request made and responses received.
53 // Debug Logging Sub Levels
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)
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.
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
71 // LogDebugWithRequestErrors states the SDK should log when service requests fail
72 // to build, send, validate, or unmarshal.
73 LogDebugWithRequestErrors
76 // A Logger is a minimalistic interface for the SDK to log messages to. Should
77 // be used to provide custom logging writers for the SDK to use.
78 type Logger interface {
82 // A LoggerFunc is a convenience type to convert a function taking a variadic
83 // list of arguments and wrap it so the Logger interface can be used.
86 // s3.New(sess, &aws.Config{Logger: aws.LoggerFunc(func(args ...interface{}) {
87 // fmt.Fprintln(os.Stdout, args...)
89 type LoggerFunc func(...interface{})
91 // Log calls the wrapped function with the arguments provided
92 func (f LoggerFunc) Log(args ...interface{}) {
96 // NewDefaultLogger returns a Logger which will write log messages to stdout, and
97 // use same formatting runes as the stdlib log.Logger
98 func NewDefaultLogger() Logger {
99 return &defaultLogger{
100 logger: log.New(os.Stdout, "", log.LstdFlags),
104 // A defaultLogger provides a minimalistic logger satisfying the Logger interface.
105 type defaultLogger struct {
109 // Log logs the parameters to the stdlib logger. See log.Println.
110 func (l defaultLogger) Log(args ...interface{}) {
111 l.logger.Println(args...)