Skip to content

Commit

Permalink
Add option to disable db logs for test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaBernstein committed Dec 18, 2021
1 parent 77532d4 commit b613a04
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions db/crud/logger.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package crud

import (
"log"

"github.com/LucaBernstein/beancount-bot-tg/helpers"
tb "gopkg.in/tucnak/telebot.v2"
)

var TEST_MODE = false

func LogDbf(r *Repo, level helpers.Level, m *tb.Message, format string, v ...interface{}) {
prefix, message := helpers.LogLocalf(level, m, format, v...)
go logToDb(r, prefix, level, message)
Expand All @@ -17,8 +21,12 @@ func logToDb(r *Repo, chat string, level helpers.Level, message string) {
} else {
values = append(values, nil)
}
_, err := r.db.Exec(`INSERT INTO "app::log" ("level", "message", "chat") VALUES ($1, $2, $3)`, values...)
if err != nil {
helpers.LogLocalf(helpers.ERROR, nil, "Error inserting log statement into db: %s", err.Error())
if !TEST_MODE {
_, err := r.db.Exec(`INSERT INTO "app::log" ("level", "message", "chat") VALUES ($1, $2, $3)`, values...)
if err != nil {
helpers.LogLocalf(helpers.ERROR, nil, "Error inserting log statement into db: %s", err.Error())
}
} else {
log.Printf("DB LOGGER IS IN TEST MODE")
}
}

0 comments on commit b613a04

Please sign in to comment.