Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change level of errors in log #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed
- Changed level of errors in log

## [0.5.2] - 2024-06-18

### Added
Expand Down
9 changes: 5 additions & 4 deletions internal/cli/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/goverland-labs/goverland-datasource-snapshot/internal/db"
"github.com/goverland-labs/goverland-datasource-snapshot/internal/helpers"
"github.com/goverland-labs/goverland-datasource-snapshot/internal/logger"
)

const (
Expand Down Expand Up @@ -123,7 +124,7 @@ func (c *Import) Execute(args Arguments) error {
}

if err != nil {
log.Error().Err(err).Msgf("upsert %s: %d: %s", importType, idx, line[0])
logger.Critical(err).Msgf("upsert %s: %d: %s", importType, idx, line[0])
}
}

Expand Down Expand Up @@ -305,7 +306,7 @@ func prepareChoice(str string) json.RawMessage {
func getTimeFromString(val string) time.Time {
i, err := strconv.ParseInt(val, 10, 64)
if err != nil {
log.Error().Err(err).Msgf("convert %s to int", val)
log.Warn().Err(err).Msgf("convert %s to int", val)
return time.Now()
}

Expand All @@ -315,7 +316,7 @@ func getTimeFromString(val string) time.Time {
func getUnixFromString(val string) int64 {
i, err := strconv.ParseInt(val, 10, 64)
if err != nil {
log.Error().Err(err).Msgf("convert %s to int", val)
log.Warn().Err(err).Msgf("convert %s to int", val)
return 0
}

Expand All @@ -324,7 +325,7 @@ func getUnixFromString(val string) int64 {
func getFloat64FromString(val string) float64 {
i, err := strconv.ParseFloat(val, 64)
if err != nil {
log.Error().Err(err).Msgf("convert %s to float", val)
log.Warn().Err(err).Msgf("convert %s to float", val)
return 0
}

Expand Down
4 changes: 2 additions & 2 deletions internal/db/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"time"

"github.com/goverland-labs/goverland-platform-events/events/ipfs"
"github.com/rs/zerolog/log"
"gorm.io/gorm"
"gorm.io/gorm/clause"

"github.com/goverland-labs/goverland-datasource-snapshot/internal/helpers"
"github.com/goverland-labs/goverland-datasource-snapshot/internal/logger"
)

const (
Expand Down Expand Up @@ -165,7 +165,7 @@ func (s *MessageService) Upsert(message ...*Message) error {
IpfsID: msg.IpfsID,
Type: string(msg.Type),
}); err != nil {
log.Error().Err(err).Msg("Failed to publish message")
logger.Critical(err).Msg("failed to publish message")
}
}

Expand Down
7 changes: 6 additions & 1 deletion internal/logger/logger.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package logger

import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/s-larionov/process-manager"
)
Expand All @@ -13,7 +14,7 @@ func (l *ProcessManagerLogger) Info(msg string, fields ...process.LogFields) {
}

func (l *ProcessManagerLogger) Error(msg string, err error, fields ...process.LogFields) {
log.Error().Err(err).Fields(convertFields(fields)).Msg(msg)
Critical(err).Fields(convertFields(fields)).Msg(msg)
}

func convertFields(fields []process.LogFields) map[string]interface{} {
Expand All @@ -23,3 +24,7 @@ func convertFields(fields []process.LogFields) map[string]interface{} {

return fields[0]
}

func Critical(err error) *zerolog.Event {
return log.Error().Err(err).Str("severity", "CRITICAL")
}
6 changes: 3 additions & 3 deletions internal/updates/delete_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (c *DeleteProposalConsumer) stop() error {
}

if err := c.con.Close(); err != nil {
log.Error().Err(err).Msg("unable to close delete proposal consumer")
log.Warn().Err(err).Msg("unable to close delete proposal consumer")

return err
}
Expand All @@ -87,13 +87,13 @@ func (c *DeleteProposalConsumer) handler() pevents.MessageHandler {

proposalID, err := c.fc.GetDeletedProposalIDByIpfsID(context.Background(), payload.IpfsID)
if err != nil {
log.Error().Err(err).Msg("getting deleted proposal ipfs data")
log.Warn().Err(err).Msg("getting deleted proposal ipfs data")

return err
}

if err = c.proposals.Delete([]string{proposalID}); err != nil {
log.Error().Err(err).Msg("process deleted proposal message")
log.Warn().Err(err).Msg("process deleted proposal message")

return err
}
Expand Down
3 changes: 2 additions & 1 deletion internal/updates/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/goverland-labs/goverland-datasource-snapshot/internal/db"
"github.com/goverland-labs/goverland-datasource-snapshot/internal/helpers"
"github.com/goverland-labs/goverland-datasource-snapshot/internal/logger"
)

const (
Expand Down Expand Up @@ -189,7 +190,7 @@ func (w *ProposalWorker) getLastProposalCreatedAt() time.Time {

lastProposal, err := w.proposals.GetLatestProposal()
if err != nil {
log.Error().Err(err).Msg("unable to get last fetched proposal")
logger.Critical(err).Msg("unable to get last fetched proposal")
return createdAfter
}

Expand Down
4 changes: 2 additions & 2 deletions internal/updates/votes.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func (w *VoteWorker) getLastVoteCreatedAtByProposal(proposalID string) time.Time

lastVote, err := w.votes.GetLatestVoteByProposal(proposalID)
if err != nil {
log.Error().Err(err).Msg("unable to get last fetched proposal")
log.Warn().Err(err).Msg("unable to get last fetched vote for proposal")
return createdAfter
}

Expand All @@ -330,7 +330,7 @@ func (w *VoteWorker) getLastVoteCreatedAtByProposal(proposalID string) time.Time
func (w *VoteWorker) getLastVoteCreatedAt() time.Time {
lastVote, err := w.votes.GetLatestVote()
if err != nil {
log.Error().Err(err).Msg("unable to get last fetched proposal")
log.Warn().Err(err).Msg("unable to get last fetched proposal")

return time.Now()
}
Expand Down
2 changes: 1 addition & 1 deletion internal/voting/action_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func getSnapshot(snapshot *string) any {

numSnapshot, err := strconv.Atoi(*snapshot)
if err != nil {
log.Error().Err(err).Msg("failed to convert snapshot to int")
log.Warn().Err(err).Msg("failed to convert snapshot to int")

return latestSnapshot
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/health/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func DefaultHandler(manager *process.Manager) http.Handler {

body, err := json.Marshal(resp)
if err != nil {
log.Error().Err(err).Msg("unable to marshal health check")
log.Warn().Err(err).Msg("unable to marshal health check")
w.WriteHeader(http.StatusInternalServerError)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/middleware/panic.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func PanicLog(w http.ResponseWriter, r *http.Request) {

body, _ := io.ReadAll(r.Body)

log.Error().Fields(map[string]interface{}{
log.Error().Str("severity", "CRITICAL").Fields(map[string]interface{}{
"request": fmt.Sprintf("%s %s?%s", r.Method, r.URL.String(), r.URL.Query().Encode()),
"body": string(body),
"stack": string(debug.Stack()),
Expand Down