Skip to content
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

Docs: Improve Logger documentations typed logger #496

Open
1 task done
amirkaws opened this issue Sep 22, 2023 · 3 comments
Open
1 task done

Docs: Improve Logger documentations typed logger #496

amirkaws opened this issue Sep 22, 2023 · 3 comments
Labels
area/logging Core logging utility documentation Improvements or additions to documentation
Milestone

Comments

@amirkaws
Copy link
Contributor

What were you searching in the docs?

I am looking for the documentation to show me how to use typed logger, and interface based logger rather than Logger. static methods.

public class Function
{
    private static ILogger _logger;

    public Function()
    {
        _logger = Logger.Create<Function>();
    }

    [Logging(LogEvent = true)]
    public async Task<APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest apigwProxyEvent,
              ILambdaContext context)
    {
        _logger.LogInformation(new { LogLocation = "FunctionHandler" }, "Test Message");

        ...
    }
}
{
    "cold_start": true,
    "xray_trace_id": "1-61b7add4-66532bb81441e1b060389429",
    "function_name": "test",
    "function_version": "$LATEST",
    "function_memory_size": 128,
    "function_arn": "arn:aws:lambda:eu-west-1:12345678910:function:test",
    "function_request_id": "52fdfc07-2182-154f-163f-5f0f9a621d72",
    "timestamp": "2021-12-13T20:32:22.5774262Z",
    "level": "Information",
    "service": "lambda-example",
    "name": "HelloWorld.Function",
    "message": "Collecting payment",
    "sampling_rate": 0.7,
    "correlation_id": "correlation_id_value"
}

Is this related to an existing documentation section?

No response

How can we improve?

Add a section in documentation related to typed logger, and another one for dependency injection

Got a suggestion in mind?

No response

Acknowledgment

  • I understand the final update might be different from my proposed suggestion, or refused.
@amirkaws amirkaws added documentation Improvements or additions to documentation triage Pending triage from maintainers labels Sep 22, 2023
@hjgraca hjgraca removed the triage Pending triage from maintainers label Oct 11, 2023
@rahulpnath
Copy link

A couple of observations using the log method on the Logger instance

  1. Throws an exception System.Reflection.TargetParameterCountException: Parameter count mismatch, when using the LogInformation with parameters

     _logger.LogInformation("Testing with parameter Log Information Method {cityName}", cityName);

    Have to explicitly pass the parameters as an object[] for it to work like below.

     _logger.LogInformation("Testing with parameter Log Information Method {cityName}", new[] { cityName });
  2. Logged Parameters are not available in the output as destructured parameters.
    The above log statement outputs the below in CloudWatch

    {
     "cold_start": true,
     "xray_trace_id": "1-654bd325-0acb33237c954016773e537b",
     "function_name": "weathertest-LambdaEmptyFunction1FunctionGetWeather-zQceOL6olYxd",
     "function_version": "$LATEST",
     "function_memory_size": 256,
     "function_arn": "arn:aws:lambda:ap-southeast-2:189107071895:function:weathertest-LambdaEmptyFunction1FunctionGetWeather-zQceOL6olYxd",
     "function_request_id": "f32b5d3f-62eb-424c-9cbc-d5b0b48e3d0d",
     "timestamp": "2023-11-08T18:27:50.6013375Z",
     "level": "Information",
     "service": "service_undefined",
     "name": "LambdaEmptyFunction1.Function",
     "message": "Testing with parameter Log Information Method Brisbane"
    }

    I expected the cityName to be available in the log output.

Not sure if these are something that could be included as part of the documentation or am f I am missing something here? @amirkaws

@hjgraca
Copy link
Contributor

hjgraca commented Nov 10, 2023

Hi @rahulpnath thanks for raising the issue and thanks for the youtube video as well 😄 really cool.

So at the moment the way you add "addiitonal keys" is by calling the methods Logger.AppendKey or Logger.AppendKeys you can have a look in the docs.

The reason behind that approach was for the user experience to be the same across all Powertools runtimes.
We now believe that we need a more .NET way to do logging, we are in the process of creating an RFC which will be similar to what you are alluding to, essentially resembling what ILogger does or what Serilog does.

Any input or feedback will be greatly appreciated, we don't have anything public yet, so if you have any ideas would love to hear them

@hjgraca hjgraca added this to the Logging V2 milestone Dec 12, 2023
@hjgraca hjgraca added the area/logging Core logging utility label Dec 12, 2023
@hjgraca hjgraca moved this to 📋 Backlog in Powertools for AWS Lambda (.NET) Dec 12, 2023
@hjgraca
Copy link
Contributor

hjgraca commented Mar 14, 2024

Discussion: #570

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/logging Core logging utility documentation Improvements or additions to documentation
Projects
Status: 📋 Backlog
Development

No branches or pull requests

3 participants