简体   繁体   中英

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

QuickFix/J provides functionality to store its logs in database.

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?

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.

You can create a Logger by implementing the "quickfix.Log" interface, and a LoggerFactory by implementing the "quickfix.LogFactory" interface.

The easiest approach would be to use the private AbstractLog from QuickFix/J.

Creating the Log 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 (eg 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, ie Console, database etc. as you will have to implement it yourself.

Creating the 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.

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.

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. eg The Logger that Logs on Console: ScreenLog , ScreenLogFactory

QuickFix/J source:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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