1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-06-09 06:20:43 +00:00

Cleaned up logging

This commit is contained in:
マリウス 2023-01-05 21:44:34 -05:00
parent acfb0ece2a
commit 42a3d1b5dc
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
18 changed files with 6 additions and 73 deletions

View File

@ -73,8 +73,8 @@ func (a *Aggregator) ListPosts() ([]post.Post, []error) {
}
sysPosts, err := (*sys).ListPosts(a.ctx.GetCurrentForum().ID)
a.ctx.Logger.Debugf("AGGEGATOR ERROR: %v", err)
if err != nil {
a.ctx.Logger.Errorf("aggregator error: %v\n", err)
errs[idx] = err
continue
}

View File

@ -127,8 +127,6 @@ func (c *Client) NewRequest(
}
}
c.logger.Debug(buffer.String())
if req, err = http.NewRequest(
method,
parsedURL.String(),
@ -180,9 +178,6 @@ func (c *Client) Do(
}
}
c.logger.Debug(res)
c.logger.Debug(string(body))
if res.StatusCode < http.StatusOK ||
res.StatusCode > http.StatusNoContent {
var errbody ErrorBody

View File

@ -113,8 +113,6 @@ func (a *PostServiceHandler) Create(
return PostModel{}, err
}
a.client.logger.Debug(response)
return *response, nil
}

View File

@ -310,7 +310,6 @@ func (sys *System) CreatePost(p *post.Post) error {
func (sys *System) CreateReply(r *reply.Reply) error {
var err error
sys.logger.Debugf("%v", r)
ID, err := strconv.Atoi(r.ID)
if err != nil {
return err

View File

@ -2,7 +2,6 @@ package lemmy
import (
"context"
"encoding/json"
"fmt"
"net/url"
"strconv"
@ -135,9 +134,6 @@ func (sys *System) ListForums() ([]forum.Forum, error) {
var models []forum.Forum
for _, i := range resp.Communities {
sys.logger.Debugf("FORUM:")
b, _ := json.Marshal(i)
sys.logger.Debug(string(b))
models = append(models, forum.Forum{
ID: strconv.Itoa(i.Community.ID),
Name: i.Community.Name,
@ -157,7 +153,7 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
Sort: types.NewOptional(types.SortTypeNew),
Limit: types.NewOptional(int64(50)),
})
sys.logger.Debug("DEEEEBUUUUUUUGGGGGGGG")
if err != nil {
return []post.Post{}, err
}
@ -167,8 +163,6 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
var models []post.Post
for _, i := range resp.Posts {
b, _ := json.Marshal(i)
sys.logger.Debug(string(b))
t := "post"
body := i.Post.Body.ValueOr("")
if i.Post.URL.IsValid() {

View File

@ -120,8 +120,6 @@ func (c *Client) NewRequest(
}
}
c.logger.Debug(buffer.String())
if req, err = http.NewRequest(
method,
parsedURL.String(),
@ -167,13 +165,10 @@ func (c *Client) Do(
}
}
c.logger.Debug(res)
c.logger.Debug(string(body))
if res.StatusCode < http.StatusOK ||
res.StatusCode > http.StatusNoContent {
return &RequestError{
Err: errors.New("Non-2xx status code"),
Err: errors.New(string(body)),
}
}

View File

@ -61,23 +61,18 @@ func (tk *ToolKit) HandleMsg(m interface{}, msg tea.Msg) (bool, []tea.Cmd) {
return false, cmds
case cmd.Command:
tk.logger.Debugf("got command: %v\n", msg)
switch msg.Call {
case cmd.WinFocus:
if msg.Target == tk.winID ||
msg.Target == "*" {
tk.logger.Debug("got WinFocus")
tk.Focus(m)
}
tk.logger.Debugf("focused: %v", tk.focused)
return true, nil
case cmd.WinBlur:
if msg.Target == tk.winID ||
msg.Target == "*" {
tk.logger.Debug("got WinBlur")
tk.Blur(m)
}
tk.logger.Debugf("focused: %v", tk.focused)
return true, nil
case cmd.WinOpen:
if tk.mh.OnWinOpenCmd != nil {

View File

@ -99,10 +99,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyMsg:
switch {
case key.Matches(msg, m.keymap.Close):
m.ctx.Logger.Debug("close received")
closed, ccmds := m.wm.CloseFocused()
if !closed {
m.ctx.Logger.Debug("CloseFocused() was false, quitting")
return m, tea.Quit
}
return m, tea.Batch(ccmds...)
@ -146,7 +144,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
forums, errs := m.a.ListForums()
for _, err := range errs {
if err != nil {
m.ctx.Logger.Error(errs)
m.ctx.Logger.Error(err)
ccmds = append(ccmds, cmd.New(
cmd.MsgError,
"*",
@ -156,7 +154,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
for _, f := range forums {
m.ctx.Logger.Debugf("Adding forum to list: %s ID %d\n", f.Title(), f.SysIDX)
listItems = append(listItems, f)
}
@ -205,7 +202,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case cmd.WinOpen:
switch msg.Target {
case postshow.WIN_ID:
m.ctx.Logger.Debugln("received WinOpen")
ccmds = m.wm.Open(
msg.Target,
postshow.NewModel(m.ctx),
@ -218,7 +214,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
&msg,
)
case postcreate.WIN_ID:
m.ctx.Logger.Debugln("received WinOpen")
ccmds = m.wm.Open(
msg.Target,
postcreate.NewModel(m.ctx),
@ -232,13 +227,12 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
)
m.viewcache = m.buildView(false)
}
m.ctx.Logger.Debugf("got back ccmds: %v\n", ccmds)
case cmd.WinClose:
switch msg.Target {
case postcreate.WIN_ID:
m.ctx.Logger.Debugln("received WinClose")
// TODO: Anything?
case popuplist.WIN_ID:
selectionIDIf := msg.GetArg("selectionID")
@ -252,7 +246,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.ctx.SetCurrentForum(forum.Forum{})
case "forum":
selected := msg.GetArg("selected").(forum.Forum)
m.ctx.Logger.Debugf("selecting system ID %d\n", selected.SysIDX)
m.ctx.SetCurrentSystem(selected.SysIDX)
m.ctx.SetCurrentForum(selected)
}
@ -266,7 +259,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
case cmd.MsgError:
m.ctx.Logger.Debugln("received MsgError")
ccmds = m.wm.Open(
msgerror.WIN_ID,
msgerror.NewModel(m.ctx),
@ -280,10 +272,8 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
)
default:
// if msg.Call < cmd.ViewFocus {
m.ctx.Logger.Debugf("updating all with cmd: %v\n", msg)
ccmds = m.wm.UpdateAll(msg)
// }
}
cmds = append(cmds, ccmds...)

View File

@ -228,12 +228,9 @@ func (m Model) buildView(cached bool) string {
var view strings.Builder = strings.Builder{}
if cached && m.focused == false && m.viewcache != "" {
m.ctx.Logger.Debugln("Cached View()")
return m.viewcache
}
m.ctx.Logger.Debugln("Posts.View()")
var l string = ""
if m.focused {
l = m.ctx.Theme.PostsList.List.Focused.Render(m.list.View())

View File

@ -45,7 +45,6 @@ func (wm *WM) Open(id string, win windows.Window, xywh [4]int, command *cmd.Comm
command.AddArg("xywh", item.XYWH)
tcmds = append(tcmds, wm.Update(id, *command))
wm.ctx.Logger.Debugf("content: %v\n", wm.ctx.Content)
tcmds = append(tcmds, wm.Resize(id, wm.ctx.Content[0], wm.ctx.Content[1])...)
// tcmds = append(tcmds, wm.Update(id, *cmd.New(
// cmd.WinRefreshData,

View File

@ -10,7 +10,6 @@ func handleViewResize(mi interface{}) (bool, []tea.Cmd) {
var m *Model = mi.(*Model)
var cmds []tea.Cmd
m.ctx.Logger.Debugf("received WindowSizeMsg: %vx%v\n", m.tk.ViewWidth(), m.tk.ViewHeight())
viewportWidth := m.tk.ViewWidth() - 2
viewportHeight := m.tk.ViewHeight() - 5
@ -28,11 +27,9 @@ func handleMsgErrorCmd(mi interface{}, c cmd.Command) (bool, []tea.Cmd) {
var cmds []tea.Cmd
if err := c.GetArg("error"); err != nil {
m.ctx.Logger.Debugf("Setting error: %v", err)
m.errs = append(m.errs, err.(error))
}
if errs := c.GetArg("errors"); errs != nil {
m.ctx.Logger.Debugf("Setting error: %v", errs)
m.errs = append(m.errs, errs.([]error)...)
}

View File

@ -8,13 +8,9 @@ func buildView(mi interface{}, cached bool) string {
var m *Model = mi.(*Model)
if vcache := m.tk.DefaultCaching(cached); vcache != "" {
m.ctx.Logger.Debugln("Cached View()")
return vcache
}
m.ctx.Logger.Debugln("View()")
m.ctx.Logger.Debugf("IsFocused: %v\n", m.tk.IsFocused())
return m.tk.ErrorDialog(
"Error",
viewportStyle.Render(m.viewport.View()),

View File

@ -23,7 +23,6 @@ func handleViewResize(mi interface{}) (bool, []tea.Cmd) {
var m *Model = mi.(*Model)
var cmds []tea.Cmd
m.ctx.Logger.Debugf("received WindowSizeMsg: %vx%v\n", m.tk.ViewWidth(), m.tk.ViewHeight())
listWidth := m.tk.ViewWidth() - 2
listHeight := m.tk.ViewHeight() - 1
@ -44,7 +43,6 @@ func handleWinOpenCmd(mi interface{}, c cmd.Command) (bool, []tea.Cmd) {
var cmds []tea.Cmd
if c.Target == WIN_ID {
m.ctx.Logger.Debug("got own WinOpen command")
m.selectionID = c.GetArg("selectionID").(string)
m.items = c.GetArg("items").([]list.Item)
m.list.SetItems(m.items)

View File

@ -10,11 +10,8 @@ func buildView(mi interface{}, cached bool) string {
var m *Model = mi.(*Model)
if vcache := m.tk.DefaultCaching(cached); vcache != "" {
m.ctx.Logger.Debugln("Cached View()")
return vcache
}
m.ctx.Logger.Debugln("View()")
m.ctx.Logger.Debugf("IsFocused: %v\n", m.tk.IsFocused())
var style lipgloss.Style
if m.tk.IsFocused() {

View File

@ -16,8 +16,6 @@ func buildView(mi interface{}, cached bool) string {
var m *Model = mi.(*Model)
if cached && m.viewcache != "" {
m.ctx.Logger.Debugln("Cached View()")
m.textarea.SetWidth(m.viewcacheTextareaXY[2])
m.textarea.SetHeight(m.viewcacheTextareaXY[3])
@ -53,9 +51,6 @@ func buildView(mi interface{}, cached bool) string {
m.viewcacheTextareaXY[2] = textareaWidth
m.viewcacheTextareaXY[3] = textareaHeight
m.ctx.Logger.Debugln("View()")
m.ctx.Logger.Debugf("IsFocused: %v\n", m.tk.IsFocused())
var tmp string = ""
if m.action == "post" {
tmp = lipgloss.JoinVertical(

View File

@ -64,7 +64,6 @@ func handleReply(mi interface{}) (bool, []tea.Cmd) {
}
}
m.ctx.Logger.Debugf("replyToIdx: %d", replyToIdx)
var ract cmd.Arg = cmd.Arg{Name: "action", Value: "reply"}
var rtype cmd.Arg = cmd.Arg{Name: "replyTo"}
var rarg cmd.Arg
@ -83,10 +82,6 @@ func handleReply(mi interface{}) (bool, []tea.Cmd) {
cmd := cmd.New(cmd.WinOpen, postcreate.WIN_ID, ract, rtype, rarg, ridx)
cmds = append(cmds, cmd.Tea())
m.ctx.Logger.Debugln("caching view")
m.ctx.Logger.Debugf("buffer: %s", m.buffer)
// m.viewcache = m.buildView(false)
return true, cmds
}
@ -135,7 +130,6 @@ func handleViewResize(mi interface{}) (bool, []tea.Cmd) {
var m *Model = mi.(*Model)
var cmds []tea.Cmd
m.ctx.Logger.Debugf("received WindowSizeMsg: %vx%v\n", m.tk.ViewWidth(), m.tk.ViewHeight())
viewportWidth := m.tk.ViewWidth() - 2
viewportHeight := m.tk.ViewHeight() - 5
@ -154,10 +148,9 @@ func handleWinOpenCmd(mi interface{}, c cmd.Command) (bool, []tea.Cmd) {
var cmds []tea.Cmd
if c.Target == WIN_ID {
m.ctx.Logger.Debug("got own WinOpen command")
m.activePost = c.GetArg("post").(*post.Post)
m.viewport.SetContent(m.renderViewport(m.activePost))
m.ctx.Logger.Debugf("loading post: %v", m.activePost.ID)
m.ctx.Logger.Debugf("loading post: %s\n", m.activePost.ID)
m.ctx.Loading = true
cmds = append(cmds, m.loadPost(m.activePost))
return true, cmds
@ -172,7 +165,6 @@ func handleWinFreshDataCmd(mi interface{}, c cmd.Command) (bool, []tea.Cmd) {
if c.Target == WIN_ID ||
c.Target == "*" {
m.ctx.Logger.Debug("got *post.Post")
m.activePost = c.GetArg("post").(*post.Post)
m.viewport.SetContent(m.renderViewport(m.activePost))
m.ctx.Loading = false

View File

@ -105,7 +105,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m *Model) loadPost(p *post.Post) tea.Cmd {
return func() tea.Msg {
m.ctx.Logger.Debug("------ EXECUTED -----")
if err := m.a.LoadPost(p); err != nil {
m.ctx.Logger.Error(err)
c := cmd.New(

View File

@ -18,11 +18,8 @@ func buildView(mi interface{}, cached bool) string {
var m *Model = mi.(*Model)
if vcache := m.tk.DefaultCaching(cached); vcache != "" {
m.ctx.Logger.Debugln("Cached View()")
return vcache
}
m.ctx.Logger.Debugln("View()")
m.ctx.Logger.Debugf("IsFocused: %v\n", m.tk.IsFocused())
return m.tk.Dialog(
"Post",