Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
a31c615d
Commit
a31c615d
authored
1 year ago
by
Jano Hendriks
Browse files
Options
Downloads
Patches
Plain Diff
Add log levels and time to logs
parent
f7b8601b
Branches
Branches containing commit
Tags
v1.190.0
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
logs/logs.go
+17
-3
17 additions, 3 deletions
logs/logs.go
with
17 additions
and
3 deletions
logs/logs.go
+
17
−
3
View file @
a31c615d
...
...
@@ -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
:
log
Entry
,
LogEntry
:
log
WithTime
,
Message
:
message
,
LogLevel
:
logLevel
,
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment