/
logging.go
48 lines (37 loc) · 901 Bytes
/
logging.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
Package logging provides support for logging to cloudwatch
within resource providers.
*/
package logging
// +build logging
import (
"io"
"log"
"os"
"syscall"
)
// define a new stdErr since we'll over-write the default stdout/err
// to prevent data leaking into the service account
var stdErr = os.NewFile(uintptr(syscall.Stderr), "/dev/stderr")
var providerLogOutput io.Writer
const (
loggerError = "Logger"
)
// SetProviderLogOutput ...
func SetProviderLogOutput(w io.Writer) {
os.Stderr = nil
os.Stdout = nil
log.SetOutput(w)
providerLogOutput = w
}
// New sets up a logger that writes to the stderr
func New(prefix string) *log.Logger {
var w io.Writer
if providerLogOutput != nil {
w = io.MultiWriter(stdErr, providerLogOutput)
} else {
w = stdErr
}
// we create our own stderr since we're going to nuke the existing one
return log.New(w, prefix, log.LstdFlags)
}