github.com/aavshr/aws-sdk-go@v1.41.3/private/model/api/logger.go (about) 1 //go:build codegen 2 // +build codegen 3 4 package api 5 6 import ( 7 "fmt" 8 "io" 9 "sync" 10 ) 11 12 var debugLogger *logger 13 var initDebugLoggerOnce sync.Once 14 15 // logger provides a basic logging 16 type logger struct { 17 w io.Writer 18 } 19 20 // LogDebug initialize's the debug logger for the components in the api 21 // package to log debug lines to. 22 // 23 // Panics if called multiple times. 24 // 25 // Must be used prior to any model loading or code gen. 26 func LogDebug(w io.Writer) { 27 var initialized bool 28 initDebugLoggerOnce.Do(func() { 29 debugLogger = &logger{ 30 w: w, 31 } 32 initialized = true 33 }) 34 35 if !initialized && debugLogger != nil { 36 panic("LogDebug called multiple times. Can only be called once") 37 } 38 } 39 40 // Logf logs using the fmt printf pattern. Appends a new line to the end of the 41 // logged statement. 42 func (l *logger) Logf(format string, args ...interface{}) { 43 if l == nil { 44 return 45 } 46 fmt.Fprintf(l.w, format+"\n", args...) 47 } 48 49 // Logln logs using the fmt println pattern. 50 func (l *logger) Logln(args ...interface{}) { 51 if l == nil { 52 return 53 } 54 fmt.Fprintln(l.w, args...) 55 }