将列附加到 QuickFix/J 日志数据库(自定义 QuickFix/J 记录器)

Append column to QuickFix/J Logs database (Custom QuickFix/J Logger)

QuickFix/J 提供将其日志存储在数据库中的功能。

是否可以将另一列(业务 ID)附加到其 table 中,从而不会在 QuickFix/J 的内部消息记录中引起问题?

如果可以的话,也请说明程序。

解决方案是创建您自己的 Logger 和 LoggerFactory,类似于 QuickFix/J 提供的那些。

您可以通过实现 "quickfix.Log" 接口创建一个 Logger,通过实现 "quickfix.LogFactory" 接口创建一个 LoggerFactory。

最简单的方法是使用来自 QuickFix/J 的私有 AbstractLog。

创建日志class:

  1. Copy the AbstractLog class as it is from QuickFix/J's source and include it in your project.
  2. Create a class which extends the AbstractLog class and implement all the abstract methods.
  3. Create member variables for any extra field you want to append to the logs (e.g. business ID), and provide a constructor which takes is as an argument and sets its value.
  4. The "logIncoming" and "logOutgoing" methods take a String parameter. This is the data you want to log. At this point you can append your own fields (added in point 3) to the logs. You can format the log as you wish and you are free to use any method of output, i.e. Console, database etc. as you will have to implement it yourself.

创建 LoggerFactory:

  1. Create a LoggerFactory that implements the quickfix.LogFactory interface.

  2. In the "create" method, create and return the instance of the Logger you created before using the constructor you require.

  3. The values that you need to be passed to the constructor can be kept as member variables of the LoggerFactory and set in LoggerFactory's constructor.

您现在有一个自定义记录器,可以使用它作为 QuickFix/J 自己的记录器,并且 QuickFix/J 将自动使用您的记录器进行记录。

ApplicationAdapter application = new FixInitiator();
SessionSettings settings = new SessionSettings("./config/initiator.cfg");
CustomLogFactory customLogFactory = new CustomLogFactory(settings, myCustomID);
DefaultMessageFactory messageFactory = new DefaultMessageFactory();
FileStoreFactory fileStoreFactory = new FileStoreFactory(settings);
socketInitiator = new SocketInitiator(application, fileStoreFactory, settings, customLogFactory, messageFactory);
socketInitiator.start(); 

查看 QuickFix/J 自己的 Logger 和 LoggerFactory 实现以获得帮助是个好主意。 例如在控制台上登录的记录器:ScreenLog, ScreenLogFactory

QuickFix/J 来源:

https://github.com/quickfix-j/quickfixj