Merge branch 'debuglog' of https://github.com/afh/cointop into afh-debuglog

pull/133/head
Miguel Mota 3 years ago
commit 52a1699764
No known key found for this signature in database
GPG Key ID: 67EC1161588A00F9

@ -101,6 +101,7 @@ type Cointop struct {
colorscheme *Colorscheme
debug bool
filecache *filecache.FileCache
logfile *os.File
forceRefresh chan bool
limiter <-chan time.Time
maxTableWidth int
@ -278,6 +279,9 @@ func NewCointop(config *Config) (*Cointop, error) {
Input: NewInputView(),
},
}
if debug {
ct.initlog()
}
err := ct.SetupConfig()
if err != nil {

@ -1,27 +1,25 @@
package cointop
import (
"fmt"
"log"
"os"
"time"
)
// debuglog writs a debug log to stdout
func (ct *Cointop) debuglog(msg string) {
if !ct.debug {
return
}
func (ct *Cointop) initlog() {
filename := "/tmp/cointop.log"
f, err := os.OpenFile(filename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
panic(err)
}
log.SetOutput(f)
ct.logfile = f
}
defer f.Close()
text := fmt.Sprintf("%v %s\n", time.Now().Unix(), msg)
if _, err = f.WriteString(text); err != nil {
panic(err)
// debuglog writes a debug log message to /tmp/cointop.log if the DEBUG environment is set.
func (ct *Cointop) debuglog(format string, args ...interface{}) {
if !ct.debug {
return
}
log.Printf(format+"\n", args...)
}

@ -1,7 +1,6 @@
package cointop
import (
"fmt"
"math"
)
@ -442,7 +441,7 @@ func (ct *Cointop) HighlightRow(pageRowIndex int) error {
cy = h - (l - pageRowIndex)
}
}
ct.debuglog(fmt.Sprintf("highlightRow idx:%v h:%v cy:%v oy:%v", pageRowIndex, h, cy, oy))
ct.debuglog("highlightRow idx:%v h:%v cy:%v oy:%v", pageRowIndex, h, cy, oy)
ct.Views.Table.SetOrigin(ox, oy)
ct.Views.Table.SetCursor(cx, cy)
return nil

@ -327,7 +327,7 @@ func (ct *Cointop) UpdatePortfolioUpdateMenu() error {
coin := ct.HighlightedRowCoin()
exists := ct.PortfolioEntryExists(coin)
value := strconv.FormatFloat(ct.CoinHoldings(coin), 'f', -1, 64)
ct.debuglog(fmt.Sprintf("holdings %v", value))
ct.debuglog("holdings %v", value)
var mode string
var current string
var submitText string

@ -6,8 +6,9 @@ import (
"github.com/miguelmota/gocui"
)
// Quit quites the program
// Quit quits the program
func (ct *Cointop) Quit() error {
ct.logfile.Close()
return gocui.ErrQuit
}
@ -28,6 +29,7 @@ func (ct *Cointop) QuitView() error {
// Exit safely exits the program
func (ct *Cointop) Exit() {
ct.debuglog("exit()")
ct.logfile.Close()
if ct.g != nil {
ct.g.Close()
} else {

Loading…
Cancel
Save