Use logger and add debug flag for extra output

This commit is contained in:
Christian Muehlhaeuser 2020-02-28 12:12:48 +01:00
parent f2e92deb04
commit e741cd6fcc
No known key found for this signature in database
GPG key ID: 3CF9FA45CA1EBB7E
5 changed files with 32 additions and 23 deletions

View file

@ -5,6 +5,7 @@ import (
"context"
"errors"
"fmt"
"log"
"regexp"
"strings"
@ -149,7 +150,7 @@ func (mod *Account) Run(eventChan chan interface{}) error {
func (mod *Account) Panes() []accounts.Pane {
ll, err := mod.client.GetLists(context.Background())
if err != nil {
fmt.Println("Error retrieving lists:", err)
log.Println("Error retrieving lists:", err)
}
p := []accounts.Pane{}
@ -346,7 +347,7 @@ func (mod *Account) LoadConversation(id string) ([]accounts.MessageEvent, error)
return r, err
}
fmt.Printf("Found %d ancestors and %d descendants\n", len(contexts.Ancestors), len(contexts.Descendants))
log.Printf("Found %d ancestors and %d descendants\n", len(contexts.Ancestors), len(contexts.Descendants))
for _, m := range contexts.Ancestors {
r = append(r, mod.handleStatus(m))
}
@ -570,7 +571,7 @@ func (mod *Account) handleNotification(n *mastodon.Notification, notify bool) {
}
default:
fmt.Println("Unknown type:", n.Type)
log.Println("Unknown type:", n.Type)
return
}
@ -672,7 +673,7 @@ func (mod *Account) handleStreamEvent(item interface{}, ch chan interface{}) {
}
default:
fmt.Printf("Unknown event: %+v\n", item)
log.Printf("Unknown event: %+v\n", item)
}
}

View file

@ -1,7 +1,6 @@
package main
import (
"fmt"
"time"
humanize "github.com/dustin/go-humanize"
@ -334,7 +333,7 @@ func (m *MessageModel) removeMessageID(id string) {
}
func (m *MessageModel) updateMessageTime() {
fmt.Println("Updating timelines...")
debugln("Updating timelines...")
if len(m.Messages()) > 0 {
var fIndex = m.Index(0, 0, core.NewQModelIndex())
var lIndex = m.Index(len(m.Messages())-1, 0, core.NewQModelIndex())

View file

@ -1,7 +1,6 @@
package main
import (
"fmt"
"log"
"strings"
"sync"
@ -57,7 +56,7 @@ var (
)
func addMessage(model *MessageModel, m *Message) {
fmt.Println("store", m.MessageID)
// debugln("store", m.MessageID)
mutex.Lock()
defer mutex.Unlock()
@ -67,7 +66,7 @@ func addMessage(model *MessageModel, m *Message) {
}
func removeMessage(model *MessageModel, m *Message) {
fmt.Println("remove", m.MessageID)
debugln("remove", m.MessageID)
mutex.RLock()
ref := modelReferences[m.MessageID]
@ -95,7 +94,7 @@ func removeMessage(model *MessageModel, m *Message) {
}
func deleteMessage(id string) {
fmt.Println("delete", id)
debugln("delete", id)
mutex.RLock()
ref := modelReferences[id]
@ -106,14 +105,14 @@ func deleteMessage(id string) {
for idx, m := range v.Messages() {
if m.MessageID == id {
trow := len(v.Messages()) - 1 - idx
fmt.Println("Found message, deleting from model...", idx, trow)
debugln("Found message, deleting from model...", idx, trow)
v.RemoveMessage(trow)
break
}
}
}
fmt.Println("done deleting")
debugln("done deleting")
}
func getMessage(id string) *Message {

View file

@ -3,7 +3,7 @@
package main
import (
"fmt"
"log"
"github.com/gen2brain/beeep"
)
@ -11,6 +11,6 @@ import (
func notify(title string, body string) {
err := beeep.Notify(title, body, "")
if err != nil {
fmt.Println("Error sending notification:", err)
log.Println("Error sending notification:", err)
}
}

View file

@ -1,7 +1,7 @@
package main
import (
"fmt"
"flag"
"log"
"net/url"
"os"
@ -17,6 +17,8 @@ import (
)
var (
debug = flag.Bool("debug", true, "Enable debug output")
config Config
configFile string
@ -36,7 +38,7 @@ func connectToInstance(instance string) bool {
instance = addHTTPPrefixIfNeeded(instance)
tc, authURI, redirectURI, err = mastodon.RegisterAccount(instance)
if err != nil {
fmt.Println("Error registering app:", err)
log.Println("Error registering app:", err)
accountBridge.SetError(err.Error())
return false
}
@ -44,8 +46,8 @@ func connectToInstance(instance string) bool {
configBridge.SetAuthURL(authURI)
configBridge.SetRedirectURL(redirectURI)
fmt.Println("auth uri:", authURI)
fmt.Println("redirect uri:", redirectURI)
log.Println("auth uri:", authURI)
log.Println("redirect uri:", redirectURI)
return true
}
@ -63,7 +65,7 @@ func addHTTPPrefixIfNeeded(instance string) string {
func authInstance(code, redirectURI string) bool {
instance, token, clientID, clientSecret, err := tc.Authenticate(code, redirectURI)
if err != nil {
fmt.Println("Error authenticating with instance:", err)
log.Println("Error authenticating with instance:", err)
accountBridge.SetError(err.Error())
return false
}
@ -186,7 +188,7 @@ func loadConversation(id string) {
return
}
fmt.Println("Found conversation posts:", len(messages))
debugln("Found conversation posts:", len(messages))
conversationModel.Clear()
for _, m := range messages {
p := messageFromEvent(m)
@ -196,7 +198,7 @@ func loadConversation(id string) {
// loadAccount loads an entire profile
func loadAccount(id string) {
log.Println("Loading account:", id)
debugln("Loading account:", id)
profile, messages, err := tc.LoadAccount(id)
if err != nil {
log.Println("Error loading account:", err)
@ -214,7 +216,7 @@ func loadAccount(id string) {
profileBridge.SetFollowing(profile.Following)
profileBridge.SetFollowedBy(profile.FollowedBy)
fmt.Println("Found account posts:", len(messages))
debugln("Found account posts:", len(messages))
accountMessagesModel.Clear()
for _, m := range messages {
p := messageFromEvent(m)
@ -243,7 +245,7 @@ func tag(token string) {
// closePane closes a pane
func closePane(idx int64) {
fmt.Println("Closing pane", idx)
debugln("Closing pane", idx)
paneModel.RemovePane(int(idx))
}
@ -325,7 +327,15 @@ func setupMastodon(config Account) {
go tc.Run(evchan)
}
func debugln(s ...interface{}) {
if *debug {
log.Println(s...)
}
}
func main() {
flag.Parse()
core.QCoreApplication_SetApplicationName("Telephant")
core.QCoreApplication_SetOrganizationName("fribbledom.com")
core.QCoreApplication_SetAttribute(core.Qt__AA_EnableHighDpiScaling, true)