Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwoctopusdeploy committed Dec 19, 2023
1 parent ee3dd67 commit c1eb30a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ void TryTurnOnTraceLoggingForTentacleRuntime(TentacleRuntime runtime, ILogger lo
{
var exePath = TentacleExeFinder.FindTentacleExe(runtime);
var exeFileInfo = new FileInfo(exePath);

File.Copy(Path.Combine(exeFileInfo.DirectoryName!, "Tentacle.exe.nlog"), Path.Combine(exeFileInfo.DirectoryName!, "Tentacle.exe.nlog_original"));

var nlogFileInfo = new FileInfo(Path.Combine(exeFileInfo.DirectoryName!, "Tentacle.exe.nlog"));

var content = File.ReadAllText(nlogFileInfo.FullName);
content = content.Replace("<logger name=\"*\" minlevel=\"Info\" writeTo=\"octopus-log-file\" />", "<logger name=\"*\" minlevel=\"Trace\" writeTo=\"octopus-log-file\" />");
content = content.Replace("<logger name=\"*\" minlevel=\"Info\" maxLevel=\"Warn\" writeTo=\"stdout\" />", "<logger name=\"*\" minlevel=\"Trace\" maxLevel=\"Warn\" writeTo=\"stdout\" />");
content = content.Replace("<variable name=\"messageLayout\" value=\"${message}${onexception:${newline}${exception:format=ToString}}\"/>", "<variable name=\"messageLayout\" value=\"[${level}] ${message}${onexception:${newline}${exception:format=ToString}}\"/>");

File.WriteAllText(nlogFileInfo.FullName, content);
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,20 @@ async Task RunCommandOutOfProcess(
async Task ProcessLogs(string s, CancellationToken ct)
{
await Task.CompletedTask;
logger.Information($"[{commandName}] " + s);

if (s.StartsWith("[TRACE]"))
{
logger.Verbose($"[{commandName}] " + s);
}
else if (s.StartsWith("[DEBUG]"))
{
logger.Debug($"[{commandName}] " + s);
}
else
{
logger.Information($"[{commandName}] " + s);
}

commandOutput(s);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using Octopus.Tentacle.Tests.Integration.Support;
using Octopus.Tentacle.Tests.Integration.Support.ExtensionMethods;
using Octopus.Tentacle.Tests.Integration.Support.TestAttributes;
using Octopus.Tentacle.Util;
using Octopus.Tentacle.Variables;
Expand Down Expand Up @@ -733,6 +734,15 @@ FileVersionInfo GetVersionInfo(TentacleConfigurationTestCase tentacleConfigurati
var output = new StringBuilder();
var errorOut = new StringBuilder();

// The tests increase the logging level for Tentacle, this impacts the command line tests as the output
// is now different than expected. We revert the loggign level just for these command line tests.
using var tempBinariesDirectory = new TemporaryDirectory();
var tentacleExeFileInfo = new FileInfo(tentacleExe);
tentacleExeFileInfo.Directory.CopyTo(tempBinariesDirectory.DirectoryPath);
File.Delete(Path.Combine(tempBinariesDirectory.DirectoryPath, "Tentacle.exe.nlog"));
File.Move(Path.Combine(tempBinariesDirectory.DirectoryPath, "Tentacle.exe.nlog_original"), Path.Combine(tempBinariesDirectory.DirectoryPath, "Tentacle.exe.nlog"));
tentacleExe = Path.Combine(tempBinariesDirectory.DirectoryPath, tentacleExeFileInfo.Name);

var result = await RetryHelper.RetryAsync<CommandResult, CommandExecutionException>(
() => Cli.Wrap(tentacleExe)
.WithArguments(arguments)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ static SerilogLoggerBuilder()
{
const string teamCityOutputTemplate =
"{TestHash} "
+ "{Timestamp:HH:mm:ss.fff zzz} "
+ "{Timestamp:HH:mm:ss.fff zzz} {Level:u3} "
+ "[{ShortContext}] "
+ "{Message}{NewLine}{Exception}";

const string localOutputTemplate =
"{Timestamp:HH:mm:ss.fff zzz} "
"{Timestamp:HH:mm:ss.fff zzz} {Level:u3} "
+ "[{ShortContext}] "
+ "{Message}{NewLine}{Exception}";

Expand All @@ -42,9 +42,9 @@ static SerilogLoggerBuilder()
: localOutputTemplate;

Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.Sink(new NonProgressNUnitSink(new MessageTemplateTextFormatter(nUnitOutputTemplate)), LogEventLevel.Debug)
.WriteTo.Sink(new TraceLogsForFailedTestsSink(new MessageTemplateTextFormatter(localOutputTemplate)))
.MinimumLevel.Debug()
.WriteTo.Sink(new NonProgressNUnitSink(new MessageTemplateTextFormatter(nUnitOutputTemplate)), LogEventLevel.Information)
.WriteTo.Sink(new TraceLogsForFailedTestsSink(new MessageTemplateTextFormatter(localOutputTemplate)), LogEventLevel.Debug)
.CreateLogger();
}

Expand Down Expand Up @@ -151,7 +151,7 @@ public void Emit(LogEvent logEvent)
var testName = TestContext.CurrentContext.Test.FullName;

if (!TraceLoggers.TryGetValue(testName, out var traceLogger))
throw new Exception($"Could not find trace logger for test '{testName}'");
return;

var output = new StringWriter();
if (logEvent.Properties.TryGetValue("SourceContext", out var sourceContext))
Expand Down

0 comments on commit c1eb30a

Please sign in to comment.