Skip to content

Commit

Permalink
Improved logging
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxW1337 committed Nov 19, 2021
1 parent faca2dc commit 3936c33
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ func respondWithText(w http.ResponseWriter, code int, payload string) {

// RespondWithError standardizes error messages, through the use of RespondWithJSON.
func respondWithError(w http.ResponseWriter, code int, message string) {
fmt.Println(message)
log.Info(message)
respondWithJSON(w, code, map[string]string{"error": message})
}

func (a *App) pullToken(w http.ResponseWriter, r *http.Request) {
if a.authToken != "" {
authHeader := r.Header.Get(headerAuthorization)
if authHeader != fmt.Sprintf("Bearer %s", a.authToken) {
log.Debugf("Invalid auth token provided: %s", authHeader)
log.Infof("Invalid auth token provided: %s", authHeader)
respondWithError(w, http.StatusForbidden, "Invalid authorization header")
return
}
Expand Down Expand Up @@ -122,5 +122,6 @@ func (a *App) pullToken(w http.ResponseWriter, r *http.Request) {
respondWithError(w, http.StatusInternalServerError, err.Error())
}

log.Infof("Successfully fetched logintoken for appid %d with memo %s", appID, vars["memo"])
respondWithText(w, http.StatusOK, account.LoginToken)
}
2 changes: 1 addition & 1 deletion src/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func init() {
var config = zap.NewProductionConfig()
config.Level = zap.NewAtomicLevelAt(zap.InfoLevel)
config.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
config.EncoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
l, err := config.Build()
if err != nil {
fmt.Printf("Error happened initializing logger: %+v", err)
Expand Down

0 comments on commit 3936c33

Please sign in to comment.