Created by: pilotso11
ZAP logger for quickfix
To use:
...
// Initialize zap
zapCfg := zap.NewDevelopmentConfig()
zapCfg.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder // colourize levels
Atom := zapCfg.Level // use Atom to turn on/off log levels if you need to
logger, _ := zapCfg.Build()
zap.ReplaceGlobals(logger)
...
logFactory := quickfix.NewZapLogFactory("FIX_", true) // FIX_ prefix and message logging enabled
acceptor, err := quickfix.NewAcceptor(app, messageStoreFactory, appSettings, logFactory)
...
Uses ZAP (https://pkg.go.dev/go.uber.org/zap), a very low latency logger for golang which supports:
- screen logging
- json logging
- caller details with line numbers (short and full path)
- default configurations that give stack traces when appropropriate in dev and production default configurations.
This wrapper passes all the quickfix logging directly to zap at INFO
level.
It sets a named logger for each session with Prefix+Sender:Target
as the label.
Setting prefix to ""
results in the message being labeled with just the sender and target.
For example if the Sender is SEND
and the target is TARG
and the prefix is FIX_
then the name will be FIX_SEND:TARG
.
There is also an option to enable or disable detailed message logging.
If message logging is enabled, EOM
field separators are replaced with |
for readability.
With no prefix you will see log messages similar to this using console/debug logging.
2022-12-28T00:59:05.023Z INFO FROMCOMP:TOCOMP quickfix@v0.6.1/session_state.go:69 incoming <-: 8=FIXT.1.1|9=76|35=CW|34=32|49=TOCOMP|52=20221228-00:59:05.022921|56=FROMCOMP|117=ID09876|297=0|10=187|
And with json logging
{"level":"info","ts":1672189226.004965,"logger":"FROMCOMP:TOCOMP","caller":"quickfix@v0.6.1/session.go:355","msg":"outgoing ->: 8=FIXT.1.1|9=81|35=A|34=1|49=FROMCOMP|52=20221228-01:00:26.004921|56=TOCOMP|98=0|108=30|141=Y|1137=9|10=039|"}
Tests have been added. Unfortunately without completely mocking the logger it is difficult to test the actual logging functions, but as they are passthroughs to ZAP there are unlikely to be any regression errors in this factory and logger.
Possible future improvements:
- Take advantage of ZAP field based logging to put the message body in its own json field
- Allow different log levels for messages and events
- Pre-check info is enabled - which would save some formatting time if info is disabled (unlikely?)
- Support split logging of events to ZAP and messages to a file