logger and first client

This commit is contained in:
Pascal Fischer 2023-09-21 16:42:44 +02:00
parent 6743054451
commit 8653c32367
2 changed files with 35 additions and 7 deletions

View File

@ -61,27 +61,24 @@ type Client struct {
ctxCancelLock *sync.Mutex
deviceName string
routeListener routemanager.RouteListener
logger CustomLogger
onHostDnsFn func([]string)
}
// NewClient instantiate a new Client
func NewClient(cfgFile, deviceName string, iFaceDiscover IFaceDiscover, routeListener RouteListener, logger CustomLogger) *Client {
func NewClient(cfgFile, deviceName string, iFaceDiscover IFaceDiscover, routeListener RouteListener) *Client {
return &Client{
cfgFile: cfgFile,
deviceName: deviceName,
iFaceDiscover: iFaceDiscover,
recorder: peer.NewRecorder(""),
ctxCancelLock: &sync.Mutex{},
logger: logger,
routeListener: routeListener,
}
}
// Run start the internal client. It is a blocker function
// func (c *Client) Run(fd int32, dns *DNSList, dnsReadyListener DnsReadyListener) error {
func (c *Client) Run(fd int32, dns *DNSList, dnsReadyListener DnsReadyListener) error {
c.logger.Info("Starting NetBird client")
log.Infof("Starting NetBird client")
cfg, err := internal.UpdateOrCreateConfig(internal.ConfigInput{
ConfigPath: c.cfgFile,
})
@ -100,12 +97,12 @@ func (c *Client) Run(fd int32, dns *DNSList, dnsReadyListener DnsReadyListener)
auth := NewAuthWithConfig(ctx, cfg)
// err = auth.login(urlOpener)
auth.loginWithSetupKeyAndSaveConfig("E9EEBA50-76A1-4C72-A939-C10655C1CC09", "iPhone")
auth.loginWithSetupKeyAndSaveConfig("C3803F45-435B-4333-96EB-50F9EC723355", "iPhone")
if err != nil {
return err
}
c.logger.Info("Auth successful")
log.Infof("Auth successful")
// todo do not throw error in case of cancelled context
ctx = internal.CtxInitState(ctx)
c.onHostDnsFn = func([]string) {}

View File

@ -0,0 +1,31 @@
package netbird
import (
"os"
"github.com/netbirdio/netbird/util"
)
var logFile *os.File
// InitializeLog initializes the log file.
func InitializeLog(logLevel string, filePath string) error {
var err error
err = util.InitLog(logLevel, filePath)
return err
}
// // CloseLog closes the log file.
// func CloseLog() {
// if logFile != nil {
// logFile.Close()
// }
// }
//
// // Log writes a message to the log file.
// func Log(message string) {
// if logFile != nil {
// ts := time.Now().Format(time.RFC3339)
// fmt.Fprintf(logFile, "%s: %s\n", ts, message)
// }
// }