diff --git a/src/agreements_api.go b/src/agreements_api.go index 14aa89a7..b39b8294 100644 --- a/src/agreements_api.go +++ b/src/agreements_api.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "log" "net/http" "reflect" @@ -103,7 +104,7 @@ func (e mainEnv) agreementAccept(w http.ResponseWriter, r *http.Request, ps http case "phone": identity = normalizePhone(identity, e.conf.Sms.DefaultCountry) } - fmt.Printf("Processing agreement, status: %s\n", status) + log.Printf("Processing agreement, status: %s\n", status) e.db.acceptAgreement(userTOKEN, mode, identity, brief, status, agreementmethod, referencecode, lastmodifiedby, starttime, expiration) /* @@ -319,7 +320,6 @@ func (e mainEnv) getUserAgreements(w http.ResponseWriter, r *http.Request, ps ht returnError(w, r, "internal error", 405, err, event) return } - //fmt.Printf("Total count of rows: %d\n", numRecords) w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(200) str := fmt.Sprintf(`{"status":"ok","total":%d,"rows":%s}`, numRecords, resultJSON) @@ -395,7 +395,6 @@ func (e mainEnv) getUserAgreement(w http.ResponseWriter, r *http.Request, ps htt returnError(w, r, "not found", 405, err, event) return } - //fmt.Printf("Total count of rows: %d\n", numRecords) w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(200) str := fmt.Sprintf(`{"status":"ok","data":%s}`, resultJSON) @@ -479,7 +478,7 @@ func (e mainEnv) consentFilterRecords(w http.ResponseWriter, r *http.Request, ps returnError(w, r, "internal error", 405, err, event) return } - fmt.Printf("Total count of rows: %d\n", numRecords) + log.Printf("Total count of rows: %d\n", numRecords) w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(200) str := fmt.Sprintf(`{"status":"ok","total":%d,"rows":%s}`, numRecords, resultJSON) diff --git a/src/agreements_db.go b/src/agreements_db.go index e093ccc2..fad5c403 100644 --- a/src/agreements_db.go +++ b/src/agreements_db.go @@ -2,7 +2,6 @@ package main import ( "encoding/json" - //"errors" "fmt" "time" diff --git a/src/autocontext/context.go b/src/autocontext/context.go index 203e596e..7eb74f71 100644 --- a/src/autocontext/context.go +++ b/src/autocontext/context.go @@ -3,6 +3,7 @@ package autocontext import ( "errors" "fmt" + "log" "net/http" "regexp" "runtime" @@ -68,13 +69,13 @@ func getRequestAddress() (string, error) { //fmt.Printf("Stack of %d bytes: %s\n", count, trace) match := regexServeHTTP.FindStringSubmatch(string(trace[0:count])) if len(match) != 2 { - fmt.Println("Autocontext: regex not found in stack") + log.Println("Autocontext: regex not found in stack") //fmt.Printf("*** STACK ***\n%s\n", trace) return "", errors.New("Failed to find *http.Request address") } if count > 3072 { - fmt.Println("Autocontext: stack frame too large, check for bugs") - fmt.Printf("*** STACK ***\n%s\n", trace) + log.Println("Autocontext: stack frame too large, check for bugs") + log.Printf("*** STACK ***\n%s\n", trace) } //fmt.Printf("*** extracted address from stacktrace: %s\n", match[1]) return match[1], nil diff --git a/src/bunker_test.go b/src/bunker_test.go index c001083e..7506325b 100644 --- a/src/bunker_test.go +++ b/src/bunker_test.go @@ -36,8 +36,7 @@ func helpServe(request *http.Request) (map[string]interface{}, error) { request.Header.Set("Content-Type", "application/json") rr := httptest.NewRecorder() router.ServeHTTP(rr, request) - fmt.Printf("[%d] %s%s\n", rr.Code, request.Host, request.URL.Path) - fmt.Printf("Response: %s\n", rr.Body.Bytes()) + log.Printf("[%d] %s%s %s\n", rr.Code, request.Host, request.URL.Path, rr.Body.Bytes()) var raw map[string]interface{} if rr.Body.Bytes()[0] == '{' { json.Unmarshal(rr.Body.Bytes(), &raw) @@ -52,8 +51,7 @@ func helpServe2(request *http.Request) (map[string]interface{}, error) { request.Header.Set("Content-Type", "application/x-www-form-urlencoded") rr := httptest.NewRecorder() router.ServeHTTP(rr, request) - fmt.Printf("[%d] %s%s\n", rr.Code, request.Host, request.URL.Path) - fmt.Printf("Response: %s\n", rr.Body.Bytes()) + log.Printf("[%d] %s%s %s\n", rr.Code, request.Host, request.URL.Path, rr.Body.Bytes()) var raw map[string]interface{} if rr.Body.Bytes()[0] == '{' { json.Unmarshal(rr.Body.Bytes(), &raw) @@ -86,12 +84,11 @@ func helpConfigurationDump(token string) ([]byte, error) { } func init() { - fmt.Printf("**INIT*TEST*CODE***\n") + log.Printf("**INIT*TEST*CODE***\n") testDBFile := storage.CreateTestDB() db, myRootToken, err := setupDB(&testDBFile, nil, "") if err != nil { - //log.Panic("error %s", err.Error()) - fmt.Printf("error %s", err.Error()) + log.Printf("Init error %s", err.Error()) } rootToken = myRootToken var cfg Config @@ -111,23 +108,22 @@ func init() { e = mainEnv{db, cfg, make(chan struct{})} rootToken2, err := e.db.getRootXtoken() if err != nil { - fmt.Printf("Failed to retrieve root token: %s\n", err) + log.Printf("Failed to retrieve root token: %s\n", err) } - fmt.Printf("Hashed root token: %s\n", rootToken2) + log.Printf("Hashed root token: %s\n", rootToken2) router = e.setupRouter() router = e.setupConfRouter(router) //test1 := &testEnv{e, rootToken, router} e.dbCleanupDo() - fmt.Printf("**INIT*DONE***\n") + log.Printf("**INIT*DONE***\n") } /* func TestBackupOK(t *testing.T) { - fmt.Printf("root token: %s\n", rootToken) + log.Printf("root token: %s\n", rootToken) raw, err := helpBackupRequest(rootToken) if err != nil { - //log.Panic("error %s", err.Error()) - log.Fatalf("failed to backup db %s", err.Error()) + log.Fatalf("Failed to backup db %s", err.Error()) } if strings.Contains(string(raw), "CREATE TABLE") == false { t.Fatalf("Backup failed\n") @@ -138,8 +134,7 @@ func TestBackupOK(t *testing.T) { func TestMetrics(t *testing.T) { raw, err := helpMetricsRequest(rootToken) if err != nil { - //log.Panic("error %s", err.Error()) - log.Fatalf("failed to get metrics %s", err.Error()) + log.Fatalf("Failed to get metrics %s", err.Error()) } if strings.Contains(string(raw), "go_memstats") == false { t.Fatalf("metrics failed\n") @@ -161,9 +156,6 @@ func TestAnonPage(t *testing.T) { pattern := value["pattern"].(string) request := httptest.NewRequest("GET", url, nil) raw, _ := helpServe0(request) - //if err != nil { - // log.Fatalf("failed to get page %s", err.Error()) - //} if strings.Contains(string(raw), pattern) == false { t.Fatalf("pattern detection failed\n") } @@ -171,11 +163,10 @@ func TestAnonPage(t *testing.T) { } func TestConfigurationOK(t *testing.T) { - fmt.Printf("root token: %s\n", rootToken) + log.Printf("Generated root token: %s\n", rootToken) raw, err := helpConfigurationDump(rootToken) if err != nil { - //log.Panic("error %s", err.Error()) - log.Fatalf("failed to fetch configuration: %s", err.Error()) + log.Fatalf("Failed to fetch configuration: %s", err.Error()) } if strings.Contains(string(raw), "CreateUserWithoutAccessToken") == false { t.Fatalf("Configuration dump failed\n") diff --git a/src/pactivities_api.go b/src/pactivities_api.go index 81bd5c8e..de514f81 100644 --- a/src/pactivities_api.go +++ b/src/pactivities_api.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "log" "net/http" "reflect" @@ -158,7 +159,7 @@ func (e mainEnv) pactivityList(w http.ResponseWriter, r *http.Request, ps httpro returnError(w, r, "internal error", 405, err, nil) return } - fmt.Printf("Total count of rows: %d\n", numRecords) + log.Printf("Total count of rows: %d\n", numRecords) w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(200) str := fmt.Sprintf(`{"status":"ok","total":%d,"rows":%s}`, numRecords, resultJSON) diff --git a/src/storage/sqlite-storage.go b/src/storage/sqlite-storage.go index c2baf913..8a0a895d 100644 --- a/src/storage/sqlite-storage.go +++ b/src/storage/sqlite-storage.go @@ -680,7 +680,7 @@ func (dbobj SQLiteDB) CleanupRecord(t Tbl, keyName string, keyValue string, bdel tbl := GetTable(t) cleanup := dbobj.decodeForCleanup(bdel) q := "update " + tbl + " SET " + cleanup + " WHERE " + dbobj.escapeName(keyName) + "=$1" - log.Printf("CleanupRecord q: %s\n", q) + log.Printf("q: %s\n", q) tx, err := dbobj.db.Begin() if err != nil { diff --git a/src/utils_test.go b/src/utils_test.go index 1191ae34..2d4536aa 100644 --- a/src/utils_test.go +++ b/src/utils_test.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "log" "io/ioutil" "net/http" "net/http/httptest" @@ -98,7 +99,7 @@ func TestUtilSMS(t *testing.T) { rw.WriteHeader(200) defer req.Body.Close() bodyBytes, _ := ioutil.ReadAll(req.Body) - fmt.Printf("body: %s\n", string(bodyBytes)) + log.Printf("body: %s\n", string(bodyBytes)) if string(bodyBytes) != "Body=Data+Bunker+code+1234&From=from1234&To=4444" { t.Fatalf("bad request: %s", string(bodyBytes)) } @@ -118,7 +119,7 @@ func TestUtilNotifyConsentChange(t *testing.T) { rw.WriteHeader(200) defer req.Body.Close() bodyBytes, _ := ioutil.ReadAll(req.Body) - fmt.Printf("body: %s\n", string(bodyBytes)) + log.Printf("body: %s\n", string(bodyBytes)) if string(bodyBytes) != `{"action":"consentchange","brief":"brief","identity":"user3@user3.com","mode":"email","status":"no"}` { q <- fmt.Sprintf("bad request in notifyConsentChange: %s", string(bodyBytes)) } else { @@ -141,7 +142,7 @@ func TestUtilNotifyProfileNew(t *testing.T) { rw.WriteHeader(200) defer req.Body.Close() bodyBytes, _ := ioutil.ReadAll(req.Body) - fmt.Printf("body: %s\n", string(bodyBytes)) + log.Printf("body: %s\n", string(bodyBytes)) if string(bodyBytes) != `{"action":"profilenew","identity":"user3@user3.com","mode":"email","profile":{"name":"alex"}}` { q <- fmt.Sprintf("bad request in notifyConsentChange: %s", string(bodyBytes)) } else { @@ -165,7 +166,7 @@ func TestUtilNotifyForgetMe(t *testing.T) { rw.WriteHeader(200) defer req.Body.Close() bodyBytes, _ := ioutil.ReadAll(req.Body) - fmt.Printf("body: %s\n", string(bodyBytes)) + log.Printf("body: %s\n", string(bodyBytes)) if string(bodyBytes) != `{"action":"forgetme","identity":"user3@user3.com","mode":"email","profile":{"name":"alex"}}` { q <- fmt.Sprintf("bad request in notifyConsentChange: %s", string(bodyBytes)) } else { @@ -189,7 +190,7 @@ func TestUtilNotifyProfileChange(t *testing.T) { rw.WriteHeader(200) defer req.Body.Close() bodyBytes, _ := ioutil.ReadAll(req.Body) - fmt.Printf("body: %s\n", string(bodyBytes)) + log.Printf("body: %s\n", string(bodyBytes)) if string(bodyBytes) != `{"action":"profilechange","identity":"user3@user3.com","mode":"email","old":{"name":"alex2"},"profile":{"name":"alex3"}}` { q <- fmt.Sprintf("bad request in notifyConsentChange: %s", string(bodyBytes)) } else { diff --git a/src/xtokens_test.go b/src/xtokens_test.go index 10b13010..e055b13d 100644 --- a/src/xtokens_test.go +++ b/src/xtokens_test.go @@ -1,7 +1,7 @@ package main import ( - "fmt" + "log" "net/http/httptest" "strings" "testing" @@ -95,7 +95,7 @@ func TestUserLoginDelete(t *testing.T) { t.Fatalf("Failed to create user login: %s", raw["message"].(string)) } xtoken := raw["xtoken"].(string) - fmt.Printf("User login *** xtoken: %s\n", xtoken) + log.Printf("User login *** xtoken: %s\n", xtoken) oldRootToken := rootToken rootToken = xtoken raw, _ = helpAcceptAgreement("token", userTOKEN, "contract1", "") @@ -130,7 +130,7 @@ func TestUserLoginDelete(t *testing.T) { if _, ok := raw["status"]; !ok || raw["status"].(string) != "ok" { t.Fatalf("Failed to get user app list with user xtoken\n") } - fmt.Printf("apps: %s\n", raw["apps"]) + log.Printf("apps: %s\n", raw["apps"]) // user asks to forget-me raw, _ = helpDeleteUser("token", userTOKEN) if _, ok := raw["status"]; !ok || raw["status"].(string) != "ok" { @@ -141,7 +141,7 @@ func TestUserLoginDelete(t *testing.T) { } rtoken0 := raw["rtoken"].(string) raw, _ = helpGetUserAppList(userTOKEN) - fmt.Printf("apps: %s\n", raw["apps"]) + log.Printf("apps: %s\n", raw["apps"]) rootToken = oldRootToken // get user requests @@ -161,7 +161,7 @@ func TestUserLoginDelete(t *testing.T) { if rtoken != rtoken0 { t.Fatalf("Rtoken0 is wrong\n") } - fmt.Printf("** User request record: %s\n", rtoken) + log.Printf("** User request record: %s\n", rtoken) } raw8, _ := helpGetUserRequest(rtoken) if raw8["status"].(string) != "ok" {