forked from cyberark/conjur-api-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.go
42 lines (36 loc) · 842 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
package logging
import (
"io"
"os"
"github.com/sirupsen/logrus"
)
// ApiLog is a separate logrus logger for the API. The destination for
// its messages is controlled by the environment variable
// CONJURAPI_LOG. CONJRAPI_LOG can be "stdout", "stderr", or the path
// to a file. If it's a path, the file's contents will be overwritten
// with new messages.
var ApiLog = logrus.New()
func init() {
dest, ok := os.LookupEnv("CONJURAPI_LOG")
if !ok {
return
}
var (
out io.Writer
err error
)
switch dest {
case "stdout":
out = os.Stdout
case "stderr":
out = os.Stderr
default:
out, err = os.OpenFile(dest, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
logrus.Fatalf("Failed to open %s: %v", dest, err.Error())
}
logrus.Infof("Logging to %s", dest)
}
ApiLog.Out = out
ApiLog.Level = logrus.DebugLevel
}