Skip to content

Commit 9c5d08c

Browse files
committed
Adds new log impls and renames files for consistency
1 parent b7d706f commit 9c5d08c

20 files changed

+789
-29
lines changed

_test/test-server/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/quickfixgo/quickfix/config"
1818
field "github.com/quickfixgo/quickfix/gen/field"
1919
tag "github.com/quickfixgo/quickfix/gen/tag"
20+
filelog "github.com/quickfixgo/quickfix/log/file"
2021
"github.com/quickfixgo/quickfix/store/file"
2122
"github.com/quickfixgo/quickfix/store/mongo"
2223
)
@@ -132,7 +133,7 @@ func main() {
132133
return
133134
}
134135

135-
fileLogFactory, err := quickfix.NewFileLogFactory(appSettings)
136+
fileLogFactory, err := filelog.NewLogFactory(appSettings)
136137
if err != nil {
137138
fmt.Println("Error creating file log factory:", err)
138139
return

accepter_test.go renamed to acceptor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func TestAcceptor_SetTLSConfig(t *testing.T) {
9898
_, err := genericSettings.AddSession(sessionSettings)
9999
require.NoError(t, err)
100100

101-
logger, err := NewScreenLogFactory().Create()
101+
logger, err := NewNullLogFactory().Create()
102102
require.NoError(t, err)
103103
acceptor := &Acceptor{settings: genericSettings, globalLog: logger}
104104
defer acceptor.Stop()

config/configuration.go

Lines changed: 99 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,100 @@ const (
849849
// Valid Values:
850850
// - A valid path
851851
FileLogPath string = "FileLogPath"
852+
853+
// SQLLogDriver sets the name of the database driver to use for application logs (see https://go.dev/wiki/SQLDrivers for the list of available drivers).
854+
// SQLLogDriver is only relevant if also using sql.NewLogFactory(..) in code
855+
// when creating your LogFactory for your initiator or acceptor.
856+
//
857+
// Required: Only if using a sql db as your Log
858+
//
859+
// Default: N/A
860+
//
861+
// Valid Values:
862+
// - See https://go.dev/wiki/SQLDrivers
863+
SQLLogDriver string = "SQLLogDriver"
864+
865+
// SQLLogDataSourceName sets the driver-specific data source name of the database to use for application logs.
866+
// This usually consists of at least a database name and connection information.
867+
// SQLLogDataSourceName is only relevant if also using sql.NewLogFactory(..) in code
868+
// when creating your LogFactory for your initiator or acceptor.
869+
//
870+
// See https://pkg.go.dev/database/sql#Open for more information.
871+
//
872+
// Required: Only if using a sql db as your Log.
873+
//
874+
// Default: N/A
875+
//
876+
// Valid Values:
877+
// - A string correspondinng to a datasource
878+
SQLLogDataSourceName string = "SQLLogDataSourceName"
879+
880+
// SQLLogConnMaxLifetime sets the maximum duration of time that a database connection may be reused.
881+
// See https://pkg.go.dev/database/sql#DB.SetConnMaxLifetime for more information.
882+
//
883+
// If your database server has a config option to close inactive connections after some duration (e.g. MySQL "wait_timeout"),
884+
// set SQLLogConnMaxLifetime to a value less than that duration.
885+
//
886+
// Example Values:
887+
// - SQLLogConnMaxLifetime=14400s # 14400 seconds
888+
// - SQLLogConnMaxLifetime=2h45m # 2 hours and 45 minutes
889+
//
890+
// SQLLogConnMaxLifetime is only relevant if also using sql.NewLogFactory(..) in code
891+
// when creating your LogFactory for your initiator or acceptor.
892+
//
893+
// Required: No
894+
//
895+
// Default: 0 (forever)
896+
//
897+
// Valid Values:
898+
// - A valid go time.Duration
899+
SQLLogConnMaxLifetime string = "SQLLogConnMaxLifetime"
900+
901+
// MongoLogConnection sets the MongoDB connection URL to use for application logs.
902+
//
903+
// See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Connect for more information.
904+
//
905+
// MongoLogConnection is only relevant if also using mongo.NewLogFactory(..) in code
906+
// when creating your LogFactory for your initiator or acceptor.
907+
//
908+
// Required: Only if using MongoDB as your Log.
909+
//
910+
// Default: N/A
911+
//
912+
// Valid Values:
913+
// - A string representing a MongoDB connection
914+
MongoLogConnection string = "MongoLogConnection"
915+
916+
// MongoLogDatabase sets the MongoDB-specific name of the database to use for application logs.
917+
//
918+
// See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Connect for more information.
919+
//
920+
// MongoLogDatabase is only relevant if also using mongo.NewLogFactory(..) in code
921+
// when creating your LogFactory for your initiator or acceptor.
922+
//
923+
// Required: Only if using MongoDB as your Log.
924+
//
925+
// Default: N/A
926+
//
927+
// Valid Values:
928+
// - A string corresponding to a MongoDB database
929+
MongoLogDatabase string = "MongoLogDatabase"
930+
931+
// MongoLogReplicaSet sets the MongoDB replica set to use for application logs.
932+
// This is optional.
933+
//
934+
// See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Connect for more information.
935+
//
936+
// MongoLogReplicaSet is only relevant if also using mongo.NewLogFactory(..) in code
937+
// when creating your LogFactory for your initiator or acceptor.
938+
//
939+
// Required: No
940+
//
941+
// Default: N/A
942+
//
943+
// Valid Values:
944+
// - A string corresponding to a MongoDB replica set
945+
MongoLogReplicaSet string = "MongoLogReplicaSet"
852946
)
853947

854948
const (
@@ -895,7 +989,7 @@ const (
895989
// - N
896990
FileStoreSync string = "FileStoreSync"
897991

898-
// SQLStoreDriver sets the name of the database driver to use (see https://go.dev/wiki/SQLDrivers for the list of available drivers).
992+
// SQLStoreDriver sets the name of the database driver to use for message storage (see https://go.dev/wiki/SQLDrivers for the list of available drivers).
899993
// SQLStoreDriver is only relevant if also using sql.NewStoreFactory(..) in code
900994
// when creating your MessageStoreFactory for your initiator or acceptor.
901995
//
@@ -907,7 +1001,7 @@ const (
9071001
// - See https://go.dev/wiki/SQLDrivers
9081002
SQLStoreDriver string = "SQLStoreDriver"
9091003

910-
// SQLStoreDataSourceName sets the driver-specific data source name of the database to use.
1004+
// SQLStoreDataSourceName sets the driver-specific data source name of the database to use for messagge storage.
9111005
// This usually consists of at least a database name and connection information.
9121006
// SQLStoreDataSourceName is only relevant if also using sql.NewStoreFactory(..) in code
9131007
// when creating your MessageStoreFactory for your initiator or acceptor.
@@ -943,7 +1037,7 @@ const (
9431037
// - A valid go time.Duration
9441038
SQLStoreConnMaxLifetime string = "SQLStoreConnMaxLifetime"
9451039

946-
// MongoStoreConnection sets the MongoDB connection URL to use.
1040+
// MongoStoreConnection sets the MongoDB connection URL to use for message storage.
9471041
//
9481042
// See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Connect for more information.
9491043
//
@@ -958,7 +1052,7 @@ const (
9581052
// - A string representing a MongoDB connection
9591053
MongoStoreConnection string = "MongoStoreConnection"
9601054

961-
// MongoStoreDatabase sets the MongoDB-specific name of the database to use.
1055+
// MongoStoreDatabase sets the MongoDB-specific name of the database to use for message storage.
9621056
//
9631057
// See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Connect for more information.
9641058
//
@@ -973,7 +1067,7 @@ const (
9731067
// - A string corresponding to a MongoDB database
9741068
MongoStoreDatabase string = "MongoStoreDatabase"
9751069

976-
// MongoStoreReplicaSet sets the MongoDB replica set to use.
1070+
// MongoStoreReplicaSet sets the MongoDB replica set to use for message storage.
9771071
// This is optional.
9781072
//
9791073
// See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Connect for more information.

file_log.go renamed to log/file/file_log.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
// Contact ask@quickfixengine.org if any conditions of this licensing
1414
// are not clear to you.
1515

16-
package quickfix
16+
package file
1717

1818
import (
1919
"fmt"
2020
"log"
2121
"os"
2222
"path"
2323

24+
"github.com/quickfixgo/quickfix"
2425
"github.com/quickfixgo/quickfix/config"
2526
)
2627

@@ -47,20 +48,20 @@ func (l fileLog) OnEventf(format string, v ...interface{}) {
4748

4849
type fileLogFactory struct {
4950
globalLogPath string
50-
sessionLogPaths map[SessionID]string
51+
sessionLogPaths map[quickfix.SessionID]string
5152
}
5253

53-
// NewFileLogFactory creates an instance of LogFactory that writes messages and events to file.
54+
// NewLogFactory creates an instance of LogFactory that writes messages and events to file.
5455
// The location of global and session log files is configured via FileLogPath.
55-
func NewFileLogFactory(settings *Settings) (LogFactory, error) {
56+
func NewLogFactory(settings *quickfix.Settings) (quickfix.LogFactory, error) {
5657
logFactory := fileLogFactory{}
5758

5859
var err error
5960
if logFactory.globalLogPath, err = settings.GlobalSettings().Setting(config.FileLogPath); err != nil {
6061
return logFactory, err
6162
}
6263

63-
logFactory.sessionLogPaths = make(map[SessionID]string)
64+
logFactory.sessionLogPaths = make(map[quickfix.SessionID]string)
6465

6566
for sid, sessionSettings := range settings.SessionSettings() {
6667
logPath, err := sessionSettings.Setting(config.FileLogPath)
@@ -101,11 +102,11 @@ func newFileLog(prefix string, logPath string) (fileLog, error) {
101102
return l, nil
102103
}
103104

104-
func (f fileLogFactory) Create() (Log, error) {
105+
func (f fileLogFactory) Create() (quickfix.Log, error) {
105106
return newFileLog("GLOBAL", f.globalLogPath)
106107
}
107108

108-
func (f fileLogFactory) CreateSessionLog(sessionID SessionID) (Log, error) {
109+
func (f fileLogFactory) CreateSessionLog(sessionID quickfix.SessionID) (quickfix.Log, error) {
109110
logPath, ok := f.sessionLogPaths[sessionID]
110111

111112
if !ok {

file_log_test.go renamed to log/file/file_log_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Contact ask@quickfixengine.org if any conditions of this licensing
1414
// are not clear to you.
1515

16-
package quickfix
16+
package file
1717

1818
import (
1919
"bufio"
@@ -22,11 +22,13 @@ import (
2222
"path"
2323
"strings"
2424
"testing"
25+
26+
"github.com/quickfixgo/quickfix"
2527
)
2628

2729
func TestFileLog_NewFileLogFactory(t *testing.T) {
2830

29-
_, err := NewFileLogFactory(NewSettings())
31+
_, err := NewLogFactory(quickfix.NewSettings())
3032

3133
if err == nil {
3234
t.Error("Should expect error when settings have no file log path")
@@ -52,9 +54,9 @@ TargetCompID=ARCA
5254
SessionQualifier=BS
5355
`
5456
stringReader := strings.NewReader(cfg)
55-
settings, _ := ParseSettings(stringReader)
57+
settings, _ := quickfix.ParseSettings(stringReader)
5658

57-
factory, err := NewFileLogFactory(settings)
59+
factory, err := NewLogFactory(settings)
5860

5961
if err != nil {
6062
t.Error("Did not expect error", err)
@@ -68,7 +70,7 @@ SessionQualifier=BS
6870
type fileLogHelper struct {
6971
LogPath string
7072
Prefix string
71-
Log Log
73+
Log quickfix.Log
7274
}
7375

7476
func newFileLogHelper(t *testing.T) *fileLogHelper {

fileutil.go renamed to log/file/file_util.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313
// Contact ask@quickfixengine.org if any conditions of this licensing
1414
// are not clear to you.
1515

16-
package quickfix
16+
package file
1717

1818
import (
1919
"fmt"
2020
"os"
2121
"strings"
22+
23+
"github.com/quickfixgo/quickfix"
2224
)
2325

24-
func sessionIDFilenamePrefix(s SessionID) string {
26+
func sessionIDFilenamePrefix(s quickfix.SessionID) string {
2527
sender := []string{s.SenderCompID}
2628
if s.SenderSubID != "" {
2729
sender = append(sender, s.SenderSubID)

fileutil_test.go renamed to log/file/file_util_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
// Contact ask@quickfixengine.org if any conditions of this licensing
1414
// are not clear to you.
1515

16-
package quickfix
16+
package file
1717

1818
import (
1919
"fmt"
2020
"os"
2121
"path"
2222
"testing"
2323

24+
"github.com/quickfixgo/quickfix"
2425
"github.com/stretchr/testify/require"
2526
)
2627

@@ -37,15 +38,15 @@ func requireFileExists(t *testing.T, fname string) {
3738

3839
func TestSessionIDFilename_MinimallyQualifiedSessionID(t *testing.T) {
3940
// When the session ID is
40-
sessionID := SessionID{BeginString: "FIX.4.4", SenderCompID: "SENDER", TargetCompID: "TARGET"}
41+
sessionID := quickfix.SessionID{BeginString: "FIX.4.4", SenderCompID: "SENDER", TargetCompID: "TARGET"}
4142

4243
// Then the filename should be
4344
require.Equal(t, "FIX.4.4-SENDER-TARGET", sessionIDFilenamePrefix(sessionID))
4445
}
4546

4647
func TestSessionIDFilename_FullyQualifiedSessionID(t *testing.T) {
4748
// When the session ID is
48-
sessionID := SessionID{
49+
sessionID := quickfix.SessionID{
4950
BeginString: "FIX.4.4",
5051
SenderCompID: "A",
5152
SenderSubID: "B",

0 commit comments

Comments
 (0)