-
Notifications
You must be signed in to change notification settings - Fork 490
Lambda Logging improvements #2062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
In Amazon.Lambda.Logging.AspNetCore convert the ASP.NET Core log level into the Lambda log level and then pass the level into the logging method Update Amazon.Lambda.TestUtitlies to have implementation of the newer logging methods Add a new static global static logging method that takes in log level, message, parameters and exception. Passing in exception in the global static logger was missing.
}, | ||
{ | ||
"Name": "Amazon.Lambda.Logging.AspNetCore", | ||
"Type": "Minor", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would feel more comfortable making this a Major version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
}, | ||
{ | ||
"Name": "Amazon.Lambda.TestUtilities", | ||
"Type": "Minor", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would feel more comfortable making this a Major version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -78,7 +88,6 @@ private static void LogWithLevelToConsole(string level, string message, params o | |||
/// <param name="level">The log level of the message</param> | |||
/// <param name="message">Message to log. The message may have format arguments.</param> | |||
/// <param name="args">Arguments to format the message with.</param> | |||
[RequiresPreviewFeatures(ParameterizedPreviewMessage)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these no longer needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the implementation in Amazon.Lambda.RuntimeSupport of these methods have been deployed to the managed runtimes. That were marked as preview till that deployment was done.
/// <param name="exception">Exception to include with the logging.</param> | ||
/// <param name="message">Message to log. The message may have format arguments.</param> | ||
/// <param name="args">Arguments to format the message with.</param> | ||
[RequiresPreviewFeatures(ParameterizedPreviewMessage)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this here but not in others?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this PR adds the implementation of these methods in Amazon.Lambda.RuntimeSupport and we will need to wait till that change in Amazon.Lambda.RuntimeSupport gets deployed to managed runtime. Ideally I should have added these at the same time I did the versions that didn't take an Exception. That was a miss on my part that I'm fixing.
/// <param name="exception">Exception to include with the logging.</param> | ||
/// <param name="message">Message to log. The message may have format arguments.</param> | ||
/// <param name="args">Arguments to format the message with.</param> | ||
[RequiresPreviewFeatures(ParameterizedPreviewMessage)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same question
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answered above
} | ||
|
||
internalLogger.LogDebug($"UCL : Retrieving type '{Types.LambdaLoggerTypeName}'"); | ||
var lambdaILoggerType = coreAssembly.GetType(Types.LambdaLoggerTypeName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isnt this library NativeAOT compatible? Why are you using reflection here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The UserCodeLoader
is not Native AOT complaint but it is only used in class library programming model and you use executable programming model for Native AOT. At the top of the UserCodeLoader file is the RequiresUnreferencedCode
attribute to say this code shouldn't be used for Native AOT.
} | ||
} | ||
|
||
internal static void SetCustomerLoggerLogAction(Assembly coreAssembly, Action<string, Exception, string, object[]> loggingWithAndExceptionLevelAction, InternalLogger internalLogger) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add docs for this method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} | ||
|
||
internalLogger.LogDebug($"UCL : Retrieving type '{Types.LambdaLoggerTypeName}'"); | ||
var lambdaILoggerType = coreAssembly.GetType(Types.LambdaLoggerTypeName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same question abotut reflection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answered above
@@ -4,7 +4,7 @@ | |||
|
|||
<PropertyGroup> | |||
<Description>Amazon.Lambda.TestUtilties includes stub implementations of interfaces defined in Amazon.Lambda.Core and helper methods.</Description> | |||
<TargetFramework>netstandard2.0</TargetFramework> | |||
<TargetFrameworks>net6.0;net8.0</TargetFrameworks> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment about moving to .net8 only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just not ready to make that call yet. Especially not for this update.
public void Log(string level, string message) | ||
{ | ||
var formmattedString = $"{level}: {message}"; | ||
Buffer.AppendLine(formmattedString); | ||
Console.WriteLine(formmattedString); | ||
} | ||
|
||
public void Log(string level, string message, params object[] args) | ||
{ | ||
var builder = new StringBuilder(); | ||
builder.Append($"{level}: {message}"); | ||
if (args != null && args.Length > 0) | ||
{ | ||
builder.AppendLine(); | ||
foreach (var arg in args) | ||
{ | ||
builder.AppendLine($"\t{arg}"); | ||
} | ||
} | ||
|
||
var formmattedString = builder.ToString(); | ||
Buffer.AppendLine(formmattedString); | ||
Console.WriteLine(formmattedString); | ||
} | ||
|
||
public void Log(string level, Exception exception, string message, params object[] args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add docs for these methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Issue #, if available:
#2032
Description of changes:
I had also wanted to update Amazon.Lambda.Logging.AspNetCore to support converting the log method to JSON if that was enabled in Lambda. Since we are missing the global static logging method that takes in exception I couldn't do that without losing the exception in the log. Once that new method added in RuntimeSupport in this PR is deployed to the managed runtimes I can go back and add the support.
I updated Amazon.Lambda.Logging.AspNetCore and Amazon.Lambda.TestUtitlies to target .NET 6.0 and .NET 8.0 instead of .NET Standard 2.0. That was needed so I have access to the parameterized logging methods. I didn't do it as a major version bump because I figured where else could you have run these packages then one of those targets. I don't feel to strong on that and if others feel I should do it as a major version bump I'm okay with that.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.