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