Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/new logging #743

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions AcceptanceTest/ATApplication.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using QuickFix;

namespace AcceptanceTest
Expand All @@ -8,11 +9,11 @@ public class ATApplication : MessageCracker, IApplication
public event System.Action StopMeEvent;

private HashSet<KeyValuePair<string, SessionID>> clOrdIDs_ = new HashSet<KeyValuePair<string, SessionID>>();
private FileLog log_;
private ILogger _logger;

public ATApplication(FileLog debugLog)
public ATApplication(ILogger debugLog)
{
log_ = debugLog;
_logger = debugLog;
}

public void OnMessage(QuickFix.FIX40.NewOrderSingle nos, SessionID sessionID)
Expand Down Expand Up @@ -172,7 +173,7 @@ public void FromApp(Message message, SessionID sessionID)
}
catch (System.Exception e)
{
log_.OnEvent("FromApp: " + e.ToString() + " while processing msg (" + message.ToString() + ")");
_logger.LogEvent("FromApp: " + e.ToString() + " while processing msg (" + message.ToString() + ")");
}
}

Expand Down
2 changes: 1 addition & 1 deletion AcceptanceTest/AcceptanceTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net461;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<Platforms>AnyCPU;x64</Platforms>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Examples/Executor/Examples.Executor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net461;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<RootNamespace>Executor</RootNamespace>
<AssemblyName>Executor</AssemblyName>
<Copyright>Copyright © Connamara Systems, LLC 2011</Copyright>
Expand Down
1 change: 1 addition & 0 deletions Examples/Executor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Runtime.ConstrainedExecution;
using System.Text;
using Acceptor;
using Microsoft.Extensions.Logging;
using QuickFix;

namespace Executor
Expand Down
2 changes: 1 addition & 1 deletion Examples/SimpleAcceptor/Examples.SimpleAcceptor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net461;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<RootNamespace>SimpleAcceptor</RootNamespace>
<AssemblyName>SimpleAcceptor</AssemblyName>
<Copyright>Copyright © Connamara Systems, LLC 2011</Copyright>
Expand Down
6 changes: 5 additions & 1 deletion Examples/TradeClient/Examples.TradeClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
<RootNamespace>TradeClient</RootNamespace>
<AssemblyName>TradeClient</AssemblyName>
<Copyright>Copyright © Connamara Systems, LLC 2011</Copyright>
Expand All @@ -20,6 +20,10 @@
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.29" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Messages\FIX44\QuickFix.FIX44.csproj" />
<ProjectReference Include="..\..\QuickFIXn\QuickFix.csproj" />
Expand Down
5 changes: 3 additions & 2 deletions Examples/TradeClient/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -32,7 +33,7 @@ static void Main(string[] args)
QuickFix.SessionSettings settings = new QuickFix.SessionSettings(file);
TradeClientApp application = new TradeClientApp();
QuickFix.IMessageStoreFactory storeFactory = new QuickFix.FileStoreFactory(settings);
QuickFix.ILogFactory logFactory = new QuickFix.ScreenLogFactory(settings);
ILoggerFactory logFactory = LoggerFactory.Create(x => x.AddConsole());
QuickFix.Transport.SocketInitiator initiator = new QuickFix.Transport.SocketInitiator(application, storeFactory, settings, logFactory);

// this is a developer-test kludge. do not emulate.
Expand Down
22 changes: 18 additions & 4 deletions QuickFIXn/AbstractInitiator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Threading;
using System.Collections.Generic;
using System;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;

namespace QuickFix
{
Expand All @@ -10,7 +12,7 @@ public abstract class AbstractInitiator : IInitiator
private IApplication _app = null;
private IMessageStoreFactory _storeFactory = null;
private SessionSettings _settings = null;
private ILogFactory _logFactory = null;
private ILoggerFactory _loggerFactory = null;
private IMessageFactory _msgFactory = null;

private object sync_ = new object();
Expand All @@ -33,20 +35,32 @@ public bool IsStopped
#endregion

public AbstractInitiator(IApplication app, IMessageStoreFactory storeFactory, SessionSettings settings)
: this(app, storeFactory, settings, null, null)
: this(app, storeFactory, settings, (ILoggerFactory)null, null)
{ }

[Obsolete]
public AbstractInitiator(IApplication app, IMessageStoreFactory storeFactory, SessionSettings settings, ILogFactory logFactory)
: this(app, storeFactory, settings, logFactory, null)
{ }

[Obsolete]
public AbstractInitiator(
IApplication app, IMessageStoreFactory storeFactory, SessionSettings settings, ILogFactory logFactory, IMessageFactory messageFactory)
: this(app, storeFactory, settings, LoggerExtensions.LoggerFactoryTransient(logFactory), messageFactory)
{
}

public AbstractInitiator(IApplication app, IMessageStoreFactory storeFactory, SessionSettings settings, ILoggerFactory loggerFactory)
: this(app, storeFactory, settings, loggerFactory, null)
{ }

public AbstractInitiator(
IApplication app, IMessageStoreFactory storeFactory, SessionSettings settings, ILoggerFactory loggerFactory, IMessageFactory messageFactory)
{
_app = app;
_storeFactory = storeFactory;
_settings = settings;
_logFactory = logFactory ?? new NullLogFactory();
_loggerFactory = loggerFactory ?? NullLoggerFactory.Instance;
_msgFactory = messageFactory ?? new DefaultMessageFactory();

HashSet<SessionID> definedSessions = _settings.GetSessions();
Expand All @@ -60,7 +74,7 @@ public void Start()
throw new System.ObjectDisposedException(this.GetType().Name);

// create all sessions
sessionFactory_ = new SessionFactory(_app, _storeFactory, _logFactory, _msgFactory);
sessionFactory_ = new SessionFactory(_app, _storeFactory, _loggerFactory, _msgFactory);
foreach (SessionID sessionID in _settings.GetSessions())
{
Dictionary dict = _settings.Get(sessionID);
Expand Down
11 changes: 11 additions & 0 deletions QuickFIXn/AcceptorSocketDescriptor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -28,12 +30,21 @@ public IPEndPoint Address

#endregion

[Obsolete]
public AcceptorSocketDescriptor(IPEndPoint socketEndPoint, SocketSettings socketSettings, QuickFix.Dictionary sessionDict)
{
socketEndPoint_ = socketEndPoint;
socketReactor_ = new ThreadedSocketReactor(socketEndPoint_, socketSettings, sessionDict, this);
}

[Obsolete]
public AcceptorSocketDescriptor(
IPEndPoint socketEndPoint, SocketSettings socketSettings, QuickFix.Dictionary sessionDict, ILoggerFactory loggerFactory)
{
socketEndPoint_ = socketEndPoint;
socketReactor_ = new ThreadedSocketReactor(socketEndPoint_, socketSettings, sessionDict, this);
}

public void AcceptSession(Session session)
{
lock (acceptedSessions_)
Expand Down
46 changes: 32 additions & 14 deletions QuickFIXn/ClientHandlerThread.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Net.Sockets;
using System.Threading;
using System;
using Microsoft.Extensions.Logging;

namespace QuickFix
{
Expand Down Expand Up @@ -32,7 +33,7 @@ public ExitedEventArgs(ClientHandlerThread clientHandlerThread)
private Thread thread_ = null;
private volatile bool isShutdownRequested_ = false;
private SocketReader socketReader_;
private FileLog log_;
private ILogger _logger;

[Obsolete("Don't use this constructor")]
public ClientHandlerThread(TcpClient tcpClient, long clientId)
Expand All @@ -46,19 +47,29 @@ public ClientHandlerThread(TcpClient tcpClient, long clientId, QuickFix.Dictiona
{
}

[Obsolete("Use constructor with injecting ILoggerFactory")]
public ClientHandlerThread(
TcpClient tcpClient, long clientId, QuickFix.Dictionary settingsDict, SocketSettings socketSettings)
: this(tcpClient, clientId, settingsDict, socketSettings, (AcceptorSocketDescriptor)null)
{

}

/// <summary>
/// Creates a ClientHandlerThread
/// </summary>
/// <param name="tcpClient"></param>
/// <param name="clientId"></param>
/// <param name="settingsDict"></param>
/// <param name="socketSettings"></param>
public ClientHandlerThread(TcpClient tcpClient, long clientId, QuickFix.Dictionary settingsDict, SocketSettings socketSettings)
: this(tcpClient, clientId, settingsDict, socketSettings, null)
/// <param name="loggerFactory"></param>
public ClientHandlerThread(
TcpClient tcpClient, long clientId, QuickFix.Dictionary settingsDict, SocketSettings socketSettings, ILoggerFactory loggerFactory)
: this(tcpClient, clientId, settingsDict, socketSettings, null, loggerFactory)
{

}

[Obsolete("Creates File Logger under the hood, please use Constructor with ILoggerFactory")]
internal ClientHandlerThread(TcpClient tcpClient, long clientId, QuickFix.Dictionary settingsDict,
SocketSettings socketSettings, AcceptorSocketDescriptor acceptorDescriptor)
{
Expand All @@ -67,11 +78,19 @@ internal ClientHandlerThread(TcpClient tcpClient, long clientId, QuickFix.Dictio
debugLogFilePath = settingsDict.GetString(SessionSettings.DEBUG_FILE_LOG_PATH);
else if (settingsDict.Has(SessionSettings.FILE_LOG_PATH))
debugLogFilePath = settingsDict.GetString(SessionSettings.FILE_LOG_PATH);
var sessionID = new SessionID(
"ClientHandlerThread", clientId.ToString(), "Debug-" + Guid.NewGuid().ToString());
_logger = new FileLog(debugLogFilePath, sessionID);
this.Id = clientId;
socketReader_ = new SocketReader(tcpClient, socketSettings, this, acceptorDescriptor);
}

// FIXME - do something more flexible than hardcoding a filelog
log_ = new FileLog(debugLogFilePath, new SessionID(
"ClientHandlerThread", clientId.ToString(), "Debug-" + Guid.NewGuid().ToString()));

internal ClientHandlerThread(TcpClient tcpClient, long clientId, QuickFix.Dictionary settingsDict,
SocketSettings socketSettings, AcceptorSocketDescriptor acceptorDescriptor, ILoggerFactory loggerFactory)
{
var sessionID = new SessionID(
"ClientHandlerThread", clientId.ToString(), "Debug-" + Guid.NewGuid().ToString());
_logger = loggerFactory.CreateLogger(sessionID.ToString());
this.Id = clientId;
socketReader_ = new SocketReader(tcpClient, socketSettings, this, acceptorDescriptor);
}
Expand Down Expand Up @@ -124,16 +143,16 @@ protected void OnExited()
/// FIXME do real logging
public void Log(string s)
{
log_.OnEvent(s);
_logger.LogEvent(s);
}

/// <summary>
/// Provide StreamReader with access to the log
/// </summary>
/// <returns></returns>
internal ILog GetLog()
internal ILogger GetLogger()
{
return log_;
return _logger;
}

#region Responder Members
Expand Down Expand Up @@ -169,10 +188,9 @@ protected virtual void Dispose(bool disposing)
socketReader_ = null;
}

if (log_ != null)
if (_logger != null)
{
log_.Dispose();
log_ = null;
_logger = null;
}
}
_disposed = true;
Expand Down
Loading