Repository: aws-powertools/powertools-lambda-python

Issue:
Bug: Child Logger doesn't respect loglevel
### Expected Behaviour

When creating Child Loggers, it should be possible to change log level.

### Default Python Library
```python
import logging

parent_logger = logging.getLogger('parent')
parent_logger.setLevel(logging.DEBUG)

parent_handler = logging.StreamHandler()
parent_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
parent_handler.setFormatter(parent_formatter)
parent_logger.addHandler(parent_handler)
parent_logger.setLevel("INFO")

child_logger = logging.getLogger('parent.child')

child_handler = logging.StreamHandler()
child_formatter = logging.Formatter('%(name)s [%(filename)s:%(lineno)d] - %(levelname)s - %(message)s')
child_handler.setFormatter(child_formatter)
child_logger.addHandler(child_handler)
child_logger.setLevel("DEBUG")

parent_logger.debug("This is a parent logger message") # LogLevel of "parent" is INFO, won't be printed
child_logger.debug("This is a child logger message") # LogLevel of "parent.child" is DEBUG, will be printed
```

### Powertools
```python
from aws_lambda_powertools import Logger

logger = Logger(
    service="payment",
    location="Test1",
    level="INFO"
)

logger2 = Logger(
    service="payment",
    child=True,
    location="Test2",
    level="DEBUG" # This doesn't take effect
)
```

### Current Behaviour

It does not respect the log level and does not emit logs if the child logger has a different log level.

### Code snippet

```python
from aws_lambda_powertools import Logger
import logging

location_format = "[%(funcName)s] %(module)s"

logger = Logger(
    service="payment",
    location=location_format,
    level="INFO"
)

logger.info("Test1")

logger2 = Logger(
    service="payment",
    child=True,
    location="Test2",
    level="DEBUG"
)
```

### Possible Solution

_No response_

### Steps to Reproduce

Write a function and use the code.

### Powertools for AWS Lambda (Python) version

latest

### AWS Lambda function runtime

3.13

### Packaging format used

Lambda Layers, PyPi

### Debugging logs

```python

```

Hints from issue comments:
@github-actions: ### ⚠️COMMENT VISIBILITY WARNING⚠️
This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a [team member](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/MAINTAINERS.md#current-maintainers) or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.@github-actions: This is now released under [3.6.0](https://github.com/aws-powertools/powertools-lambda-python/releases/tag/v3.6.0) version!

Solution patch:
diff --git a/aws_lambda_powertools/logging/logger.py b/aws_lambda_powertools/logging/logger.py
index c242f5c9b..ab29b6af6 100644
--- a/aws_lambda_powertools/logging/logger.py
+++ b/aws_lambda_powertools/logging/logger.py
@@ -285,7 +285,11 @@ class Logger:
         #   b) different sampling mechanisms
         #   c) multiple messages from being logged as handlers can be duplicated
         is_logger_preconfigured = getattr(self._logger, LOGGER_ATTRIBUTE_PRECONFIGURED, False)
-        if self.child or is_logger_preconfigured:
+        if self.child:
+            self.setLevel(log_level)
+            return
+
+        if is_logger_preconfigured:
             return
 
         self.setLevel(log_level)


Test patch:
diff --git a/tests/functional/logger/required_dependencies/test_logger.py b/tests/functional/logger/required_dependencies/test_logger.py
index 70f08f1bb..5c85677d7 100644
--- a/tests/functional/logger/required_dependencies/test_logger.py
+++ b/tests/functional/logger/required_dependencies/test_logger.py
@@ -1217,3 +1217,18 @@ def test_append_context_keys_with_formatter(stdout, service_name):
     # THEN the context keys should not persist
     current_keys = logger.get_current_keys()
     assert current_keys == {}
+
+
+def test_logger_change_level_child_logger(stdout, service_name):
+    # GIVEN a new Logger and child Logger
+    logger = Logger(service=service_name, stream=stdout)
+    child_logger = Logger(service=service_name, child=True, stream=stdout, level="DEBUG")
+
+    # WHEN we emit logs for both in DEBUG level
+    logger.debug("PARENT")
+    child_logger.debug("CHILD")
+
+    # THEN only child log must emit log due to level
+    logs = list(stdout.getvalue().strip().split("\n"))
+    assert len(logs) == 1
+    assert "service" in logs[0]