Skip to content

Commit

Permalink
Configure IG log for integration test
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Chang <vicchang@nvidia.com>
  • Loading branch information
mocsharp committed Nov 9, 2022
1 parent ab29adf commit 54efccb
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tests/Integration.Test/Hooks/TestHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ public static void Shtudown()

[AfterTestRun(Order = 0)]
[AfterScenario]
public static void ClearTestData()
public static void ClearTestData(ISpecFlowOutputHelper outputHelper, ScenarioContext scenarioContext)
{
s_minioSink.CleanBucketAsync();
RabbitConnectionFactory.PurgeAllQueues(s_options.Value.Messaging);
outputHelper.WriteLine("=============================== END {0} ===============================", scenarioContext.ScenarioInfo.Title);
}

private static void SetupInformaticsGateway()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!--
<!--
~ Copyright 2022 MONAI Consortium
~
~ Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -67,6 +67,10 @@
<ProjectReference Include="..\..\src\InformaticsGateway\Monai.Deploy.InformaticsGateway.csproj" />
</ItemGroup>

<ItemGroup>
<None Include="./nlog.config" CopyToOutputDirectory="Always" />
</ItemGroup>

<Target Name="CopyPluginsBuild" AfterTargets="Build">
<ItemGroup>
<PluginDlls Include="$(OutDir)Monai.Deploy.Messaging.RabbitMQ.dll;$(OutDir)Monai.Deploy.Storage.MinIO.dll;$(OutDir)Minio.dll" />
Expand Down
88 changes: 88 additions & 0 deletions tests/Integration.Test/nlog.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8" ?>

<!--
Copyright 2022 MONAI Consortium
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Debug"
internalLogFile="${basedir}/logs/internal-nlog.txt">

<extensions>
<add assembly="NLog.Web.AspNetCore"/>
<add assembly="NLog.Extensions.Logging"/>
</extensions>

<variable name="logDir" value="${basedir}/logs/" />

<time type="AccurateUTC" />

<targets async="true">
<!-- File Target for all log messages with basic details -->
<target xsi:type="File" name="allfile" fileName="${logDir}/MIG-${shortdate}.log" >
<layout xsi:type="JsonLayout" includeEventProperties="true" includeScopeProperties="true">
<attribute name="timestamp" layout="${date:format=o}" />
<attribute name="level" layout="${level:upperCase=true}"/>
<attribute name="logger" layout="${logger}" />
<attribute name="message" layout="${message:raw=true}" />
<attribute name="properties" layout="${message:raw=true}" />
</layout>
</target>


<!--Console Target for hosting lifetime messages to improve Docker / Visual Studio startup detection -->
<target xsi:type="ColoredConsole" name="lifetimeConsole" layout="${longdate}|${event-properties:item=EventId:whenEmpty=0}|${uppercase:${level}}|${logger}|${scopenested}|${message} ${exception:format=tostring}" />

<target name="logstash" xsi:type="Network" address="${environment:LOGSTASH_URL}" newLine="true">
<layout xsi:type="JsonLayout" IncludeEventProperties="true" IncludeScopeProperties="true">
<attribute name="Tag" layout="${environment:ENVIRONMENT_NAME}" />
<attribute name="ServiceName" layout="${servicename}" />
<attribute name="ServiceVersion" layout="${serviceversion}" />
<attribute name="MachineName" layout="${machinename}" />
<attribute name="CorrelationId" layout="${mdlc:item=correlationId}"/>
<attribute name="LoggerName" layout="${logger}"/>
<attribute name="Level" layout="${level:upperCase=true}"/>
<attribute name="Message" layout="${message}"/>
<attribute name="Exception" layout="${onexception:${literal:text=|}"/>
<attribute name="Exception2" layout="${exception:format=tostring}"/>
</layout>
</target>

</targets>

<!-- rules to map from logger name to target -->
<rules>
<!--All logs, including from Microsoft-->
<logger name="*" minlevel="Trace" writeTo="allfile" />

<!--Output hosting lifetime messages to console target for faster startup detection -->
<logger name="Microsoft.EntityFrameworkCore" minlevel="Warn" writeTo="lifetimeConsole" final="false" />
<logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="lifetimeConsole" final="false" />
<logger name="Monai.*" minlevel="Debug" writeTo="lifetimeConsole" final="false" />

<!--Skip non-critical Microsoft logs and so log only own logs (BlackHole) -->
<logger name="Microsoft.*" maxlevel="Info" final="true" />
<logger name="System.Net.Http.*" maxlevel="Info" final="true" />

<logger name="*" minlevel="Trace" writeTo="logstash" >
<filters FilterDefaultAction="Log">
<when condition="length('${environment:LOGSTASH_URL}') &lt; 10" action="Ignore" />
</filters>
</logger>

</rules>
</nlog>

0 comments on commit 54efccb

Please sign in to comment.