From e77a304f75c93bbf0f4547a907da5cc1f36652d6 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 27 Jan 2021 23:00:02 +0100 Subject: [PATCH] improve logging --- contacts.go | 2 +- fingerprint/fingerprint.go | 2 +- groups.go | 1 - server.go | 22 +++++++++------------- textsecure.go | 3 ++- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/contacts.go b/contacts.go index 99d26ea..cccbdc0 100644 --- a/contacts.go +++ b/contacts.go @@ -126,7 +126,7 @@ func updateContact(c *signalservice.ContactDetails) error { InboxPosition: c.GetInboxPosition(), Archived: c.GetArchived(), } - log.Debugln(c.GetAvatar(), buf) + log.Debugln("[textsecure] avatar", c.GetAvatar(), buf) return WriteContactsToPath() } diff --git a/fingerprint/fingerprint.go b/fingerprint/fingerprint.go index 7b414a9..ae30731 100644 --- a/fingerprint/fingerprint.go +++ b/fingerprint/fingerprint.go @@ -56,7 +56,7 @@ func getFingerprint(iterations int, stableIdentifier []byte, identityKeys []axol buf := new(bytes.Buffer) err := binary.Write(buf, binary.BigEndian, FINGERPRINT_VERSION) if err != nil { - fmt.Println("binary.Write failed:", err) + fmt.Println("[textsecure] binary.Write failed:", err) } version := buf.Bytes() startData := append(version, publicKey...) diff --git a/groups.go b/groups.go index c90a3ca..eb1e3e4 100644 --- a/groups.go +++ b/groups.go @@ -370,7 +370,6 @@ func RequestGroupInfo(g *Group) error { log.Debugln("[textsecure] request group update", g.Hexid) for _, m := range g.Members { if m != config.Tel { - log.Debugln(m) omsg := &outgoingMessage{ destination: m, group: &groupMessage{ diff --git a/server.go b/server.go index 578dd57..e2c788a 100644 --- a/server.go +++ b/server.go @@ -139,25 +139,23 @@ func requestCode(tel, method string) (string, error) { log.Infoln("[textsecure] request verification code for ", tel) resp, err := transport.Transport.Get(fmt.Sprintf(createAccountPath, method, tel, "android")) if err != nil { - fmt.Println(err.Error()) + log.Errorln("[textsecure] requestCode", err) return "", err } if resp.IsError() { if resp.Status == 402 { - log.Debugln(resp.Body) buf := new(bytes.Buffer) buf.ReadFrom(resp.Body) newStr := buf.String() - fmt.Printf(newStr) + log.Errorln("[textsecure] requestCode", newStr) defer resp.Body.Close() return "", errors.New("Need to solve captcha") } else if resp.Status == 413 { - log.Debugln(resp.Body) buf := new(bytes.Buffer) buf.ReadFrom(resp.Body) newStr := buf.String() - log.Debugln(newStr) + log.Errorln("[textsecure] requestCode", newStr) defer resp.Body.Close() return "", errors.New("Rate Limit Exeded") @@ -255,7 +253,7 @@ func verifyCode(code string, pin *string, credentials *AuthCredentials) (error, } resp, err := transport.Transport.PutJSON(fmt.Sprintf(VERIFY_ACCOUNT_CODE_PATH, code), body) if err != nil { - fmt.Println(err.Error()) + log.Errorln("[textsecure] verifyCode", err) return err, nil } if resp.IsError() { @@ -264,11 +262,9 @@ func verifyCode(code string, pin *string, credentials *AuthCredentials) (error, buf := new(bytes.Buffer) buf.ReadFrom(resp.Body) newStr := buf.String() - fmt.Printf(newStr) + log.Errorln("[textsecure] verifyCode", newStr) v := RegistrationLockFailure{} err := json.Unmarshal([]byte(newStr), &v) - log.Debugln("v", v) - if err != nil { return err, nil } @@ -455,14 +451,14 @@ func GetProfileE164(tel string) (Contact, error) { resp, err := transport.Transport.Get(fmt.Sprintf(PROFILE_PATH, tel)) if err != nil { - log.Debugln(err) + log.Errorln("[textsecure] GetProfileE164 ", err) } profile := &Profile{} dec := json.NewDecoder(resp.Body) err = dec.Decode(&profile) if err != nil { - log.Debugln(err) + log.Errorln("[textsecure] GetProfileE164 ", err) } avatar, _ := GetAvatar(profile.Avatar) buf := new(bytes.Buffer) @@ -471,7 +467,7 @@ func GetProfileE164(tel string) (Contact, error) { c := contacts[profile.UUID] avatarDecrypted, err := decryptAvatar(buf.Bytes(), []byte(profile.IdentityKey)) if err != nil { - log.Debugln(err) + log.Errorln("[textsecure] GetProfileE164 ", err) } c.Username = profile.Username c.UUID = profile.UUID @@ -800,7 +796,7 @@ func makePreKeyBundle(UUID string, deviceID uint32) (*axolotl.PreKeyBundle, erro preKeyId := uint32(0) var preKey *axolotl.ECPublicKey if d.PreKey == nil { - log.Debugln(fmt.Errorf("no prekey for contact %s, device %d", UUID, deviceID)) + log.Debugln("[textsecure] makePreKeyBundle", fmt.Errorf("no prekey for contact %s, device %d", UUID, deviceID)) } else { preKeyId = d.PreKey.ID decPK, err := decodeKey(d.PreKey.PublicKey) diff --git a/textsecure.go b/textsecure.go index 50e719d..28b75db 100644 --- a/textsecure.go +++ b/textsecure.go @@ -366,7 +366,8 @@ func registerDevice() error { } client.RegistrationDone() if client.RegistrationDone != nil { - fmt.Println("RegistrationDone__") + log.Infoln("[textsecure] RegistrationDone") + client.RegistrationDone() } return nil