Skip to content

Commit

Permalink
Fix: Go APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
mhd999 committed Feb 21, 2023
1 parent f160eae commit 5a6fb2c
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/telia-oss/rootle
go 1.18

require (
github.com/google/uuid v1.3.0
github.com/telia-oss/rootle/interceptor v0.0.0-20221026105925-b6b93b7b1e2b
google.golang.org/grpc v1.53.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/telia-oss/rootle/interceptor v0.0.0-20221026105925-b6b93b7b1e2b h1:5cVeYwZv1rq6tI328L7sTMLNfEkbr3MfQrhVG+TVT7E=
github.com/telia-oss/rootle/interceptor v0.0.0-20221026105925-b6b93b7b1e2b/go.mod h1:k275qThNlhdR5qbcoH2xOL1C/eV5dvIa+TkDVpjtBo8=
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
Expand Down
6 changes: 0 additions & 6 deletions go.work

This file was deleted.

2 changes: 0 additions & 2 deletions go.work.sum

This file was deleted.

15 changes: 10 additions & 5 deletions rootle.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import (
"encoding/json"
"log"
"time"

"github.com/google/uuid"
)

type Log struct {
ID string `json:"id"`
Application string `json:"application"`
Timestamp int64 `json:"timestamp"`
Message string `json:"message"`
Message any `json:"message"`
Level string `json:"level"`
Event *string `json:"event,omitempty"`
Downstream *Downstream `json:"downstream,omitempty"`
Expand Down Expand Up @@ -133,14 +135,17 @@ var localRootle *Config

func New(ctx context.Context, conf Config) *Config {
localRootle = &conf
if conf.ID == nil {
conf.ID = String(uuid.New().String())
}
return &conf
}

func GetRootle() *Config {
return localRootle
}

func logMessage(c Config, message string, level string, event *string, downstream *Downstream, stackTrace *string, code *int, callback func(logJSON string)) {
func logMessage(c Config, message any, level string, event *string, downstream *Downstream, stackTrace *string, code *int, callback func(logJSON string)) {
rootleLog := Log{
ID: *c.ID,
Application: *c.Application,
Expand All @@ -158,19 +163,19 @@ func logMessage(c Config, message string, level string, event *string, downstrea
callback(string(jsonLog))
}

func (c *Config) Info(message string) {
func (c *Config) Info(message any) {
logMessage(*c, message, "INFO", nil, nil, nil, nil, func(logJSON string) {
log.Println(logJSON)
})
}

func (c *Config) Warn(message string) {
func (c *Config) Warn(message any) {
logMessage(*c, message, "WARN", nil, nil, nil, nil, func(logJSON string) {
log.Println(logJSON)
})
}

func (c *Config) Error(message string, event *string, downstream *Downstream, stackTrace *string, code *int) {
func (c *Config) Error(message any, event *string, downstream *Downstream, stackTrace *string, code *int) {
logMessage(*c, message, "ERROR", event, downstream, stackTrace, code, func(logJSON string) {
log.Println(logJSON)
})
Expand Down

0 comments on commit 5a6fb2c

Please sign in to comment.