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

Logging settings not working for Serverless API Blueprint #399

Closed
matheusmaximo opened this issue Feb 18, 2019 · 7 comments
Closed

Logging settings not working for Serverless API Blueprint #399

matheusmaximo opened this issue Feb 18, 2019 · 7 comments
Labels
bug This issue is a bug. investigating This issue is being investigated and/or work is in progress to resolve the issue.

Comments

@matheusmaximo
Copy link

Steps to reproduce:

  1. Create a new Serverless application using ASP.NET Core Web API from Blueprint

  2. Amend ValuesController to have the following code:

     private readonly ILogger<ValuesController> _logger;
    
     public ValuesController(ILogger<ValuesController> logger)
     {
         _logger = logger;
     }
    
     // GET api/values
     [HttpGet]
     public IEnumerable<string> Get()
     {
         _logger.LogDebug("This is a DEBUG comment");
         return new string[] { "value1", "value2" };
     }
    
  3. Run code

  4. Using postman, hit the ValuesController Get.

I can see 2 possible solutions here:
a) Amend appsetings.json to Logging section instead of Lambda.Logging
b) Amend this file aws-lambda-dotnet/blob/master/Libraries/src/Amazon.Lambda.AspNetCoreServer/AbstractAspNetCoreFunction.cs Line 179 to not include the Section "Logging"

@klaytaybai klaytaybai added the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Feb 20, 2019
@klaytaybai
Copy link

I'm going to start working on reproducing this now. What is the exception/problem you are seeing?

@matheusmaximo
Copy link
Author

I was expecting "This is a DEBUG comment" to appears in debug logs (console app and CloudWatch). They are not appearing neither one.

@klaytaybai
Copy link

Hi @matheusmaximo, I'm not sure why Debug logs don't work, but it could be related to aws/aws-logging-dotnet#52. For you, at least you are already using the correct Amazon.Lambda.Logging.AspNetCore logging library if you are using the Serverless API Blueprint. I don't think the solutions you recommended are appropriate. If you try creating some logs with other log levels, which should work, you will see that adjusting the log levels in the appsettings.json will correctly filter out low log levels.

I'll talk with @normj to find out more about the complications with Debug logs.

@normj
Copy link
Member

normj commented Feb 21, 2019

Looks like we have a bug in the Amazon.Lambda.AspNetCoreServer that is not pulling the log levels into the ILoggingBuilder. I'll investigate why that is happening.

You can change the minimum in code by editing the class that extends from APIGatewayProxyFunction which is usually LambdaEntryPoint

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;

namespace LambdaLoggingDebugTest
{
    public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
    {
        protected override void Init(IWebHostBuilder builder)
        {
            builder
                .UseStartup<Startup>()
                .ConfigureLogging((hostingContext, logging) =>
                {
                    logging.SetMinimumLevel(LogLevel.Trace);
                });
        }
    }
}

@klaytaybai klaytaybai added the bug This issue is a bug. label Feb 21, 2019
@normj
Copy link
Member

normj commented Feb 21, 2019

I found the problem in the library causing the logging settings to not be correctly read from appsettings.json 0d3cdb3

I'll get the fix out soon.

@normj
Copy link
Member

normj commented Feb 22, 2019

I just released version 3.0.2 of Amazon.Lambda.AspNetCoreServer which fixes the bug with logging not being read from config.

@normj normj closed this as completed Feb 22, 2019
@matheusmaximo
Copy link
Author

I confirm that this fixed the problem. Thank you all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. investigating This issue is being investigated and/or work is in progress to resolve the issue.
Projects
None yet
Development

No branches or pull requests

3 participants