mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-16 07:16:38 +00:00
Add context to throughout the project and update logging (#2209)
propagate context from all the API calls and log request ID, account ID and peer ID --------- Co-authored-by: Zoltan Papp <zoltan.pmail@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"os"
|
||||
@@ -57,7 +58,7 @@ func WriteJson(file string, obj interface{}) error {
|
||||
}
|
||||
|
||||
// DirectWriteJson writes JSON config object to a file creating parent directories if required without creating a temporary file
|
||||
func DirectWriteJson(file string, obj interface{}) error {
|
||||
func DirectWriteJson(ctx context.Context, file string, obj interface{}) error {
|
||||
|
||||
_, _, err := prepareConfigFileDir(file)
|
||||
if err != nil {
|
||||
|
||||
@@ -27,7 +27,6 @@ func WithCustomDialer() grpc.DialOption {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
conn, err := nbnet.NewDialer().DialContext(ctx, "tcp", addr)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to dial: %s", err)
|
||||
|
||||
@@ -2,6 +2,7 @@ package util
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -30,7 +31,11 @@ func InitLog(logLevel string, logPath string) error {
|
||||
log.SetOutput(io.Writer(lumberjackLogger))
|
||||
}
|
||||
|
||||
formatter.SetTextFormatter(log.StandardLogger())
|
||||
if os.Getenv("NB_LOG_FORMAT") == "json" {
|
||||
formatter.SetJSONFormatter(log.StandardLogger())
|
||||
} else {
|
||||
formatter.SetTextFormatter(log.StandardLogger())
|
||||
}
|
||||
log.SetLevel(level)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user