From 8e6e01f47c320f862b9ba44815587006ba80cf77 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Thu, 17 Aug 2023 22:05:46 +0200 Subject: switch from log to slog This commit replaces the various log entry points with a common logger provided via context. This is helpful as it groups all log entries together via the txid and should help in the future when debugging cascading errors. --- cmd/monfront/create.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'cmd/monfront/create.go') diff --git a/cmd/monfront/create.go b/cmd/monfront/create.go index 43805a1..e11679f 100644 --- a/cmd/monfront/create.go +++ b/cmd/monfront/create.go @@ -3,7 +3,6 @@ package main import ( "database/sql" "fmt" - "log" "net/http" "strings" ) @@ -38,14 +37,14 @@ func showCreate(con *Context) { rows, err := DB.Query(prim.query) defer rows.Close() if err != nil { - log.Printf("could not get commands: %s", err) + con.log.Info("could not get commands", "error", err) con.Error = "could not get commands" returnError(http.StatusInternalServerError, con, con.w) return } result, err := rowsToResult(rows) if err != nil { - log.Printf("could not get %s: %s", prim.name, err) + con.log.Info("could not get", "primitive", prim.name, "error", err) con.Error = "could not get " + prim.name returnError(http.StatusInternalServerError, con, con.w) return @@ -137,7 +136,7 @@ func addCreate(con *Context) { stmt := `insert into ` + t.Table + `(` + strings.Join(t.Fields, ",") + `) values (` + strings.Join(vals, ",") + `)` _, err := DB.Exec(stmt, fields...) if err != nil { - log.Printf("could not insert new %s: %s", addType, err) + con.log.Info("could not insert new type", "type", addType, "error", err) con.Error = "could not insert new " + addType returnError(http.StatusInternalServerError, con, con.w) return -- cgit v1.2.3-70-g09d2