Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #16 from OctopusDeploy/enh-logwithcontext
Browse files Browse the repository at this point in the history
Separating system and task logs
  • Loading branch information
slewis74 committed Mar 18, 2021
2 parents 5558b28 + e8502d8 commit 9e402b0
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 34 deletions.
22 changes: 11 additions & 11 deletions source/Server.Tests/AdoApiClientScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace Octopus.Server.Extensibility.IssueTracker.AzureDevOps.Tests
[TestFixture]
public class AdoApiClientScenarios
{
private static readonly HtmlConvert HtmlConvert = new HtmlConvert(Substitute.For<ILog>());
private ILog? log;
private static readonly HtmlConvert HtmlConvert = new HtmlConvert(Substitute.For<ISystemLog>());
private ISystemLog? log;

private static IAzureDevOpsConfigurationStore CreateSubstituteStore()
{
Expand All @@ -31,7 +31,7 @@ private static IAzureDevOpsConfigurationStore CreateSubstituteStore()
[SetUp]
public void SetUp()
{
log = Substitute.For<ILog>();
log = Substitute.For<ISystemLog>();
}

[Test]
Expand All @@ -46,7 +46,7 @@ public void ClientCanRequestAndParseWorkItemsRefsAndLinks()
.Returns((HttpStatusCode.OK,
JObject.Parse(@"{""id"":2,""fields"":{""System.CommentCount"":0,""System.Title"": ""README has no useful content""}}")));

var workItemLinks = new AdoApiClient(store, httpJsonClient, HtmlConvert, log!).GetBuildWorkItemLinks(
var workItemLinks = new AdoApiClient(log!, store, httpJsonClient, HtmlConvert).GetBuildWorkItemLinks(
AdoBuildUrls.ParseBrowserUrl("http://redstoneblock/DefaultCollection/Deployable/_build/results?buildId=24"));

var workItemLink = ((ISuccessResult<WorkItemLink[]>)workItemLinks).Value.Single();
Expand All @@ -68,7 +68,7 @@ public void SourceGetsSet()
.Returns((HttpStatusCode.OK,
JObject.Parse(@"{""id"":2,""fields"":{""System.CommentCount"":0,""System.Title"": ""README has no useful content""}}")));

var workItemLinks = new AdoApiClient(store, httpJsonClient, HtmlConvert, log!).GetBuildWorkItemLinks(
var workItemLinks = new AdoApiClient(log!, store, httpJsonClient, HtmlConvert).GetBuildWorkItemLinks(
AdoBuildUrls.ParseBrowserUrl("http://redstoneblock/DefaultCollection/Deployable/_build/results?buildId=24"));

var workItemLink = ((ISuccessResult<WorkItemLink[]>)workItemLinks).Value.Single();
Expand All @@ -90,7 +90,7 @@ public void ClientCanRequestAndParseWorkItemsWithReleaseNotes()
.Returns((HttpStatusCode.OK, JObject.Parse(@"{""totalCount"":3,""count"":3,""comments"":[{""text"":""= Changelog = N/A""}," +
@"{""text"":""<div>= Changelog =&nbsp;README <i>riddle</i> now has an answer!</div>""},{""text"":""See also related issue.""}]}")));

var workItemLinks = new AdoApiClient(store, httpJsonClient, HtmlConvert, log!).GetBuildWorkItemLinks(
var workItemLinks = new AdoApiClient(log!, store, httpJsonClient, HtmlConvert).GetBuildWorkItemLinks(
AdoBuildUrls.ParseBrowserUrl("http://redstoneblock/DefaultCollection/Deployable/_build/results?buildId=28"));

var workItemLink = ((ISuccessResult<WorkItemLink[]>)workItemLinks).Value.Single();
Expand Down Expand Up @@ -118,7 +118,7 @@ public void ClientReportsFailuresAndReturnsPartialResults()
httpJsonClient.Get("http://redstoneblock/DefaultCollection/Deployable/_apis/wit/workitems/6/comments?api-version=4.1-preview.2", "rumor")
.Returns((HttpStatusCode.InternalServerError, null));

var workItemLinks = new AdoApiClient(store, httpJsonClient, HtmlConvert, log!).GetBuildWorkItemLinks(
var workItemLinks = new AdoApiClient(log!, store, httpJsonClient, HtmlConvert).GetBuildWorkItemLinks(
AdoBuildUrls.ParseBrowserUrl("http://redstoneblock/DefaultCollection/Deployable/_build/results?buildId=29"));

var successResult = ((ISuccessResult<WorkItemLink[]>)workItemLinks);
Expand Down Expand Up @@ -146,12 +146,12 @@ public void PersonalAccessTokenIsOnlySentToItsOrigin()
});

// Request to other host should not include password
new AdoApiClient(store, httpJsonClient, HtmlConvert, log!)
new AdoApiClient(log!, store, httpJsonClient, HtmlConvert)
.GetBuildWorkItemsRefs(AdoBuildUrls.ParseBrowserUrl("http://someotherhost/DefaultCollection/Deployable/_build/results?buildId=24"));
Assert.IsNull(passwordSent);

// Request to origin should include password
new AdoApiClient(store, httpJsonClient, HtmlConvert, log!)
new AdoApiClient(log!, store, httpJsonClient, HtmlConvert)
.GetBuildWorkItemsRefs(AdoBuildUrls.ParseBrowserUrl("http://redstoneblock/DefaultCollection/Deployable/_build/results?buildId=24"));
Assert.AreEqual("rumor", passwordSent);
}
Expand All @@ -165,7 +165,7 @@ public void AcceptsDeletedBuildAsPermanentEmptySet()
.Returns((HttpStatusCode.NotFound,
JObject.Parse(@"{""$id"":""1"",""message"":""The requested build 7 could not be found."",""errorCode"":0,""eventId"":3000}")));

var workItemLinks = new AdoApiClient(store, httpJsonClient, HtmlConvert, log!).GetBuildWorkItemLinks(
var workItemLinks = new AdoApiClient(log!, store, httpJsonClient, HtmlConvert).GetBuildWorkItemLinks(
AdoBuildUrls.ParseBrowserUrl("http://redstoneblock/DefaultCollection/Deployable/_build/results?buildId=7"));

Assert.IsEmpty(((ISuccessResult<WorkItemLink[]>)workItemLinks).Value);
Expand All @@ -183,7 +183,7 @@ public void AcceptsDeletedWorkItemAsPermanentMissingTitle()
.Returns((HttpStatusCode.NotFound,
JObject.Parse(@"{""$id"":""1"",""message"":""TF401232: Work item 999 does not exist."",""errorCode"":0,""eventId"":3200}")));

var workItemLinks = new AdoApiClient(store, httpJsonClient, HtmlConvert, log!).GetBuildWorkItemLinks(
var workItemLinks = new AdoApiClient(log!, store, httpJsonClient, HtmlConvert).GetBuildWorkItemLinks(
AdoBuildUrls.ParseBrowserUrl("http://redstoneblock/DefaultCollection/Deployable/_build/results?buildId=8"));

var workItemLink = ((ISuccessResult<WorkItemLink[]>)workItemLinks).Value.Single();
Expand Down
2 changes: 1 addition & 1 deletion source/Server.Tests/HtmlConvertScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class HtmlConvertScenarios
[Test]
public void ConvertsEntitiesAndNewlines()
{
var plainText = new HtmlConvert(Substitute.For<ILog>()).ToPlainText(@"one<br>two&nbsp;three<div>four</div>fi&lt;e<p>six</p>seven");
var plainText = new HtmlConvert(Substitute.For<ISystemLog>()).ToPlainText(@"one<br>two&nbsp;three<div>four</div>fi&lt;e<p>six</p>seven");

Assert.AreEqual(string.Join(Environment.NewLine, @"one", "two\u00a0three", "four", "fi<e", "", "six", "", "seven"), plainText);
}
Expand Down
2 changes: 1 addition & 1 deletion source/Server.Tests/Server.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="NSubstitute" Version="3.1.0" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="Octopus.Diagnostics" Version="1.3.0" />
<PackageReference Include="Octopus.Diagnostics" Version="2.1.0" />
<PackageReference Include="TeamCity.VSTest.TestAdapter" Version="1.0.15" />
</ItemGroup>

Expand Down
8 changes: 4 additions & 4 deletions source/Server/AdoClients/AdoApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ interface IAdoApiClient

class AdoApiClient : IAdoApiClient
{
private readonly ISystemLog systemLog;
private readonly IAzureDevOpsConfigurationStore store;
private readonly IHttpJsonClient client;
private readonly HtmlConvert htmlConvert;
private readonly ILog log;

public AdoApiClient(IAzureDevOpsConfigurationStore store, IHttpJsonClient client, HtmlConvert htmlConvert, ILog log)
public AdoApiClient(ISystemLog systemLog, IAzureDevOpsConfigurationStore store, IHttpJsonClient client, HtmlConvert htmlConvert)
{
this.systemLog = systemLog;
this.store = store;
this.client = client;
this.htmlConvert = htmlConvert;
this.log = log;
}

internal string? GetPersonalAccessToken(AdoUrl adoUrl)
Expand Down Expand Up @@ -170,7 +170,7 @@ string BuildWorkItemBrowserUrl(AdoProjectUrls adoProjectUrls, int workItemId)
if (comments is FailureResult failure)
{
// if we can't retrieve the comments then move on without
log.WarnFormat("Error retrieving Azure DevOps comments for work item {0}. Error: {1}", workItemId, failure.ErrorString);
systemLog.WarnFormat("Error retrieving Azure DevOps comments for work item {0}. Error: {1}", workItemId, failure.ErrorString);
return null;
}

Expand Down
12 changes: 6 additions & 6 deletions source/Server/Configuration/AzureDevOpsConfigureCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ namespace Octopus.Server.Extensibility.IssueTracker.AzureDevOps.Configuration
{
class AzureDevOpsConfigureCommands : IContributeToConfigureCommand
{
readonly ILog log;
readonly ISystemLog systemLog;
readonly Lazy<IAzureDevOpsConfigurationStore> azureDevOpsConfiguration;

public AzureDevOpsConfigureCommands(
ILog log,
ISystemLog systemLog,
Lazy<IAzureDevOpsConfigurationStore> azureDevOpsConfiguration)
{
this.log = log;
this.systemLog = systemLog;
this.azureDevOpsConfiguration = azureDevOpsConfiguration;
}

Expand All @@ -26,19 +26,19 @@ public IEnumerable<ConfigureCommandOption> GetOptions()
{
var isEnabled = bool.Parse(v);
azureDevOpsConfiguration.Value.SetIsEnabled(isEnabled);
log.Info($"Azure DevOps Issue Tracker integration IsEnabled set to: {isEnabled}");
systemLog.Info($"Azure DevOps Issue Tracker integration IsEnabled set to: {isEnabled}");
});
yield return new ConfigureCommandOption("AzureDevOpsBaseUrl=", AzureDevOpsConfigurationResource.BaseUrlDescription,
v =>
{
azureDevOpsConfiguration.Value.SetBaseUrl(v);
log.Info($"Azure DevOps Issue Tracker integration base Url set to: {v}");
systemLog.Info($"Azure DevOps Issue Tracker integration base Url set to: {v}");
});
yield return new ConfigureCommandOption("AzureDevOpsPersonalAccessToken=", AzureDevOpsConfigurationResource.PersonalAccessTokenDescription,
v =>
{
azureDevOpsConfiguration.Value.SetPersonalAccessToken(v.ToSensitiveString());
log.Info($"Azure DevOps Issue Tracker integration personal access token set to: {v}");
systemLog.Info($"Azure DevOps Issue Tracker integration personal access token set to: {v}");
});
}
}
Expand Down
8 changes: 4 additions & 4 deletions source/Server/Configuration/DatabaseInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ namespace Octopus.Server.Extensibility.IssueTracker.AzureDevOps.Configuration
{
class DatabaseInitializer : ExecuteWhenDatabaseInitializes
{
readonly ILog log;
readonly ISystemLog systemLog;
readonly IConfigurationStore configurationStore;

public DatabaseInitializer(ILog log, IConfigurationStore configurationStore)
public DatabaseInitializer(ISystemLog systemLog, IConfigurationStore configurationStore)
{
this.log = log;
this.systemLog = systemLog;
this.configurationStore = configurationStore;
}

Expand All @@ -21,7 +21,7 @@ public override void Execute()
if (doc != null)
return;

log.Info("Initializing Azure DevOps integration settings");
systemLog.Info("Initializing Azure DevOps integration settings");
doc = new AzureDevOpsConfiguration();
configurationStore.Create(doc);
}
Expand Down
6 changes: 3 additions & 3 deletions source/Server/Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.11.4" />
<PackageReference Include="Octopus.Data" Version="5.2.0" />
<PackageReference Include="Octopus.Diagnostics" Version="1.3.5" />
<PackageReference Include="Octopus.Server.Extensibility" Version="11.0.0" />
<PackageReference Include="Octopus.Data" Version="5.3.0" />
<PackageReference Include="Octopus.Diagnostics" Version="2.1.0" />
<PackageReference Include="Octopus.Server.Extensibility" Version="13.0.0" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions source/Server/WorkItems/HtmlConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class HtmlConvert
.Split(' ')
.ToDictionary(n => n, n => true);

private readonly ILog log;
private readonly ISystemLog systemLog;

public HtmlConvert(ILog log)
public HtmlConvert(ISystemLog systemLog)
{
this.log = log;
this.systemLog = systemLog;
}

public string ToPlainText(string html)
Expand All @@ -35,7 +35,7 @@ public string ToPlainText(string html)
}
catch (Exception ex)
{
log.Info(ex, "Unable to convert Azure DevOps work item comment HTML to plain text.");
systemLog.Info(ex, "Unable to convert Azure DevOps work item comment HTML to plain text.");
return html;
}
}
Expand Down

0 comments on commit 9e402b0

Please sign in to comment.