Skip to content

Commit

Permalink
fix logging so as not to lose the source line ref
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmturner authored Feb 15, 2020
1 parent 3bfb2ad commit 4ba5599
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
7 changes: 5 additions & 2 deletions v8/client/settings.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package client

import "log"
import (
"fmt"
"log"
)

// Settings holds optional client settings.
type Settings struct {
Expand Down Expand Up @@ -64,6 +67,6 @@ func (s *Settings) Logger() *log.Logger {
// Log will write to the service's logger if it is configured.
func (cl *Client) Log(format string, v ...interface{}) {
if cl.settings.Logger() != nil {
cl.settings.Logger().Printf(format, v...)
cl.settings.Logger().Output(2, fmt.Sprintf(format, v...))
}
}
7 changes: 4 additions & 3 deletions v8/examples/example-AD.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@ func main() {
s := httpServer()
defer s.Close()
fmt.Printf("Listening on %s\n", s.URL)
l := log.New(os.Stderr, "GOKRB5 Client: ", log.Ldate|log.Ltime|log.Lshortfile)

b, _ := hex.DecodeString(testdata.TESTUSER1_USERKRB5_AD_KEYTAB)
kt := keytab.New()
kt.Unmarshal(b)
c, _ := config.NewFromString(testdata.TEST_KRB5CONF)
cl := client.NewWithKeytab("testuser1", "USER.GOKRB5", kt, c, client.DisablePAFXFAST(true))
cl := client.NewWithKeytab("testuser1", "USER.GOKRB5", kt, c, client.DisablePAFXFAST(true), client.Logger(l))
httpRequest(s.URL, cl)

b, _ = hex.DecodeString(testdata.TESTUSER2_USERKRB5_AD_KEYTAB)
kt = keytab.New()
kt.Unmarshal(b)
c, _ = config.NewFromString(testdata.TEST_KRB5CONF)
cl = client.NewWithKeytab("testuser2", "USER.GOKRB5", kt, c, client.DisablePAFXFAST(true))
cl = client.NewWithKeytab("testuser2", "USER.GOKRB5", kt, c, client.DisablePAFXFAST(true), client.Logger(l))
httpRequest(s.URL, cl)
}

Expand All @@ -48,7 +49,7 @@ func httpRequest(url string, cl *client.Client) {

err := cl.Login()
if err != nil {
l.Printf("Error on AS_REQ: %v\n", err)
l.Fatalf("Error on AS_REQ: %v\n", err)
}

spnegoCl := spnego.NewClient(cl, nil, "HTTP/host.res.gokrb5")
Expand Down
2 changes: 1 addition & 1 deletion v8/spnego/spnego.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (s *SPNEGO) AcceptSecContext(ct gssapi.ContextToken) (bool, context.Context
// Log will write to the service's logger if it is configured.
func (s *SPNEGO) Log(format string, v ...interface{}) {
if s.serviceSettings.Logger() != nil {
s.serviceSettings.Logger().Printf(format, v...)
s.serviceSettings.Logger().Output(2, fmt.Sprintf(format, v...))
}
}

Expand Down

0 comments on commit 4ba5599

Please sign in to comment.