github.com/haraldrudell/parl@v0.4.176/plog/get-log.go (about) 1 /* 2 © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 3 ISC License 4 */ 5 6 package plog 7 8 import ( 9 "io" 10 "log" 11 "os" 12 ) 13 14 // logMap translates an [io.Writer] instance to a [log.logger] instance 15 // - key: io.Writer such as os.Stderr 16 // - value: log.Logger obtaiend from [log.New] 17 var logMap = map[io.Writer]*log.Logger{ 18 os.Stdout: log.New(os.Stdout, "", 0), 19 os.Stderr: log.New(os.Stderr, "", 0), 20 } 21 22 // GetLog returns shared log.Logger instances for file descriptors os.Stdout and os.Stderr. 23 // - if Logger instance is shared, output is thread-safe. 24 // - if other means of output is used, the result is unpredictably intermingled output 25 func GetLog(writer io.Writer) *log.Logger { 26 return logMap[writer] 27 }