forked from quickfixgo/traderui
-
Notifications
You must be signed in to change notification settings - Fork 3
/
fancylog.go
82 lines (63 loc) · 1.83 KB
/
fancylog.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"fmt"
"time"
"github.com/fatih/color"
"github.com/gosuri/uitable"
"github.com/quickfixgo/quickfix"
)
type screenLog struct {
prefix string
}
func (l screenLog) OnIncoming(s []byte) {
table := uitable.New()
table.MaxColWidth = 150
table.Wrap = true // wrap columns
table.AddRow(" |Time:", fmt.Sprintf("%v", time.Now().UTC()))
table.AddRow(" |Session:", l.prefix)
table.AddRow(" |Content:", string(s))
color.Set(color.Bold, color.FgBlue)
fmt.Println("<=== Incoming FIX Msg: <===")
fmt.Println(table)
color.Unset()
}
func (l screenLog) OnOutgoing(s []byte) {
table := uitable.New()
table.MaxColWidth = 150
table.Wrap = true // wrap columns
table.AddRow(" |Time:", fmt.Sprintf("%v", time.Now().UTC()))
table.AddRow(" |Session:", l.prefix)
table.AddRow(" |Content:", string(s))
color.Set(color.Bold, color.FgMagenta)
fmt.Println("===> Outgoing FIX Msg: ===>")
fmt.Println(table)
color.Unset()
}
func (l screenLog) OnEvent(s string) {
table := uitable.New()
table.MaxColWidth = 150
table.Wrap = true // wrap columns
table.AddRow(" |Time:", fmt.Sprintf("%v", time.Now().UTC()))
table.AddRow(" |Session:", l.prefix)
table.AddRow(" |Content:", s)
color.Set(color.Bold, color.FgCyan)
fmt.Println("==== Event: ====")
fmt.Println(table)
color.Unset()
}
func (l screenLog) OnEventf(format string, a ...interface{}) {
l.OnEvent(fmt.Sprintf(format, a...))
}
type screenLogFactory struct{}
func (screenLogFactory) Create() (quickfix.Log, error) {
log := screenLog{"GLOBAL"}
return log, nil
}
func (screenLogFactory) CreateSessionLog(sessionID quickfix.SessionID) (quickfix.Log, error) {
log := screenLog{sessionID.String()}
return log, nil
}
// NewFancyLog creates an instance of LogFactory that writes messages and events to stdout.
func NewFancyLog() quickfix.LogFactory {
return screenLogFactory{}
}