Skip to content

Update global logger to support logging with level and arguments. #2005

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

Merged
merged 2 commits into from
Mar 13, 2025

Conversation

normj
Copy link
Member

@normj normj commented Mar 8, 2025

Issue #, if available:
#1747 (comment)

Description of changes:
Add to the global logger LambdaLogger in Amazon.Lambda.Core a new parameterized logging method that takes in log level. The method is marked as preview till the new version of Amazon.Lambda.RuntimeSupport is deployed to the managed runtime.

Once the PR is deployed to the managed runtime we can update Amazon.Lambda.Logging.AspNetCore to use this new method so the log levels will be honored.

Testing

Ran tests and added an integ test cases for the new logging scenario.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

{
"Projects": [
{
"Name": "Amazon.Lambda.RuntimeSupport",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to have 2 entries for RuntimeSupport? Seems like both can be combined into 1.

Copy link
Member Author

@normj normj Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. The second one is supposed to be Amazon.Lambda.Core which I marked as preview since the API is in preview status. It will get a minor version bump once the API is out of preview.

@@ -9,8 +12,11 @@ namespace Amazon.Lambda.Core
/// </summary>
public static class LambdaLogger
{
// Logging action, logs to Console by default
// The name of this field must not change or be readonly because Amazon.Runtime.Support will use reflection to replace the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong name "Amazon.Runtime.Support"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


#if NET6_0_OR_GREATER

// The name of this field must not change or be readonly because Amazon.Runtime.Support will use reflection to replace the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong name "Amazon.Runtime.Support"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

private static void LogWithLevelToConsole(string level, string message, params object[] args)
{
// Formatting here is not important, it is used for debugging Amazon.Lambda.Core only.
// In a real scenario Amazon.Runtime.Support will change the value of _loggingWithLevelAction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong name "Amazon.Runtime.Support"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


private const string ParameterizedPreviewMessage =
"This method has been mark as preview till the Lambda .NET Managed runtime has been updated with the backing implementation of this method. " +
"It is possible to use this method whilein preview if the Lambda function is deployed as an executable and uses the latest version of Amazon.Lambda.RuntimeSupport.";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo in "whilein"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@normj normj merged commit b0d7cce into dev Mar 13, 2025
5 checks passed
@normj normj deleted the normj/global-logging-level branch March 13, 2025 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants