-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set root log level from zappa log_level
- Loading branch information
Showing
5 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import pytest | ||
import logging | ||
from zappa.handler import LambdaHandler | ||
|
||
""" | ||
https://github.com/zappa/Zappa/issues/1336 | ||
2024-08-13 @ceturc | ||
Test that the root logger's level is updated when log_level is set. | ||
This was Zappa's default behavior prior to 0.59.0. This test is | ||
designed to prevent future regressions of logging. | ||
""" | ||
|
||
event = { | ||
"body": "", | ||
"resource": "/{proxy+}", | ||
"requestContext": {}, | ||
"queryStringParameters": {}, | ||
"headers": { | ||
"Host": "example.com", | ||
}, | ||
"pathParameters": {"proxy": "root-logger"}, | ||
"httpMethod": "GET", | ||
"stageVariables": {}, | ||
"path": "/root-logger", | ||
} | ||
|
||
|
||
@pytest.fixture() | ||
def reset_handler_singleton(): | ||
""" | ||
Since the LambdaHandler is a singleton, it must be | ||
destroyed before tests for logging changes to take effect. | ||
""" | ||
LambdaHandler._LambdaHandler__instance = None | ||
yield | ||
|
||
|
||
def test_wsgi_root_log_level_debug(caplog, reset_handler_singleton): | ||
lh = LambdaHandler("tests.test_wsgi_root_log_level_settings_debug") | ||
response = lh.handler(event, None) | ||
assert response["statusCode"] == 200 | ||
assert ("root", logging.DEBUG, "debug message") in caplog.record_tuples | ||
assert ("root", logging.INFO, "info message") in caplog.record_tuples | ||
assert ("root", logging.WARNING, "warning message") in caplog.record_tuples | ||
assert ("root", logging.ERROR, "error message") in caplog.record_tuples | ||
assert ("root", logging.CRITICAL, "critical message") in caplog.record_tuples | ||
|
||
|
||
def test_wsgi_root_log_level_info(caplog, reset_handler_singleton): | ||
lh = LambdaHandler("tests.test_wsgi_root_log_level_settings_info") | ||
response = lh.handler(event, None) | ||
assert response["statusCode"] == 200 | ||
assert ("root", logging.DEBUG, "debug message") not in caplog.record_tuples | ||
assert ("root", logging.INFO, "info message") in caplog.record_tuples | ||
assert ("root", logging.WARNING, "warning message") in caplog.record_tuples | ||
assert ("root", logging.ERROR, "error message") in caplog.record_tuples | ||
assert ("root", logging.CRITICAL, "critical message") in caplog.record_tuples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from flask import Flask, request | ||
import logging | ||
|
||
app = Flask(__name__) | ||
|
||
|
||
@app.route("/root-logger", methods=["GET", "POST"]) | ||
def return_request_url(): | ||
logging.debug("debug message") | ||
logging.info("info message") | ||
logging.warning("warning message") | ||
logging.error("error message") | ||
logging.critical("critical message") | ||
return "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
API_STAGE = "dev" | ||
APP_FUNCTION = "app" | ||
APP_MODULE = "tests.test_wsgi_root_log_level_app" | ||
BINARY_SUPPORT = False | ||
CONTEXT_HEADER_MAPPINGS = {} | ||
DEBUG = "True" | ||
DJANGO_SETTINGS = None | ||
DOMAIN = "api.example.com" | ||
ENVIRONMENT_VARIABLES = {} | ||
LOG_LEVEL = "DEBUG" | ||
PROJECT_NAME = "wsgi_root_log_level" | ||
COGNITO_TRIGGER_MAPPING = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
API_STAGE = "dev" | ||
APP_FUNCTION = "app" | ||
APP_MODULE = "tests.test_wsgi_root_log_level_app" | ||
BINARY_SUPPORT = False | ||
CONTEXT_HEADER_MAPPINGS = {} | ||
DEBUG = "True" | ||
DJANGO_SETTINGS = None | ||
DOMAIN = "api.example.com" | ||
ENVIRONMENT_VARIABLES = {} | ||
LOG_LEVEL = "INFO" | ||
PROJECT_NAME = "wsgi_root_log_level" | ||
COGNITO_TRIGGER_MAPPING = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters