Azure / azure-functions-core-tools

Command line tools for Azure Functions
MIT License
1.3k stars 431 forks source link

Azure Functions - Disable this log - "Sending HTTP request GET https//...." #3059

Open Yashuaa opened 2 years ago

Yashuaa commented 2 years ago

Hi,

We make multiple http request, I don't want to see this puke

Sending HTTP request GET https://www.some-external-api.com....

How can I disable these logs?

I tried "logging:logLevel:Microsoft.Azure.WebJobs.Script.WebHost.Middleware.SystemTraceMiddleware": "None" and it didn't work..

For example I don't want to see these HTTP logs that are similar to this image

Yashuaa commented 2 years ago

bump

Yashuaa commented 2 years ago

hello?

Yashuaa commented 2 years ago

is anyone out there? echoes

Yashuaa commented 2 years ago

Imagine - a whole week - and not even a comment lol.

Yashuaa commented 2 years ago

hey, its me again

kshyju commented 2 years ago

Hi @Yashuaa 👋

Where are you seeing this log messages? How does your Logging or LogLevel settings configured? You should be able to update the log level for any logger category using these settings.

Yashuaa commented 2 years ago

Hi @kshyju . This is in Azure Functions Log Stream... I can't find out how to suppress... I've looked everywhere, I don't think it's possible to suppress just the request garbage and not EVERYTHING under the information category .... does that make sense ?

kshyju commented 2 years ago

@Yashuaa Can your host.JSON, specifically the logging portion of the JSON. Also, Is this is a V3 app or V4? In-proc or isolated?

ejizba commented 2 years ago

FYI here's a pretty good writeup of how to suppress various logs: https://github.com/anthonychu/functions-log-suppression

In addition to @kshyju's questions - I'm also curious what language this is for? (.NET/JavaScript/etc.)

Yashuaa commented 2 years ago

this is .NET 6 C# Azure Function v4 (the latest)

kshyju commented 2 years ago

@Yashuaa Can your host.JSON, specifically the logging portion of the JSON?

Yashuaa commented 2 years ago

sure..


    "logging": {
        "logLevel": {
            "Function": "Information",
            "default": "None"
        },
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            },
            "httpAutoCollectionOptions": {
                "enableHttpTriggerExtendedInfoCollection": false,
                "enableW3CDistributedTracing": false,
                "enableResponseHeaderInjection": false
            }
        }
    }
Yashuaa commented 2 years ago

Any ideas anyone? @kshyju

Yashuaa commented 2 years ago

I guess there is no way to do this unless you change the log level above Information, but then you suppress all of your logs.

CSaldanha commented 1 year ago

I'm having the same issue where I am also seeing a Verbose Log message with Request headers exposing the Authorization header. Any ideas on how to suppress these log messages:

2023-01-18T20:08:09Z   [Information]   Start processing HTTP request GET <url>
2023-01-18T20:08:09Z   [Verbose]   Request Headers:
Authorization: ...    
BhuvanaBellala commented 1 year ago

Same issue. The Request headers do not show up in App insights but do show up in log stream. My host.json contains the following and it didn't help. Any other suggestions?

"logLevel": {
  "default": "Error",
  "Azure.Core": "Warning",
  "System.Net.Http.HttpClient": "Warning"
  }
unowiz commented 1 year ago

I have the same issue in my Azure Function (.net7 dotnet-isolated ) with http Client injected. ` public class Function1 { private readonly ILogger _logger; private readonly HttpClient _httpClient;

    public HwBLDImport(ILogger<Function1> logger, IHttpClientFactory httpClientFactory)
    {
        _logger = logger;
        _httpClient = httpClientFactory.CreateClient();
        _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    }

// rest of the code `

and a very simple start up ` using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting;

var host = new HostBuilder() .ConfigureFunctionsWorkerDefaults() .ConfigureServices((config, services) => { services.AddHttpClient(); }) .Build();

host.Run(); `

host.json simply ignores what every I add to stop the http client logging `

{ "version": "2.0", "logging": { "logLevel": { "System.Net.Http.HttpClient.*": "Error" }, "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" } } } } `

The log suppressions that Anthony Chu mentioned do not work https://github.com/anthonychu/functions-log-suppression

Kriof commented 10 months ago

I know it was resolved issue with hosts.json for out-of-process Azure Functions but it seems not to work for .net 5,6,7 Isolated mode... Any ideas how to resolve it for Isolated?

matt-cassinelli commented 8 months ago

This was annoying for me too. As a workaround I added this to Program.cs:

.ConfigureLogging(logging =>
{
    logging.AddFilter("Azure.Core", LogLevel.Warning);
})
arteny commented 8 months ago

This was annoying for me too. As a workaround I added this to Program.cs:

.ConfigureLogging(logging =>
{
    logging.AddFilter("Azure.Core", LogLevel.Warning);
})

for which object you added this?

SeyedAliAsghari96 commented 5 months ago

i added .ConfigureLogging(logging => { logging.SetMinimumLevel( LogLevel.Warning); }) and log my information with _logger.LogWarning. Is there a way to keep the logInformation added in the code without using _logger.LogWarning?

NamelessParanoia commented 1 week ago

For anyone experiencing this in .NET 8 Isolated: I found that the host.json file needed to be specifically loaded as a configuration file in order for the application to load it. Perhaps this is part of the standard template, but it's easy to miss when migrating. hostBuilder.ConfigureAppConfiguration((context, builder) =>{ builder.AddJsonFile("host.json", optional: true); ....

As also noted in other articles, there's a default rule that prevents logging above warning level to app insights. This is disabled using the following code:

.ConfigureLogging(logging =>
{
    // The Application Insights SDK adds a default logging filter that instructs ILogger to capture only Warning and more severe logs. Application Insights requires an explicit override. 
    // Configuration in hosts did not override
    logging.Services.Configure<LoggerFilterOptions>(options =>
    {
        LoggerFilterRule? defaultRule = options?.Rules?.FirstOrDefault(rule => rule.ProviderName == "Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider");
        if (defaultRule is not null)
        {
            options!.Rules.Remove(defaultRule);
        }
    });
})

The below is a sample content for host.json - note the "System.Net.Http.HttpClient": "None". Dependencies for HTTP calls are still tracked, so we really don't need the noise the httpclient throws out. Once the host.json was specifically loaded to config, it was then seemingly respected.

"logging": {
  "logLevel": {
    "default": "Information",
    "Function": "Information",
    "Host.Aggregator": "Information",
    "Azure.Messaging.ServiceBus": "Warning",
    "Azure.Core": "Warning",
    "Azure.Core.1": "Warning",
    "Azure.Core.2": "Warning",
    "Azure.Core.3": "Warning",
    "Azure.Core.4": "Warning",
    "Azure.Storage.Blobs": "Warning",
    "Azure.Storage.Tables": "Warning",
    "DurableTask.AzureStorage": "Warning",
    "System.Net.Http.HttpClient": "None"
  },
  "applicationInsights": {
    "samplingSettings": {
      "isEnabled": true,
      "excludedTypes": "Traces;Exceptions"
    },
    "enableLiveMetricsFilters": true
  }
},