Skip to content

Commit

Permalink
Attempt to log still on template errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Meves committed Aug 9, 2020
1 parent 542bf1f commit 4522239
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
4 changes: 2 additions & 2 deletions oauthproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ func (p *OAuthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
func (p *OAuthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
redirect, err := p.GetRedirect(req)
if err != nil {
logger.Printf("Error obtaining redirect: %s", err.Error())
logger.Printf("Error obtaining redirect: %v", err)
p.ErrorPage(rw, http.StatusInternalServerError, "Internal Server Error", err.Error())
return
}
Expand All @@ -657,7 +657,7 @@ func (p *OAuthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
session := &sessionsapi.SessionState{User: user}
err = p.SaveSession(rw, req, session)
if err != nil {
logger.Printf("Error saving session: %s", err.Error())
logger.Printf("Error saving session: %v", err)
p.ErrorPage(rw, http.StatusInternalServerError, "Internal Server Error", err.Error())
return
}
Expand Down
28 changes: 25 additions & 3 deletions pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,15 @@ func (l *Logger) Output(calldepth int, message string) {
File: file,
Message: message,
})
// Fallback for template errors
if err != nil {
panic(err)
_, ferr := fmt.Fprintf(l.writer, "[%s] [%s] %s",
FormatTimestamp(now),
file,
message)
if ferr != nil {
panic(ferr)
}
}

_, err = l.writer.Write([]byte("\n"))
Expand Down Expand Up @@ -177,8 +184,17 @@ func (l *Logger) PrintAuthf(username string, req *http.Request, status AuthStatu
Status: string(status),
Message: fmt.Sprintf(format, a...),
})
// Fallback for template errors
if err != nil {
panic(err)
_, ferr := fmt.Fprintf(l.writer, "%s - %s [%s] [%s] %s",
client,
username,
FormatTimestamp(now),
string(status),
fmt.Sprintf(format, a...))
if ferr != nil {
panic(ferr)
}
}

_, err = l.writer.Write([]byte("\n"))
Expand Down Expand Up @@ -234,8 +250,14 @@ func (l *Logger) PrintReq(username, upstream string, req *http.Request, url url.
UserAgent: fmt.Sprintf("%q", req.UserAgent()),
Username: username,
})
// Fallback for template errors
if err != nil {
panic(err)
_, ferr := fmt.Fprintf(l.writer, "%s - %s [%s] %s %s %s %q %s %q %d %d %0.3f",
client, username, FormatTimestamp(ts), req.Host, req.Method, upstream,
url.RequestURI(), req.Proto, req.UserAgent(), status, size, duration)
if ferr != nil {
panic(ferr)
}
}

_, err = l.writer.Write([]byte("\n"))
Expand Down
7 changes: 1 addition & 6 deletions pkg/sessions/persistence/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ func (m *Manager) Save(rw http.ResponseWriter, req *http.Request, s *sessions.Se
return err
}

err = tckt.setCookie(rw, req, s)
if err != nil {
return err
}

return nil
return tckt.setCookie(rw, req, s)
}

// Load reads sessions.SessionState information from a session store. It will
Expand Down

0 comments on commit 4522239

Please sign in to comment.