简体   繁体   English

将列附加到 QuickFix/J Logs 数据库(自定义 QuickFix/J Logger)

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

QuickFix/J provides functionality to store its logs in database. QuickFix/J 提供将其日志存储在数据库中的功能。

Is it possible to append another column (business ID) to one of its table in such a way that it does not cause problems in QuickFix/J's internal message logging?是否可以将另一列(业务 ID)附加到其中一个表中,从而不会导致 QuickFix/J 的内部消息日志记录出现问题?

If it is possible kindly mention the procedure to do it too.如果可能,请提及执行此操作的程序。

The solution is to create your own Logger and LoggerFactory similar to the ones provided by QuickFix/J.解决方案是创建您自己的 Logger 和 LoggerFactory,类似于 QuickFix/J 提供的 Logger 和 LoggerFactory。

You can create a Logger by implementing the "quickfix.Log" interface, and a LoggerFactory by implementing the "quickfix.LogFactory" interface.你可以通过实现“quickfix.Log”接口来创建一个Logger,通过实现“quickfix.LogFactory”接口来创建一个LoggerFactory。

The easiest approach would be to use the private AbstractLog from QuickFix/J.最简单的方法是使用 QuickFix/J 中的私有 AbstractLog。

Creating the Log class:创建日志类:

  1. Copy the AbstractLog class as it is from QuickFix/J's source and include it in your project.从 QuickFix/J 的源代码中复制AbstractLog类并将其包含在您的项目中。
  2. Create a class which extends the AbstractLog class and implement all the abstract methods.创建一个扩展 AbstractLog 类并实现所有抽象方法的类。
  3. Create member variables for any extra field you want to append to the logs (eg business ID), and provide a constructor which takes is as an argument and sets its value.为要附加到日志的任何额外字段(例如业务 ID)创建成员变量,并提供一个将 is 作为参数并设置其值的构造函数。
  4. The "logIncoming" and "logOutgoing" methods take a String parameter. “logIncoming”和“logOutgoing”方法采用字符串参数。 This is the data you want to log.这是您要记录的数据。 At this point you can append your own fields (added in point 3) to the logs.此时,您可以将自己的字段(在第 3 点中添加)附加到日志中。 You can format the log as you wish and you are free to use any method of output, ie Console, database etc. as you will have to implement it yourself.您可以根据需要格式化日志,您可以自由使用任何输出方法,即控制台、数据库等,因为您必须自己实现它。

Creating the LoggerFactory:创建 LoggerFactory:

  1. Create a LoggerFactory that implements the quickfix.LogFactory interface.创建一个实现 quickfix.LogFactory 接口的 LoggerFactory。

  2. In the "create" method, create and return the instance of the Logger you created before using the constructor you require.在“create”方法中,创建并返回您在使用您需要的构造函数之前创建的 Logger 的实例。

  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.您需要传递给构造函数的值可以保留为 LoggerFactory 的成员变量,并在 LoggerFactory 的构造函数中设置。

You have a custom Logger now and can use it as QuickFix/J's own loggers are used, and QuickFix/J will automatically log using your logger.您现在有一个自定义记录器,可以在使用 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(); 

Taking a look at QuickFix/J's own Logger and LoggerFactory implementations for help would be a good idea.查看 QuickFix/J 自己的 Logger 和 LoggerFactory 实现以获得帮助将是一个好主意。 eg The Logger that Logs on Console: ScreenLog , ScreenLogFactory例如登录控制台的记录器: ScreenLogScreenLogFactory

QuickFix/J source: QuickFix/J 来源:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM