Skip to content

Commit

Permalink
Adds new log impls and renames files for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
ackleymi committed Sep 12, 2024
1 parent 2903198 commit 342c12e
Show file tree
Hide file tree
Showing 20 changed files with 789 additions and 29 deletions.
3 changes: 2 additions & 1 deletion _test/test-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/quickfixgo/quickfix/config"
field "github.com/quickfixgo/quickfix/gen/field"
tag "github.com/quickfixgo/quickfix/gen/tag"
filelog "github.com/quickfixgo/quickfix/log/file"
"github.com/quickfixgo/quickfix/store/file"
"github.com/quickfixgo/quickfix/store/mongo"
)
Expand Down Expand Up @@ -132,7 +133,7 @@ func main() {
return
}

fileLogFactory, err := quickfix.NewFileLogFactory(appSettings)
fileLogFactory, err := filelog.NewLogFactory(appSettings)
if err != nil {
fmt.Println("Error creating file log factory:", err)
return
Expand Down
2 changes: 1 addition & 1 deletion accepter_test.go → acceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestAcceptor_SetTLSConfig(t *testing.T) {
_, err := genericSettings.AddSession(sessionSettings)
require.NoError(t, err)

logger, err := NewScreenLogFactory().Create()
logger, err := NewNullLogFactory().Create()
require.NoError(t, err)
acceptor := &Acceptor{settings: genericSettings, globalLog: logger}
defer acceptor.Stop()
Expand Down
104 changes: 99 additions & 5 deletions config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,100 @@ const (
// Valid Values:
// - A valid path
FileLogPath string = "FileLogPath"

// 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).
// SQLLogDriver is only relevant if also using sql.NewLogFactory(..) in code
// when creating your LogFactory for your initiator or acceptor.
//
// Required: Only if using a sql db as your Log
//
// Default: N/A
//
// Valid Values:
// - See https://go.dev/wiki/SQLDrivers
SQLLogDriver string = "SQLLogDriver"

// SQLLogDataSourceName sets the driver-specific data source name of the database to use for application logs.
// This usually consists of at least a database name and connection information.
// SQLLogDataSourceName is only relevant if also using sql.NewLogFactory(..) in code
// when creating your LogFactory for your initiator or acceptor.
//
// See https://pkg.go.dev/database/sql#Open for more information.
//
// Required: Only if using a sql db as your Log.
//
// Default: N/A
//
// Valid Values:
// - A string correspondinng to a datasource
SQLLogDataSourceName string = "SQLLogDataSourceName"

// SQLLogConnMaxLifetime sets the maximum duration of time that a database connection may be reused.
// See https://pkg.go.dev/database/sql#DB.SetConnMaxLifetime for more information.
//
// If your database server has a config option to close inactive connections after some duration (e.g. MySQL "wait_timeout"),
// set SQLLogConnMaxLifetime to a value less than that duration.
//
// Example Values:
// - SQLLogConnMaxLifetime=14400s # 14400 seconds
// - SQLLogConnMaxLifetime=2h45m # 2 hours and 45 minutes
//
// SQLLogConnMaxLifetime is only relevant if also using sql.NewLogFactory(..) in code
// when creating your LogFactory for your initiator or acceptor.
//
// Required: No
//
// Default: 0 (forever)
//
// Valid Values:
// - A valid go time.Duration
SQLLogConnMaxLifetime string = "SQLLogConnMaxLifetime"

// MongoLogConnection sets the MongoDB connection URL to use for application logs.
//
// See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Connect for more information.
//
// MongoLogConnection is only relevant if also using mongo.NewLogFactory(..) in code
// when creating your LogFactory for your initiator or acceptor.
//
// Required: Only if using MongoDB as your Log.
//
// Default: N/A
//
// Valid Values:
// - A string representing a MongoDB connection
MongoLogConnection string = "MongoLogConnection"

// MongoLogDatabase sets the MongoDB-specific name of the database to use for application logs.
//
// See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Connect for more information.
//
// MongoLogDatabase is only relevant if also using mongo.NewLogFactory(..) in code
// when creating your LogFactory for your initiator or acceptor.
//
// Required: Only if using MongoDB as your Log.
//
// Default: N/A
//
// Valid Values:
// - A string corresponding to a MongoDB database
MongoLogDatabase string = "MongoLogDatabase"

// MongoLogReplicaSet sets the MongoDB replica set to use for application logs.
// This is optional.
//
// See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Connect for more information.
//
// MongoLogReplicaSet is only relevant if also using mongo.NewLogFactory(..) in code
// when creating your LogFactory for your initiator or acceptor.
//
// Required: No
//
// Default: N/A
//
// Valid Values:
// - A string corresponding to a MongoDB replica set
MongoLogReplicaSet string = "MongoLogReplicaSet"
)

const (
Expand Down Expand Up @@ -895,7 +989,7 @@ const (
// - N
FileStoreSync string = "FileStoreSync"

// SQLStoreDriver sets the name of the database driver to use (see https://go.dev/wiki/SQLDrivers for the list of available drivers).
// 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).
// SQLStoreDriver is only relevant if also using sql.NewStoreFactory(..) in code
// when creating your MessageStoreFactory for your initiator or acceptor.
//
Expand All @@ -907,7 +1001,7 @@ const (
// - See https://go.dev/wiki/SQLDrivers
SQLStoreDriver string = "SQLStoreDriver"

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

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

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

// MongoStoreReplicaSet sets the MongoDB replica set to use.
// MongoStoreReplicaSet sets the MongoDB replica set to use for message storage.
// This is optional.
//
// See https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Connect for more information.
Expand Down
15 changes: 8 additions & 7 deletions file_log.go → log/file/file_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
// Contact [email protected] if any conditions of this licensing
// are not clear to you.

package quickfix
package file

import (
"fmt"
"log"
"os"
"path"

"github.com/quickfixgo/quickfix"
"github.com/quickfixgo/quickfix/config"
)

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

type fileLogFactory struct {
globalLogPath string
sessionLogPaths map[SessionID]string
sessionLogPaths map[quickfix.SessionID]string
}

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

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

logFactory.sessionLogPaths = make(map[SessionID]string)
logFactory.sessionLogPaths = make(map[quickfix.SessionID]string)

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

func (f fileLogFactory) Create() (Log, error) {
func (f fileLogFactory) Create() (quickfix.Log, error) {
return newFileLog("GLOBAL", f.globalLogPath)
}

func (f fileLogFactory) CreateSessionLog(sessionID SessionID) (Log, error) {
func (f fileLogFactory) CreateSessionLog(sessionID quickfix.SessionID) (quickfix.Log, error) {
logPath, ok := f.sessionLogPaths[sessionID]

if !ok {
Expand Down
12 changes: 7 additions & 5 deletions file_log_test.go → log/file/file_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Contact [email protected] if any conditions of this licensing
// are not clear to you.

package quickfix
package file

import (
"bufio"
Expand All @@ -22,11 +22,13 @@ import (
"path"
"strings"
"testing"

"github.com/quickfixgo/quickfix"
)

func TestFileLog_NewFileLogFactory(t *testing.T) {

_, err := NewFileLogFactory(NewSettings())
_, err := NewLogFactory(quickfix.NewSettings())

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

factory, err := NewFileLogFactory(settings)
factory, err := NewLogFactory(settings)

if err != nil {
t.Error("Did not expect error", err)
Expand All @@ -68,7 +70,7 @@ SessionQualifier=BS
type fileLogHelper struct {
LogPath string
Prefix string
Log Log
Log quickfix.Log
}

func newFileLogHelper(t *testing.T) *fileLogHelper {
Expand Down
6 changes: 4 additions & 2 deletions fileutil.go → log/file/file_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
// Contact [email protected] if any conditions of this licensing
// are not clear to you.

package quickfix
package file

import (
"fmt"
"os"
"strings"

"github.com/quickfixgo/quickfix"
)

func sessionIDFilenamePrefix(s SessionID) string {
func sessionIDFilenamePrefix(s quickfix.SessionID) string {
sender := []string{s.SenderCompID}
if s.SenderSubID != "" {
sender = append(sender, s.SenderSubID)
Expand Down
7 changes: 4 additions & 3 deletions fileutil_test.go → log/file/file_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
// Contact [email protected] if any conditions of this licensing
// are not clear to you.

package quickfix
package file

import (
"fmt"
"os"
"path"
"testing"

"github.com/quickfixgo/quickfix"
"github.com/stretchr/testify/require"
)

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

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

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

func TestSessionIDFilename_FullyQualifiedSessionID(t *testing.T) {
// When the session ID is
sessionID := SessionID{
sessionID := quickfix.SessionID{
BeginString: "FIX.4.4",
SenderCompID: "A",
SenderSubID: "B",
Expand Down
Loading

0 comments on commit 342c12e

Please sign in to comment.