-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.go
44 lines (38 loc) · 1018 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
// SPDX-FileCopyrightText: 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
package main
import (
"fmt"
"os"
"path"
"runtime"
"strings"
"github.com/sirupsen/logrus"
)
const (
fluentBitLogLevelEnvVar = "FLB_LOG_LEVEL"
)
/*
SetupLogger sets up Logrus with the log level determined by the Fluent Bit Env Var
https://github.com/aws/amazon-kinesis-firehose-for-fluent-bit/blob/mainline/plugins/plugins.go
*/
func SetupLogger() {
logrus.SetOutput(os.Stdout)
switch strings.ToUpper(os.Getenv(fluentBitLogLevelEnvVar)) {
default:
logrus.SetLevel(logrus.InfoLevel)
case "DEBUG":
logrus.SetLevel(logrus.DebugLevel)
logrus.SetReportCaller(true)
logrus.SetFormatter(&logrus.TextFormatter{
CallerPrettyfier: func(f *runtime.Frame) (string, string) {
return f.Function + "()", fmt.Sprintf("%s:%d", path.Base(f.File), f.Line)
},
})
case "INFO":
logrus.SetLevel(logrus.InfoLevel)
case "ERROR":
logrus.SetLevel(logrus.ErrorLevel)
}
}