Add raw data logging support for LambdaLogger #1238
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available: : #1232
Description of changes: Add an overload to
LambdaLogger.Log()
to allow logging using raw data.Overview
In #1232 we brought up our use case of
ILogger
interface. Before we can implement such a logger we need to have a way to forward raw UTF8 data to the output. In this PR we propose that an overload is added toLambdaLogger
(for .NET 6 runtime only)This will be implemented in a similar fashion to
Log(string)
: it's delegated to a default method butLogLevelLoggerWriter
will replace that method with the formatted version using reflection.To do this the output
Stream
is passed toWrapperTextWriter
. If the Telemetry logging file descriptor is available this will be theFileStream
wrapper for that FD, otherwise the stream is set toNULL
and the logging action is delegated back toFormattedWriteLine()
Testing
Because this new function is only supported on .NET 6 and higher we added
net6.0
target toAmazon.Lambda.RuntimeSupport.UnitTests.csproj
.We added equivalent tests to existing tests for
FileDescriptorLogFactory.FileDescriptorLogStream
(raw data writing variant). We also added several unit tests toLogLevelLoggerWriter
.We also fixed a failing test :
HandlerTests.PositiveHandlerTestsAsync
. This test is failing for .NET 6 because by default theLambdaBootstrap
always initializes theLogLevelLoggerWriter
instance, which in turn redirects theLambdaLogger
output, causing the logs to not be redirected to the test. This is fixed by creating another constructor forLambdaBootstrap
to accept aIConsoleLoggerWriter
instance which the test itself provides.Remarks
There are two places whether the logging action of
LambdaLogger
is set. The first place isLogLevelLoggerWriter
which we include in this PR. The second place is inUserCodeLoader.SetCustomerLoggerLogAction()
. We are still not sure what the usage of this method. I'm happy to hear about this usage and amend the PR.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.