Skip to content

Commit

Permalink
Merge pull request #839 from gbirchmeier/screenlogtweaks
Browse files Browse the repository at this point in the history
ScreenLog adjustments
  • Loading branch information
gbirchmeier authored Feb 23, 2024
2 parents 0ed0129 + cbb8752 commit 3200a30
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Examples/TradeClient/tradeclient.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ LogoutTimeout=5
ResetOnLogon=Y
ResetOnDisconnect=Y

ScreenLogShowIncoming=Y
ScreenLogShowOutgoing=Y
ScreenLogShowEvents=Y

[SESSION]
# inherit ConnectionType, ReconnectInterval and SenderCompID from default
BeginString=FIX.4.4
Expand Down
4 changes: 2 additions & 2 deletions QuickFIXn/Logger/ScreenLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void OnIncoming(string msg)

lock (_sync)
{
System.Console.WriteLine("<incoming> " + msg);
System.Console.WriteLine("<incoming> " + msg.Replace(Message.SOH, '|'));
}
}

Expand All @@ -42,7 +42,7 @@ public void OnOutgoing(string msg)

lock (_sync)
{
System.Console.WriteLine("<outgoing> " + msg);
System.Console.WriteLine("<outgoing> " + msg.Replace(Message.SOH, '|'));
}
}

Expand Down
29 changes: 20 additions & 9 deletions QuickFIXn/Logger/ScreenLogFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,38 @@ public class ScreenLogFactory : ILogFactory

private readonly SessionSettings _settings;

private readonly bool _logIncoming = false;
private readonly bool _logOutgoing = false;
private readonly bool _logEvent = false;

public ScreenLogFactory(SessionSettings settings)
{
_settings = settings;
}

public ScreenLogFactory(bool logIncoming, bool logOutgoing, bool logEvent)
{
_logIncoming = logIncoming;
_logOutgoing = logOutgoing;
_logEvent = logEvent;

_settings = new SessionSettings();
}

#region LogFactory Members

public ILog Create(SessionID sessionId) {
bool logIncoming = false;
bool logOutgoing = false;
bool logEvent = false;
bool logIncoming = _logIncoming;
bool logOutgoing = _logOutgoing;
bool logEvent = _logEvent;

if(_settings.Has(sessionId))
{
SettingsDictionary dict = _settings.Get(sessionId);
if (dict.Has(SCREEN_LOG_SHOW_INCOMING))
logIncoming = dict.GetBool(SCREEN_LOG_SHOW_INCOMING);
if (dict.Has(SCREEN_LOG_SHOW_OUTGOING))
logOutgoing = dict.GetBool(SCREEN_LOG_SHOW_OUTGOING);
if (dict.Has(SCREEN_LOG_SHOW_EVENTS))
logEvent = dict.GetBool(SCREEN_LOG_SHOW_EVENTS);

logIncoming = _logIncoming || dict.IsBoolPresentAndTrue(SCREEN_LOG_SHOW_INCOMING);
logOutgoing = _logOutgoing || dict.IsBoolPresentAndTrue(SCREEN_LOG_SHOW_OUTGOING);
logEvent = _logEvent || dict.IsBoolPresentAndTrue(SCREEN_LOG_SHOW_EVENTS);
}

return new ScreenLog(logIncoming, logOutgoing, logEvent);
Expand Down
9 changes: 9 additions & 0 deletions QuickFIXn/SettingsDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ public bool GetBool(string key)
}
}

/// <summary>
/// Return true if key is present AND value is true, else false
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public bool IsBoolPresentAndTrue(string key) {
return Has(key) && GetBool(key);
}

public DayOfWeek GetDay(string key) {
string abbr = GetString(key).Substring(0, 2).ToUpperInvariant();
return abbr switch
Expand Down
3 changes: 2 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ What's New
* Move all store classes to new QuickFix.Store namespace
* FileLog: remove the single-param ctor, no reason for anyone to use it
* ScreenLog ctor: removed unused sessionId param
* ScreenLogFactory: remove public vars and a ctor that no one should be using
* ScreenLogFactory: remove unused public vars
* #708 - In FIX50, rename field SecurityStat to SecurityStatus, to match SP1 and SP2 (gbirchmeier)
* #639 - address Dictionary ctor bug, then cleanup/nullable-ize (gbirchmeier)
* rename to SettingsDictionary to reduce name confusion with System.Collections.Generic.Dictionary
Expand Down Expand Up @@ -77,6 +77,7 @@ What's New
* Perform socket read operations according to Task-based asynchronous pattern (TAP) instead of Asynchronous
Programming Model (APM), in order to catch unobserved SocketExceptions (nmandzyk)
* Cleanup/nullable-ize SocketInitiatorThread (gbirchmeier)
* #839 - change ScreenLog to output FIX messages with "|" instead of non-visible SOH (gbirchmeier)

### v1.11.2:
* same as v1.11.1, but I fixed the readme in the pushed nuget packages
Expand Down
10 changes: 10 additions & 0 deletions UnitTests/SettingsDictionaryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ public void SetGetBool()
Assert.Throws<ConfigError>(delegate { d.GetBool("BADBOOLKEY2"); });
}

[Test]
public void IsBoolPresentAndTrue() {
SettingsDictionary d = new();
d.SetBool("BOOLKEY-T", true);
d.SetBool("BOOLKEY-F", false);
Assert.IsTrue(d.IsBoolPresentAndTrue("BOOLKEY-T"));
Assert.IsFalse(d.IsBoolPresentAndTrue("BOOLKEY-F"));
Assert.IsFalse(d.IsBoolPresentAndTrue("nonexistent key"));
}

[Test]
public void SetGetDay()
{
Expand Down

0 comments on commit 3200a30

Please sign in to comment.