In quickfix we use FileLogPath to configure log files. Streaming and trading sessions might create lot of log files but there is no way to archive this files. We might end up with crashing an server due to space issue. To avoid such situation we may need to stop and clear the files periodically. This is manual and difficult job for long term point of view.
Now access the logger in quickfix implementation class and use this logging where ever we need to log it.
That's it. Now we can log where ever we need and all the logs going to quickfix log file. This file will be automatically archived after reaching 250 MB.
[DEFAULT] ConnectionType=initiator SocketConnectHost=127.0.0.1 CheckLatency=N StartTime=12:00:00 EndTime=13:05:00 FileStorePath=logs/fix-session FileLogPath=logs/fix-clientWe have options in quickfix instead of using FileLogFactoy we can use other factory methods but that's not easy if your quickfix layer is part of the application and that application already using another logging framework.
LogFactory logFactory = new FileLogFactory(settings);Now lets see how logback framework can be used in quickfix to solve this issue. First we need to disable default logging given by quickfix as like below. We need to pass null in the logfactory argument then quickfix automatically creates NULLLOGFactory as default implementation and then no more logging going forward.
InputStream inputStream = new FileInputStream(new File(configFile)); settings = new SessionSettings(inputStream); MessageStoreFactory messageStoreFactory = new FileStoreFactory(settings); messageFactory = new DefaultMessageFactory(); initiator = new SocketInitiator(this, messageStoreFactory, settings, null, messageFactory);We disabled quickfix logging. Lets configure logback for quickfix. First create Logger and Appender in logback.xml as like below
<appender class="ch.qos.logback.core.rolling.RollingFileAppender" name="Quick-fix-appender"> <file>logs/quickfix.log</file> <rollingpolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <filenamepattern>logs/fix.%d{yyyy-MM-dd}.%i.log.gz </filenamepattern> <timebasedfilenamingandtriggeringpolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxfilesize>250MB</maxfilesize> </timebasedfilenamingandtriggeringpolicy> </rollingpolicy> <encoder> <pattern>%msg%n</pattern> </encoder> </appender> <logger additivity="false" level="INFO" name="quick-fix-logger"> <appender-ref ref="Quick-fix-appender"> </appender-ref></logger>
Now access the logger in quickfix implementation class and use this logging where ever we need to log it.
public class FixApplication implements Application{ static final Logger LOG = LoggerFactory. getLogger("quick-fix-logger"); @Override public void onConnect() { LOG.info("onConnect"); } }
That's it. Now we can log where ever we need and all the logs going to quickfix log file. This file will be automatically archived after reaching 250 MB.
0 Comments
Post a Comment