Skip to content
Snippets Groups Projects
Commit a31c615d authored by Jano Hendriks's avatar Jano Hendriks
Browse files

Add log levels and time to logs

parent f7b8601b
Branches
Tags v1.190.0
No related merge requests found
......@@ -4,7 +4,9 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/MindscapeHQ/raygun4go"
log "github.com/sirupsen/logrus"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/date_utils"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/errors"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/string_utils"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/utils"
......@@ -17,11 +19,17 @@ import (
"runtime"
"strings"
"github.com/MindscapeHQ/raygun4go"
"github.com/aws/aws-lambda-go/events"
)
const (
FatalLevel = log.FatalLevel
ErrorLevel = log.ErrorLevel
WarnLevel = log.WarnLevel
InfoLevel = log.InfoLevel
DebugLevel = log.DebugLevel
)
type LogEntryWithLevel struct {
//LogBuffer *bytes.Buffer
LogEntry *log.Entry
......@@ -133,6 +141,10 @@ func InitLogs(requestID *string, isDebugBuild bool, buildVersion string, request
}
}
func SetLevel(logLevel log.Level) {
log.SetLevel(logLevel)
}
func LogLevel() log.Level {
logLevelString := os.Getenv("LOG_LEVEL")
......@@ -526,8 +538,10 @@ func storeLogEntry(logEntry *log.Entry, message interface{}, logLevel log.Level)
if logEntry != nil &&
logEntry.Logger != nil &&
logEntry.Logger.IsLevelEnabled(logLevel) {
logWithTime := logEntry.WithField("log_time", date_utils.CurrentDate())
cachedLogEntries = append(cachedLogEntries, LogEntryWithLevel{
LogEntry: logEntry,
LogEntry: logWithTime,
Message: message,
LogLevel: logLevel,
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment