Trace logs can provide us with invaluable information about Halibut when debugging problems, but unfortunately they are too verbose to be practical on the build server, as the extra logging causes the build logs to be prohibitively large.
This PR attempts to have the best of both worlds (info-level logs when everything is fine, trace-level logs when there are problems) by logging a test's trace logs to a separate log file which can be kept if the test fails.
Results
Fixes [sc-56164]
During the setup for each individual test (BaseTest.SetUp), a TraceLogFileLogger is created and passed to the SerilogLoggerBuilder when initializing the logger. This new class is responsible for writing logs to a temporary file, and copying that file to the build artifacts directory if needed.
Once the SerilogLoggerBuilder.Build method is called, the instance of TraceLogFileLogger is stored in memory for the currently running test and is utilised by a custom Serilog sink which will find and write to the appropriate trace logger for the current test each time a log message is sent.
After the test is completed, the teardown method (BaseTest.TearDown) will check the status of the test and have the TraceLogFileLogger copy the trace log file to the build artifacts if the test failed.
Trace log files are named {TestHash}.tracelog, where TestHash is a short Base64 hash based on the test name. This TestHash is also printed in the log output, allowing a developer to easily find the corresponding trace log file for any failed test.
Before
No trace logs for failed tests 😞
After
How to review this PR
Are there are any other tests or test base class which need to modified to log trace-level logs? I've modified the default for the IClientAndServiceBuilder implementations, but are there any tests that don't use these builders that need updating?
Pre-requisites
[ ] I have read How we use GitHub Issues for help deciding when and where it's appropriate to make an issue.
[ ] I have considered informing or consulting the right people, according to the ownership map.
[ ] I have considered appropriate testing for my change.
Background
Trace logs can provide us with invaluable information about Halibut when debugging problems, but unfortunately they are too verbose to be practical on the build server, as the extra logging causes the build logs to be prohibitively large.
This PR attempts to have the best of both worlds (info-level logs when everything is fine, trace-level logs when there are problems) by logging a test's trace logs to a separate log file which can be kept if the test fails.
Results
Fixes [sc-56164]
During the setup for each individual test (
BaseTest.SetUp
), aTraceLogFileLogger
is created and passed to theSerilogLoggerBuilder
when initializing the logger. This new class is responsible for writing logs to a temporary file, and copying that file to the build artifacts directory if needed.Once the
SerilogLoggerBuilder.Build
method is called, the instance ofTraceLogFileLogger
is stored in memory for the currently running test and is utilised by a custom Serilog sink which will find and write to the appropriate trace logger for the current test each time a log message is sent.After the test is completed, the teardown method (
BaseTest.TearDown
) will check the status of the test and have theTraceLogFileLogger
copy the trace log file to the build artifacts if the test failed.Trace log files are named {TestHash}.tracelog, where TestHash is a short Base64 hash based on the test name. This TestHash is also printed in the log output, allowing a developer to easily find the corresponding trace log file for any failed test.
Before
No trace logs for failed tests 😞
After
How to review this PR
Are there are any other tests or test base class which need to modified to log trace-level logs? I've modified the default for the
IClientAndServiceBuilder
implementations, but are there any tests that don't use these builders that need updating?Pre-requisites