mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 16:26:38 +00:00
Initialize logging properly
This commit is contained in:
@@ -5,19 +5,22 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"syscall/js"
|
"syscall/js"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
netbird "github.com/netbirdio/netbird/client/embed"
|
netbird "github.com/netbirdio/netbird/client/embed"
|
||||||
"github.com/netbirdio/netbird/client/wasm/internal/http"
|
"github.com/netbirdio/netbird/client/wasm/internal/http"
|
||||||
"github.com/netbirdio/netbird/client/wasm/internal/rdp"
|
"github.com/netbirdio/netbird/client/wasm/internal/rdp"
|
||||||
"github.com/netbirdio/netbird/client/wasm/internal/ssh"
|
"github.com/netbirdio/netbird/client/wasm/internal/ssh"
|
||||||
|
"github.com/netbirdio/netbird/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
clientStartTimeout = 30 * time.Second
|
clientStartTimeout = 30 * time.Second
|
||||||
clientStopTimeout = 10 * time.Second
|
clientStopTimeout = 10 * time.Second
|
||||||
|
defaultLogLevel = "warn"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -27,11 +30,11 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func startClient(ctx context.Context, nbClient *netbird.Client) error {
|
func startClient(ctx context.Context, nbClient *netbird.Client) error {
|
||||||
log.Println("Starting NetBird client...")
|
log.Info("Starting NetBird client...")
|
||||||
if err := nbClient.Start(ctx); err != nil {
|
if err := nbClient.Start(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Println("NetBird client started successfully")
|
log.Info("NetBird client started successfully")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +42,7 @@ func startClient(ctx context.Context, nbClient *netbird.Client) error {
|
|||||||
func parseClientOptions(jsOptions js.Value) (netbird.Options, error) {
|
func parseClientOptions(jsOptions js.Value) (netbird.Options, error) {
|
||||||
options := netbird.Options{
|
options := netbird.Options{
|
||||||
DeviceName: "dashboard-client",
|
DeviceName: "dashboard-client",
|
||||||
LogLevel: "warn",
|
LogLevel: defaultLogLevel,
|
||||||
}
|
}
|
||||||
|
|
||||||
if jwtToken := jsOptions.Get("jwtToken"); !jwtToken.IsNull() && !jwtToken.IsUndefined() {
|
if jwtToken := jsOptions.Get("jwtToken"); !jwtToken.IsNull() && !jwtToken.IsUndefined() {
|
||||||
@@ -97,12 +100,12 @@ func createStopMethod(client *netbird.Client) js.Func {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
if err := client.Stop(ctx); err != nil {
|
if err := client.Stop(ctx); err != nil {
|
||||||
log.Printf("Error stopping client: %v", err)
|
log.Errorf("Error stopping client: %v", err)
|
||||||
reject.Invoke(js.ValueOf(err.Error()))
|
reject.Invoke(js.ValueOf(err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("NetBird client stopped")
|
log.Info("NetBird client stopped")
|
||||||
resolve.Invoke(js.ValueOf(true))
|
resolve.Invoke(js.ValueOf(true))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -132,7 +135,7 @@ func createSSHMethod(client *netbird.Client) js.Func {
|
|||||||
|
|
||||||
if err := sshClient.StartSession(80, 24); err != nil {
|
if err := sshClient.StartSession(80, 24); err != nil {
|
||||||
if closeErr := sshClient.Close(); closeErr != nil {
|
if closeErr := sshClient.Close(); closeErr != nil {
|
||||||
log.Printf("Error closing SSH client: %v", closeErr)
|
log.Errorf("Error closing SSH client: %v", closeErr)
|
||||||
}
|
}
|
||||||
reject.Invoke(err.Error())
|
reject.Invoke(err.Error())
|
||||||
return
|
return
|
||||||
@@ -219,7 +222,11 @@ func netBirdClientConstructor(this js.Value, args []js.Value) any {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Creating NetBird client with options: deviceName=%s, hasJWT=%v, hasSetupKey=%v, mgmtURL=%s",
|
if err := util.InitLog(options.LogLevel, util.LogConsole); err != nil {
|
||||||
|
log.Warnf("Failed to initialize logging: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("Creating NetBird client with options: deviceName=%s, hasJWT=%v, hasSetupKey=%v, mgmtURL=%s",
|
||||||
options.DeviceName, options.JWTToken != "", options.SetupKey != "", options.ManagementURL)
|
options.DeviceName, options.JWTToken != "", options.SetupKey != "", options.ManagementURL)
|
||||||
|
|
||||||
client, err := netbird.New(options)
|
client, err := netbird.New(options)
|
||||||
@@ -229,7 +236,7 @@ func netBirdClientConstructor(this js.Value, args []js.Value) any {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clientObj := createClientObject(client)
|
clientObj := createClientObject(client)
|
||||||
log.Println("NetBird client created successfully")
|
log.Info("NetBird client created successfully")
|
||||||
resolve.Invoke(clientObj)
|
resolve.Invoke(clientObj)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ package http
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
log "github.com/sirupsen/logrus"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall/js"
|
"syscall/js"
|
||||||
@@ -39,7 +39,7 @@ func performRequest(nbClient *netbird.Client, method, url string, headers map[st
|
|||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := resp.Body.Close(); err != nil {
|
if err := resp.Body.Close(); err != nil {
|
||||||
log.Printf("failed to close response body: %v", err)
|
log.Errorf("failed to close response body: %v", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user