Skip to content

Commit

Permalink
fix: Use log level from config
Browse files Browse the repository at this point in the history
  • Loading branch information
joeirimpan committed Jun 27, 2022
1 parent 92b4cd5 commit 0f74d4a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config.sample.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
log_level="info"

[server]
address = ":8082"
read_timeout = "5s"
Expand Down
2 changes: 1 addition & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func handlePostback(w http.ResponseWriter, r *http.Request) {
message.Attachments = a
}

app.logger.ErrorWith("sending message").String("provider", provider).String("message", fmt.Sprintf("%#+v", message)).Write()
app.logger.DebugWith("sending message").String("provider", provider).String("message", fmt.Sprintf("%#+v", message)).Write()

// Send message.
if err := p.Push(message); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ func loadMessengers(msgrs []string, app *App) {
}

func main() {
logLevels := onelog.INFO | onelog.WARN | onelog.ERROR | onelog.FATAL
if ko.String("log_level") == "debug" {
logLevels |= onelog.DEBUG
}

// setup logger
l := onelog.NewContext(os.Stderr, onelog.INFO|onelog.WARN|onelog.ERROR|onelog.FATAL, "p")
l := onelog.NewContext(os.Stderr, logLevels, "p")
l.Hook(func(e onelog.Entry) {
e.String("ts", time.Now().Format(time.RFC3339Nano))
e.String("line", l.Caller(5))
Expand Down

0 comments on commit 0f74d4a

Please sign in to comment.