Repository: meltano/meltano

Issue:
Azure State backend - silence logs
### Feature scope

Configuration (settings parsing, validation, etc.)

### Description

Using Azure as a backend fills the meltano log with noise, multiple log lines for each http request, basically making the log unusable.

So far I have managed to silence these logs with an addition to `meltano/core/state_store/azure.py`

```
import logging

logger=logging.getLogger('azure.core.pipeline.policies.http_logging_policy')
logger.setLevel(logging.WARNING)
```

Without the suppression above, the logs are full of multiline messages like this, logs become virtually useless:

```
2023-05-31T08:29:59.892347Z [info     ] Request URL: 'https://***.blob.core.windows.net/meltano-state/dev%3Atap-freshdesk-to-target-postgres/lock'
Request method: 'HEAD'
Request headers:
    'x-ms-version': 'REDACTED'
    'Accept': 'application/xml'
    'User-Agent': 'azsdk-python-storage-blob/12.16.0 Python/3.9.16 (Linux-5.10.102.2-microsoft-standard-x86_64-with-glibc2.31)'
    'x-ms-date': 'REDACTED'
    'x-ms-client-request-id': '54f13080-ff8d-11ed-8616-00155da6d400'
    'Authorization': 'REDACTED'
No body was attached to the request
2023-05-31T08:29:59.901579Z [info     ] Response status: 404
Response headers:
    'Transfer-Encoding': 'chunked'
    'Server': 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0'
    'x-ms-request-id': 'fe209118-f01e-0044-229a-935122000000'
    'x-ms-client-request-id': '54f13080-ff8d-11ed-8616-00155da6d400'
    'x-ms-version': 'REDACTED'
    'x-ms-error-code': 'BlobNotFound'
    'Date': 'Wed, 31 May 2023 08:29:59 GMT'
2023-05-31T08:29:59.913150Z [info     ] Request URL: 'https://***.blob.core.windows.net/meltano-state/dev%3Atap-freshdesk-to-target-postgres/lock?comp=REDACTED&blockid=REDACTED'
Request method: 'PUT'
Request headers:
    'Content-Length': '17'
    'x-ms-version': 'REDACTED'
    'Content-Type': 'application/octet-stream'
    'Accept': 'application/xml'
    'User-Agent': 'azsdk-python-storage-blob/12.16.0 Python/3.9.16 (Linux-5.10.102.2-microsoft-standard-x86_64-with-glibc2.31)'
    'x-ms-date': 'REDACTED'
    'x-ms-client-request-id': '54f45b48-ff8d-11ed-8616-00155da6d400'
    'Authorization': 'REDACTED'
A body is sent with the request
```

Would you consider a PR to suppress the INFO logs from Azure Blob Client?



Discussion:
Thanks for reporting @acarter24!

> Would you consider a PR to suppress the INFO logs from Azure Blob Client?

I think so! I wonder if we could set the level for that logger in the default logging config:

https://github.com/meltano/meltano/blob/857d62b8b18d04ca31c29f9d5d7f20a17e43bd74/src/meltano/core/logging/utils.py#L104-L125
Looks like a good solution. I'm just attempting something with `logging.yaml` to see if I can fix for my specific case, but I think it would be wise to have it in the default logging config, it absolutely obliterates the meltano logs :)
I tried this in logging.yaml

```
version: 1
loggers:
  azure.core.pipeline.policies.http_logging_policy:
    handlers: [console]
    level: WARNING
    propagate: yes
```

but received this error

```
Unable to configure logger 'azure.core.pipeline.policies.http_logging_policy'
```

First time using logging.yaml so have I misunderstood how to target a specific logger?

@acarter24 I believe you're missing a definition for the `console` handler. Try this:

```yaml
version: 1
formatters:
  structured:
    (): meltano.core.logging.console_log_formatter
    colors: true
handlers:
  console:
    class: logging.StreamHandler
    level: INFO
    formatter: structured
    stream: "ext://sys.stderr"
loggers:
  azure.core.pipeline.policies.http_logging_policy:
    handlers: [console]
    level: WARNING
    propagate: yes
```
If I were to apply the filter in `meltano/src/meltano/core/logging/utils.py` as you suggested above, is it only affecting core meltano activities like state, or should the logging settings apply to taps/targets too?
> If I were to apply the filter in `meltano/src/meltano/core/logging/utils.py` as you suggested above, is it only affecting core meltano activities like state, or should the logging settings apply to taps/targets too?

It'd only affect the Meltano core. SDK-based plugins can use their own YAML configuration. For example: https://github.com/edgarrmondragon/meltano-dataops/blob/3a742fe69823cc0c83f44a17a878ee9697845bde/meltano.yml#L5-L8
I tried both methods, altering `utils.py` and the `logging.yaml` you suggested above, only the alteration to `utils.py` suppressed the logs. The error I previously had with `logging.yaml` did go away, but the messages from that logger were not suppressed.

Happy to make the PR if you like?
> I tried both methods, altering `utils.py` and the `logging.yaml` you suggested above, only the alteration to `utils.py` suppressed the logs. The error I previously had with `logging.yaml` did go away, but the messages from that logger were not suppressed.

Interesting, might be worth trying with

```yaml
version: 1
disable_existing_loggers: yes
...
```

> Happy to make the PR if you like?

By all means 😄 
Just realised the issue with the file, needs to be `logging.yaml` and not `logging.yml` :) Sorry for the confusion.

This worked - without the `root:` section the log format reverted to the default python type which I don't like so much.

```version: 1

formatters:
  structured_locals: # log format for structured plain text logs WITH local variables
    (): meltano.core.logging.console_log_formatter
    colors: True # also enables traceback formatting with `rich`
    show_locals: True # enables local variable logging in tracebacks (can be very verbose and leak sensitive data)

handlers:
  console: # log to the console (stderr) using structured_colored formatter, logging everything at DEBUG level and up
    class: logging.StreamHandler
    level: INFO
    formatter: structured_locals
    stream: "ext://sys.stderr"

root:
  level: INFO
  propagate: yes
  handlers: [console]

loggers:
  azure.core.pipeline.policies.http_logging_policy:
    handlers: [console]
    level: WARNING
    propagate: yes
```

Will still make the PR though, think it's better than someone else going through this loop again.
Relevant issue for the file name

* https://github.com/meltano/meltano/issues/7013


Resolving patch:
diff --git a/src/meltano/core/logging/utils.py b/src/meltano/core/logging/utils.py
--- a/src/meltano/core/logging/utils.py
+++ b/src/meltano/core/logging/utils.py
@@ -108,18 +108,18 @@ def default_config(log_level: str) -> dict:
                 "propagate": True,
             },
             "snowplow_tracker.emitters": {
-                "handlers": ["console"],
                 "level": logging.ERROR,
             },
             "urllib3": {
-                "handlers": ["console"],
                 "level": logging.INFO,
-                "propagate": False,
             },
             "asyncio": {
-                "handlers": ["console"],
                 "level": logging.INFO,
-                "propagate": False,
+            },
+            # Azure HTTP logs at info level are too noisy; see
+            # https://github.com/meltano/meltano/issues/7723
+            "azure.core.pipeline.policies.http_logging_policy": {
+                "level": logging.WARNING,
             },
         },
     }


Test patch: