QuickFix/J 提供将其日志存储在数据库中的功能。
是否可以将另一列(业务 ID) append 到其中一个表中,从而不会在 QuickFix/J 的内部消息日志记录中造成问题?
如果可能的话,请提及执行此操作的程序。
最佳答案
解决方案是创建您自己的 Logger 和 LoggerFactory,类似于 QuickFix/J 提供的 Logger 和 LoggerFactory。
您可以通过实现“quickfix.Log”接口(interface)创建Logger,并通过实现“quickfix.LogFactory”接口(interface)创建LoggerFactory。
最简单的方法是使用 QuickFix/J 中的私有(private) AbstractLog。
创建 Log 类:
- Copy the AbstractLog class as it is from QuickFix/J's source and include it in your project.
- Create a class which extends the AbstractLog class and implement all the abstract methods.
- 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.
- 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:
Create a LoggerFactory that implements the quickfix.LogFactory interface.
In the "create" method, create and return the instance of the Logger you created before using the constructor you require.
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 实现来寻求帮助将是一个好主意。 例如登录控制台的Logger:ScreenLog , ScreenLogFactory
QuickFix/J 来源:
关于java - 将列 append 到 QuickFix/J Logs 数据库(自定义 QuickFix/J Logger),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33033629/