New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logger: Add support for toggling sub logger name output for log events #407
Changes from 4 commits
1500789
96edcf8
4c70c2e
38cd3cd
811ce2b
2bea5ce
77e647b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,24 +134,24 @@ func registerNewSubLogger(logger string) *subLogger { | |
|
||
// register all loggers at package init() | ||
func init() { | ||
Global = registerNewSubLogger("log") | ||
|
||
ConnectionMgr = registerNewSubLogger("connection") | ||
CommunicationMgr = registerNewSubLogger("comms") | ||
ConfigMgr = registerNewSubLogger("config") | ||
DatabaseMgr = registerNewSubLogger("database") | ||
OrderMgr = registerNewSubLogger("order") | ||
PortfolioMgr = registerNewSubLogger("portfolio") | ||
SyncMgr = registerNewSubLogger("sync") | ||
TimeMgr = registerNewSubLogger("timekeeper") | ||
WebsocketMgr = registerNewSubLogger("websocket") | ||
EventMgr = registerNewSubLogger("event") | ||
DispatchMgr = registerNewSubLogger("dispatch") | ||
|
||
ExchangeSys = registerNewSubLogger("exchange") | ||
GRPCSys = registerNewSubLogger("grpc") | ||
RESTSys = registerNewSubLogger("rest") | ||
|
||
Ticker = registerNewSubLogger("ticker") | ||
OrderBook = registerNewSubLogger("orderbook") | ||
Global = registerNewSubLogger("LOG") | ||
|
||
ConnectionMgr = registerNewSubLogger("CONNECTION") | ||
CommunicationMgr = registerNewSubLogger("COMMS") | ||
ConfigMgr = registerNewSubLogger("CONFIG") | ||
DatabaseMgr = registerNewSubLogger("DATABASE") | ||
OrderMgr = registerNewSubLogger("ORDER") | ||
PortfolioMgr = registerNewSubLogger("PORTFOLIO") | ||
SyncMgr = registerNewSubLogger("SYNC") | ||
TimeMgr = registerNewSubLogger("TIMEKEEPER") | ||
WebsocketMgr = registerNewSubLogger("WEBSOCKET") | ||
EventMgr = registerNewSubLogger("EVENT") | ||
DispatchMgr = registerNewSubLogger("DISPATCH") | ||
|
||
ExchangeSys = registerNewSubLogger("EXCHANGE") | ||
GRPCSys = registerNewSubLogger("GRPC") | ||
RESTSys = registerNewSubLogger("REST") | ||
|
||
Ticker = registerNewSubLogger("TICKER") | ||
OrderBook = registerNewSubLogger("ORDERBOOK") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While I don't really mind that these are changed to upper case can we either add support for migrating existing to upper case or even something as simple as strings.ToUpper in registerNewSubLogger (I have a config setup already with some subloggers configured :D) |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"bytes" | ||
"io/ioutil" | ||
"os" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
|
@@ -20,8 +21,9 @@ func SetupTest() { | |
Level: "INFO|WARN|DEBUG|ERROR", | ||
}, | ||
AdvancedSettings: advancedSettings{ | ||
Spacer: " | ", | ||
TimeStampFormat: timestampFormat, | ||
ShowLogSystemName: trueptr, | ||
Spacer: " | ", | ||
TimeStampFormat: timestampFormat, | ||
Headers: headers{ | ||
Info: "[INFO]", | ||
Warn: "[WARN]", | ||
|
@@ -31,7 +33,7 @@ func SetupTest() { | |
}, | ||
SubLoggers: []SubLoggerConfig{ | ||
{ | ||
Name: "test", | ||
Name: "TEST", | ||
Level: "INFO|DEBUG|WARN|ERROR", | ||
Output: "stdout", | ||
}}, | ||
|
@@ -101,9 +103,9 @@ func TestRemoveWriter(t *testing.T) { | |
func TestLevel(t *testing.T) { | ||
SetupTest() | ||
|
||
_, err := Level("log") | ||
_, err := Level("LOG") | ||
if err != nil { | ||
t.Errorf("Failed to get log %s levels skippin", err) | ||
t.Errorf("Failed to get log %s levels skipping", err) | ||
} | ||
|
||
_, err = Level("totallyinvalidlogger") | ||
|
@@ -115,7 +117,7 @@ func TestLevel(t *testing.T) { | |
func TestSetLevel(t *testing.T) { | ||
SetupTest() | ||
|
||
newLevel, err := SetLevel("log", "ERROR") | ||
newLevel, err := SetLevel("LOG", "ERROR") | ||
if err != nil { | ||
t.Skipf("Failed to get log %s levels skipping", err) | ||
} | ||
|
@@ -135,7 +137,7 @@ func TestSetLevel(t *testing.T) { | |
} | ||
|
||
func TestValidSubLogger(t *testing.T) { | ||
b, logPtr := validSubLogger("log") | ||
b, logPtr := validSubLogger("LOG") | ||
|
||
if !b { | ||
t.Skip("validSubLogger() should return found, pointer if valid logger found") | ||
|
@@ -153,7 +155,7 @@ func TestCloseLogger(t *testing.T) { | |
} | ||
|
||
func TestConfigureSubLogger(t *testing.T) { | ||
err := configureSubLogger("log", "INFO", os.Stdin) | ||
err := configureSubLogger("LOG", "INFO", os.Stdin) | ||
if err != nil { | ||
t.Skipf("configureSubLogger() returned unexpected error %v", err) | ||
} | ||
|
@@ -209,13 +211,13 @@ func BenchmarkInfoln(b *testing.B) { | |
|
||
func TestNewLogEvent(t *testing.T) { | ||
w := &bytes.Buffer{} | ||
logger.newLogEvent("out", "header", w) | ||
logger.newLogEvent("out", "header", "SUBLOGGER", w) | ||
|
||
if w.String() == "" { | ||
t.Error("newLogEvent() failed expected output got empty string") | ||
} | ||
|
||
err := logger.newLogEvent("out", "header", nil) | ||
err := logger.newLogEvent("out", "header", "SUBLOGGER", nil) | ||
if err == nil { | ||
t.Error("Error expected with output is set to nil") | ||
} | ||
|
@@ -225,7 +227,7 @@ func TestInfo(t *testing.T) { | |
w := &bytes.Buffer{} | ||
|
||
tempSL := subLogger{ | ||
"testymctestalot", | ||
"TESTYMCTESTALOT", | ||
splitLevel("INFO|WARN|DEBUG|ERROR"), | ||
w, | ||
} | ||
|
@@ -239,10 +241,27 @@ func TestInfo(t *testing.T) { | |
tempSL.output = nil | ||
w.Reset() | ||
|
||
SetLevel("testymctestalot", "INFO") | ||
SetLevel("TESTYMCTESTALOT", "INFO") | ||
Debug(&tempSL, "HelloHello") | ||
|
||
if w.String() != "" { | ||
t.Error("Expected output buffer to be empty but Debug wrote to output") | ||
} | ||
} | ||
|
||
func TestSubLoggerName(t *testing.T) { | ||
SetupTest() | ||
w := &bytes.Buffer{} | ||
|
||
logger.newLogEvent("out", "header", "SUBLOGGER", w) | ||
if !strings.Contains(w.String(), "SUBLOGGER") { | ||
t.Error("Expected SUBLOGGER in output") | ||
} | ||
|
||
logger.ShowLogSystemName = false | ||
w = &bytes.Buffer{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can be changed to w.Reset() |
||
logger.newLogEvent("out", "header", "SUBLOGGER", w) | ||
if strings.Contains(w.String(), "SUBLOGGER") { | ||
t.Error("Unexpected SUBLOGGER in output") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be a nil pointer and cause a segfault if people don't have "showLogSystemName" in their config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoopsies!