From d62e1f7b8f7818cf15884ab6485febde8931c9ea Mon Sep 17 00:00:00 2001 From: Gregory Wells Date: Tue, 24 Mar 2026 18:08:36 -0400 Subject: [PATCH] Debug connecting to the LDAP server --- src/logging/logging.go | 29 ++++++++++++++++++++++++++++- src/main/ldap.go | 9 ++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/logging/logging.go b/src/logging/logging.go index 0625178..c74686e 100644 --- a/src/logging/logging.go +++ b/src/logging/logging.go @@ -1,6 +1,9 @@ package logging -import "log" +import ( + "fmt" + "log" +) type EventType int @@ -16,6 +19,30 @@ func Infof(message string, vars ...any) { log.Printf(message, vars...) } +func Debug(message string) { + log.Printf("Warn: %s", message) +} + +func Debugf(message string, v ...any) { + log.Printf("Warn: %s", fmt.Sprintf(message, v...)) +} + +func Warn(message string) { + log.Printf("Warn: %s", message) +} + +func Warnf(message string, v ...any) { + log.Printf("Warn: %s", fmt.Sprintf(message, v...)) +} + +func Error(message string) { + log.Printf("Error: %s", message) +} + +func Errorf(message string, v ...any) { + log.Printf("Error: %s", fmt.Sprintf(message, v...)) +} + func Fatal(message string) { log.Fatal(message) } diff --git a/src/main/ldap.go b/src/main/ldap.go index 3acf6f1..1a0916c 100644 --- a/src/main/ldap.go +++ b/src/main/ldap.go @@ -5,6 +5,7 @@ import ( "errors" "log" + "astraltech.xyz/accountmanager/src/logging" "github.com/go-ldap/ldap/v3" ) @@ -21,15 +22,21 @@ type LDAPSearch struct { } func connectToLDAPServer(URL string, starttls bool, ignore_cert bool) (*LDAPServer, error) { + logging.Debugf("Connecting to LDAP server %s", URL) l, err := ldap.DialURL(URL) if err != nil { + logging.Fatal("Failed to connect to LDAP server") + logging.Fatal(err.Error()) return nil, err } + logging.Infof("Connected to LDAP server") if starttls { + logging.Debugf("Enabling StartTLS") if err := l.StartTLS(&tls.Config{InsecureSkipVerify: ignore_cert}); err != nil { - log.Println("StartTLS failed:", err) + logging.Errorf("StartTLS failed %s", err.Error()) } + logging.Infof("StartTLS enabled") } return &LDAPServer{