Skip to content

Commit

Permalink
[logs] added some log tags and removed unneeded logs (#1674)
Browse files Browse the repository at this point in the history
* logs: removed auth logs since they crowded logs

* logs: removed feed logs

* logs: added log tags for workspace logs

* logs: added feed tag to feed.go file

* logs: added auth tag to handlers/auth.go

* logs: added bounty tag to logs in handlers/bounty.go
  • Loading branch information
kevkevinpal authored May 29, 2024
1 parent fd13cf2 commit 809c433
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 98 deletions.
7 changes: 0 additions & 7 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ func PubKeyContext(next http.Handler) http.Handler {
if token == "" {
token = r.Header.Get("x-jwt")
}
fmt.Println("PubKeyContext Token:")
fmt.Println(token)

if token == "" {
fmt.Println("[auth] no token")
Expand All @@ -50,8 +48,6 @@ func PubKeyContext(next http.Handler) http.Handler {

isJwt := strings.Contains(token, ".") && !strings.HasPrefix(token, ".")

fmt.Println("Checking if JWT: ")
fmt.Println(isJwt)
if isJwt {
claims, err := DecodeJwt(token)

Expand All @@ -67,14 +63,11 @@ func PubKeyContext(next http.Handler) http.Handler {
return
}

fmt.Println("Passed jwt check")
ctx := context.WithValue(r.Context(), ContextKey, claims["pubkey"])
next.ServeHTTP(w, r.WithContext(ctx))
} else {
pubkey, err := VerifyTribeUUID(token, true)

fmt.Println("Checking pubkey and error: ")
fmt.Println(pubkey)
if pubkey == "" || err != nil {
fmt.Println("[auth] no pubkey || err != nil")
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions feeds/podcastindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func EpisodeToGeneric(ep Episode, includeFeedStuff bool) Item {

func PodcastToGeneric(url string, p *Podcast) (Feed, error) {
items := []Item{}
// fmt.Println("P EPISODES", len(p.Episodes), p)
for _, ep := range p.Episodes {
items = append(items, EpisodeToGeneric(ep, false))
}
Expand Down Expand Up @@ -80,7 +79,6 @@ func PodcastIndexHeaders() map[string]string {

func ParsePodcastFeed(url string, fulltext bool) (*Feed, error) {
pod, err := PodcastFeed(url, fulltext)
fmt.Println("GOT A POD!", pod)
if err != nil || pod == nil {
return nil, err
}
Expand Down
14 changes: 7 additions & 7 deletions handlers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ func (ah *authHandler) CreateConnectionCode(w http.ResponseWriter, r *http.Reque
}

if err != nil {
fmt.Println(err)
fmt.Println("[auth]", err)
w.WriteHeader(http.StatusNotAcceptable)
return
}

_, err = ah.db.CreateConnectionCode(codeArr)

if err != nil {
fmt.Println("=> ERR create connection code", err)
fmt.Println("[auth] => ERR create connection code", err)
w.WriteHeader(http.StatusBadRequest)
return
}
Expand Down Expand Up @@ -131,7 +131,7 @@ func ReceiveLnAuthData(w http.ResponseWriter, r *http.Request) {

exVerify, err := auth.VerifyDerSig(sig, k1, userKey)
if err != nil || !exVerify {
fmt.Println("Error signing signature")
fmt.Println("[auth] Error signing signature")
w.WriteHeader(http.StatusUnauthorized)
json.NewEncoder(w).Encode(err.Error())
return
Expand All @@ -150,7 +150,7 @@ func ReceiveLnAuthData(w http.ResponseWriter, r *http.Request) {
tokenString, err := auth.EncodeJwt(userKey)

if err != nil {
fmt.Println("error creating LNAUTH JWT")
fmt.Println("[auth] error creating LNAUTH JWT")
w.WriteHeader(http.StatusNotAcceptable)
json.NewEncoder(w).Encode(err.Error())
return
Expand All @@ -174,7 +174,7 @@ func ReceiveLnAuthData(w http.ResponseWriter, r *http.Request) {
socket.Conn.WriteJSON(socketMsg)
db.Store.DeleteCache(k1[0:20])
} else {
fmt.Println("Socket Error", err)
fmt.Println("[auth] Socket Error", err)
}

responseMsg["status"] = "OK"
Expand All @@ -194,7 +194,7 @@ func (ah *authHandler) RefreshToken(w http.ResponseWriter, r *http.Request) {
claims, err := ah.decodeJwt(token)

if err != nil {
fmt.Println("Failed to parse JWT")
fmt.Println("[auth] Failed to parse JWT")
w.WriteHeader(http.StatusUnauthorized)
json.NewEncoder(w).Encode(err.Error())
return
Expand All @@ -209,7 +209,7 @@ func (ah *authHandler) RefreshToken(w http.ResponseWriter, r *http.Request) {
tokenString, err := ah.encodeJwt(pubkey)

if err != nil {
fmt.Println("error creating refresh JWT")
fmt.Println("[auth] error creating refresh JWT")
w.WriteHeader(http.StatusNotAcceptable)
json.NewEncoder(w).Encode(err.Error())
return
Expand Down
66 changes: 33 additions & 33 deletions handlers/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (h *bountyHandler) GetBountyById(w http.ResponseWriter, r *http.Request) {
bounties, err := h.db.GetBountyById(bountyId)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
fmt.Println("[bounty] Error", err)
} else {
var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties)
w.WriteHeader(http.StatusOK)
Expand All @@ -69,7 +69,7 @@ func (h *bountyHandler) GetNextBountyByCreated(w http.ResponseWriter, r *http.Re
bounties, err := h.db.GetNextBountyByCreated(r)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
fmt.Println("[bounty] Error", err)
} else {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bounties)
Expand All @@ -80,7 +80,7 @@ func (h *bountyHandler) GetPreviousBountyByCreated(w http.ResponseWriter, r *htt
bounties, err := h.db.GetPreviousBountyByCreated(r)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
fmt.Println("[bounty] Error", err)
} else {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bounties)
Expand All @@ -91,7 +91,7 @@ func (h *bountyHandler) GetWorkspaceNextBountyByCreated(w http.ResponseWriter, r
bounties, err := h.db.GetNextWorkspaceBountyByCreated(r)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
fmt.Println("[bounty] Error", err)
} else {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bounties)
Expand All @@ -102,7 +102,7 @@ func (h *bountyHandler) GetWorkspacePreviousBountyByCreated(w http.ResponseWrite
bounties, err := h.db.GetPreviousWorkspaceBountyByCreated(r)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
fmt.Println("[bounty] Error", err)
} else {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bounties)
Expand All @@ -127,7 +127,7 @@ func (h *bountyHandler) GetBountyByCreated(w http.ResponseWriter, r *http.Reques
bounties, err := h.db.GetBountyDataByCreated(created)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
fmt.Println("[bounty] Error", err)
} else {
var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties)

Expand Down Expand Up @@ -159,7 +159,7 @@ func (h *bountyHandler) GetPersonCreatedBounties(w http.ResponseWriter, r *http.
bounties, err := h.db.GetCreatedBounties(r)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
fmt.Println("[bounty] Error", err)
} else {
var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties)
w.WriteHeader(http.StatusOK)
Expand All @@ -171,7 +171,7 @@ func (h *bountyHandler) GetPersonAssignedBounties(w http.ResponseWriter, r *http
bounties, err := h.db.GetAssignedBounties(r)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Println("Error", err)
fmt.Println("[bounty] Error", err)
} else {
var bountyResponse []db.BountyResponse = h.GenerateBountyResponse(bounties)
w.WriteHeader(http.StatusOK)
Expand All @@ -189,7 +189,7 @@ func (h *bountyHandler) CreateOrEditBounty(w http.ResponseWriter, r *http.Reques
r.Body.Close()
err = json.Unmarshal(body, &bounty)
if err != nil {
fmt.Println(err)
fmt.Println("[bounty]", err)
w.WriteHeader(http.StatusNotAcceptable)
return
}
Expand Down Expand Up @@ -253,14 +253,14 @@ func (h *bountyHandler) CreateOrEditBounty(w http.ResponseWriter, r *http.Reques
hasBountyRoles := h.userHasManageBountyRoles(pubKeyFromAuth, bounty.WorkspaceUuid)
if !hasBountyRoles {
msg := "You don't have a=the right permission ton update bounty"
fmt.Println(msg)
fmt.Println("[bounty]", msg)
w.WriteHeader(http.StatusBadRequest)
json.NewEncoder(w).Encode(msg)
return
}
} else {
msg := "Cannot edit another user's bounty"
fmt.Println(msg)
fmt.Println("[bounty]", msg)
w.WriteHeader(http.StatusBadRequest)
json.NewEncoder(w).Encode(msg)
return
Expand All @@ -284,7 +284,7 @@ func (h *bountyHandler) CreateOrEditBounty(w http.ResponseWriter, r *http.Reques

b, err := h.db.CreateOrEditBounty(bounty)
if err != nil {
fmt.Println(err)
fmt.Println("[bounty]", err)
w.WriteHeader(http.StatusBadRequest)
return
}
Expand All @@ -298,7 +298,7 @@ func (h *bountyHandler) DeleteBounty(w http.ResponseWriter, r *http.Request) {
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)

if pubKeyFromAuth == "" {
fmt.Println("no pubkey from auth")
fmt.Println("[bounty] no pubkey from auth")
w.WriteHeader(http.StatusUnauthorized)
return
}
Expand All @@ -307,19 +307,19 @@ func (h *bountyHandler) DeleteBounty(w http.ResponseWriter, r *http.Request) {
pubkey := chi.URLParam(r, "pubkey")

if pubkey == "" {
fmt.Println("no pubkey from route")
fmt.Println("[bounty] no pubkey from route")
w.WriteHeader(http.StatusUnauthorized)
return
}
if created == "" {
fmt.Println("no created timestamp from route")
fmt.Println("[bounty] no created timestamp from route")
w.WriteHeader(http.StatusUnauthorized)
return
}

b, err := h.db.DeleteBounty(pubkey, created)
if err != nil {
fmt.Println("failed to delete bounty", err.Error())
fmt.Println("[bounty] failed to delete bounty", err.Error())
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode("failed to delete bounty")
return
Expand Down Expand Up @@ -470,14 +470,14 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request

id, err := utils.ConvertStringToUint(idParam)
if err != nil {
fmt.Println("could not parse id")
fmt.Println("[bounty] could not parse id")
w.WriteHeader(http.StatusForbidden)
h.m.Unlock()
return
}

if pubKeyFromAuth == "" {
fmt.Println("no pubkey from auth")
fmt.Println("[bounty] no pubkey from auth")
w.WriteHeader(http.StatusUnauthorized)
h.m.Unlock()
return
Expand Down Expand Up @@ -530,7 +530,7 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request

err = json.Unmarshal(body, &request)
if err != nil {
fmt.Println(err)
fmt.Println("[bounty]", err)
w.WriteHeader(http.StatusNotAcceptable)
h.m.Unlock()
return
Expand All @@ -546,11 +546,11 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request
req, _ := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(jsonBody))
req.Header.Set("x-user-token", config.RelayAuthKey)
req.Header.Set("Content-Type", "application/json")
log.Printf("Making Bounty Payment: amount: %d, pubkey: %s, route_hint: %s", amount, assignee.OwnerPubKey, assignee.OwnerRouteHint)
log.Printf("[bounty] Making Bounty Payment: amount: %d, pubkey: %s, route_hint: %s", amount, assignee.OwnerPubKey, assignee.OwnerRouteHint)
res, err := h.httpClient.Do(req)

if err != nil {
log.Printf("Request Failed: %s", err)
log.Printf("[bounty] Request Failed: %s", err)
h.m.Unlock()
return
}
Expand Down Expand Up @@ -613,7 +613,7 @@ func (h *bountyHandler) BountyBudgetWithdraw(w http.ResponseWriter, r *http.Requ
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)

if pubKeyFromAuth == "" {
fmt.Println("no pubkey from auth")
fmt.Println("[bounty] no pubkey from auth")
w.WriteHeader(http.StatusUnauthorized)
h.m.Unlock()
return
Expand All @@ -630,7 +630,7 @@ func (h *bountyHandler) BountyBudgetWithdraw(w http.ResponseWriter, r *http.Requ
return
}

log.Printf("[BountyBudgetWithdraw] Logging body: orguuid: %s, pubkey: %s, invoice: %s", request.OrgUuid, pubKeyFromAuth, request.PaymentRequest)
log.Printf("[bounty] [BountyBudgetWithdraw] Logging body: orguuid: %s, pubkey: %s, invoice: %s", request.OrgUuid, pubKeyFromAuth, request.PaymentRequest)

// check if user is the admin of the workspace
// or has a withdraw bounty budget role
Expand Down Expand Up @@ -683,7 +683,7 @@ func (h *bountyHandler) NewBountyBudgetWithdraw(w http.ResponseWriter, r *http.R
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)

if pubKeyFromAuth == "" {
fmt.Println("no pubkey from auth")
fmt.Println("[bounty] no pubkey from auth")
w.WriteHeader(http.StatusUnauthorized)
h.m.Unlock()
return
Expand Down Expand Up @@ -760,7 +760,7 @@ func (h *bountyHandler) GetLightningInvoice(payment_request string) (db.InvoiceR
res, _ := h.httpClient.Do(req)

if err != nil {
log.Printf("Request Failed: %s", err)
log.Printf("[bounty] Request Failed: %s", err)
return db.InvoiceResult{}, db.InvoiceError{}
}

Expand All @@ -774,7 +774,7 @@ func (h *bountyHandler) GetLightningInvoice(payment_request string) (db.InvoiceR
err = json.Unmarshal(body, &invoiceErr)

if err != nil {
log.Printf("Reading Invoice body failed: %s", err)
log.Printf("[bounty] Reading Invoice body failed: %s", err)
return db.InvoiceResult{}, invoiceErr
}

Expand All @@ -785,7 +785,7 @@ func (h *bountyHandler) GetLightningInvoice(payment_request string) (db.InvoiceR
err = json.Unmarshal(body, &invoiceRes)

if err != nil {
log.Printf("Reading Invoice body failed: %s", err)
log.Printf("[bounty] Reading Invoice body failed: %s", err)
return invoiceRes, db.InvoiceError{}
}

Expand All @@ -805,7 +805,7 @@ func (h *bountyHandler) PayLightningInvoice(payment_request string) (db.InvoiceP
res, err := h.httpClient.Do(req)

if err != nil {
log.Printf("Request Failed: %s", err)
log.Printf("[bounty] Request Failed: %s", err)
return db.InvoicePaySuccess{}, db.InvoicePayError{}
}

Expand All @@ -818,7 +818,7 @@ func (h *bountyHandler) PayLightningInvoice(payment_request string) (db.InvoiceP
err = json.Unmarshal(body, &invoiceError)

if err != nil {
log.Printf("Reading Invoice pay error body failed: %s", err)
log.Printf("[bounty] Reading Invoice pay error body failed: %s", err)
return db.InvoicePaySuccess{}, db.InvoicePayError{}
}

Expand All @@ -828,7 +828,7 @@ func (h *bountyHandler) PayLightningInvoice(payment_request string) (db.InvoiceP
err = json.Unmarshal(body, &invoiceSuccess)

if err != nil {
log.Printf("Reading Invoice pay success body failed: %s", err)
log.Printf("[bounty] Reading Invoice pay success body failed: %s", err)
return db.InvoicePaySuccess{}, db.InvoicePayError{}
}

Expand Down Expand Up @@ -857,7 +857,7 @@ func (h *bountyHandler) PollInvoice(w http.ResponseWriter, r *http.Request) {
var err error

if pubKeyFromAuth == "" {
fmt.Println("no pubkey from auth")
fmt.Println("[bounty] no pubkey from auth")
w.WriteHeader(http.StatusUnauthorized)
return
}
Expand Down Expand Up @@ -896,7 +896,7 @@ func (h *bountyHandler) PollInvoice(w http.ResponseWriter, r *http.Request) {
res, _ := h.httpClient.Do(req)

if err != nil {
log.Printf("Request Failed: %s", err)
log.Printf("[bounty] Request Failed: %s", err)
return
}

Expand Down Expand Up @@ -925,7 +925,7 @@ func (h *bountyHandler) PollInvoice(w http.ResponseWriter, r *http.Request) {
// Unmarshal result
keysendError := db.KeysendError{}
err = json.Unmarshal(body, &keysendError)
log.Printf("Keysend Payment to %s Failed, with Error: %s", invData.UserPubkey, keysendError.Error)
log.Printf("[bounty] Keysend Payment to %s Failed, with Error: %s", invData.UserPubkey, keysendError.Error)
}
}
// Update the invoice status
Expand Down
Loading

0 comments on commit 809c433

Please sign in to comment.