-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for debug logs in executed functions. (#745)
* Adding support for debug logs in executed functions. * Adding tests to see make sure host prevents debug logs
- Loading branch information
Showing
14 changed files
with
235 additions
and
17 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 |
---|---|---|
|
@@ -84,7 +84,7 @@ celerybeat-schedule | |
|
||
# virtualenv (.venv/.venv36/.venv37/.venv38) | ||
.venv* | ||
venv/ | ||
venv*/ | ||
ENV/ | ||
py3env/ | ||
|
||
|
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
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
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
15 changes: 15 additions & 0 deletions
15
tests/unittests/http_functions/debug_logging/function.json
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,15 @@ | ||
{ | ||
"scriptFile": "main.py", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$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,13 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import logging | ||
|
||
import azure.functions | ||
|
||
|
||
def main(req: azure.functions.HttpRequest): | ||
logging.info('logging info', exc_info=True) | ||
logging.warning('logging warning', exc_info=True) | ||
logging.debug('logging debug', exc_info=True) | ||
logging.error('logging error', exc_info=True) | ||
return 'OK-debug' |
15 changes: 15 additions & 0 deletions
15
tests/unittests/http_functions/debug_user_logging/function.json
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,15 @@ | ||
{ | ||
"scriptFile": "main.py", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$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,16 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import logging | ||
|
||
import azure.functions | ||
|
||
|
||
logger = logging.getLogger('my function') | ||
|
||
|
||
def main(req: azure.functions.HttpRequest): | ||
logger.info('logging info', exc_info=True) | ||
logger.warning('logging warning', exc_info=True) | ||
logger.debug('logging debug', exc_info=True) | ||
logger.error('logging error', exc_info=True) | ||
return 'OK-user-debug' |
15 changes: 15 additions & 0 deletions
15
tests/unittests/log_filtering_functions/debug_logging/function.json
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,15 @@ | ||
{ | ||
"scriptFile": "main.py", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/unittests/log_filtering_functions/debug_logging/main.py
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,13 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import logging | ||
|
||
import azure.functions | ||
|
||
|
||
def main(req: azure.functions.HttpRequest): | ||
logging.info('logging info', exc_info=True) | ||
logging.warning('logging warning', exc_info=True) | ||
logging.debug('logging debug', exc_info=True) | ||
logging.error('logging error', exc_info=True) | ||
return 'OK-debug' |
15 changes: 15 additions & 0 deletions
15
tests/unittests/log_filtering_functions/debug_user_logging/function.json
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,15 @@ | ||
{ | ||
"scriptFile": "main.py", | ||
"bindings": [ | ||
{ | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req" | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/unittests/log_filtering_functions/debug_user_logging/main.py
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,16 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
import logging | ||
|
||
import azure.functions | ||
|
||
|
||
logger = logging.getLogger('my function') | ||
|
||
|
||
def main(req: azure.functions.HttpRequest): | ||
logger.info('logging info', exc_info=True) | ||
logger.warning('logging warning', exc_info=True) | ||
logger.debug('logging debug', exc_info=True) | ||
logger.error('logging error', exc_info=True) | ||
return 'OK-user-debug' |
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
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,64 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import typing | ||
|
||
from azure_functions_worker import testutils | ||
from azure_functions_worker.testutils import TESTS_ROOT, remove_path | ||
|
||
HOST_JSON_TEMPLATE_WITH_LOGLEVEL_INFO = """\ | ||
{ | ||
"version": "2.0", | ||
"logging": { | ||
"logLevel": { | ||
"default": "Information" | ||
} | ||
}, | ||
"functionTimeout": "00:05:00" | ||
} | ||
""" | ||
|
||
|
||
class TestLogFilteringFunctions(testutils.WebHostTestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
host_json = TESTS_ROOT / cls.get_script_dir() / 'host.json' | ||
|
||
with open(host_json, 'w+') as f: | ||
f.write(HOST_JSON_TEMPLATE_WITH_LOGLEVEL_INFO) | ||
|
||
super(TestLogFilteringFunctions, cls).setUpClass() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
host_json = TESTS_ROOT / cls.get_script_dir() / 'host.json' | ||
remove_path(host_json) | ||
|
||
super(TestLogFilteringFunctions, cls).tearDownClass() | ||
|
||
@classmethod | ||
def get_script_dir(cls): | ||
return testutils.UNIT_TESTS_FOLDER / 'log_filtering_functions' | ||
|
||
def test_debug_logging(self): | ||
r = self.webhost.request('GET', 'debug_logging') | ||
self.assertEqual(r.status_code, 200) | ||
self.assertEqual(r.text, 'OK-debug') | ||
|
||
def check_log_debug_logging(self, host_out: typing.List[str]): | ||
self.assertIn('logging info', host_out) | ||
self.assertIn('logging warning', host_out) | ||
self.assertIn('logging error', host_out) | ||
self.assertNotIn('logging debug', host_out) | ||
|
||
def test_debug_with_user_logging(self): | ||
r = self.webhost.request('GET', 'debug_user_logging') | ||
self.assertEqual(r.status_code, 200) | ||
self.assertEqual(r.text, 'OK-user-debug') | ||
|
||
def check_log_debug_with_user_logging(self, host_out: typing.List[str]): | ||
self.assertIn('logging info', host_out) | ||
self.assertIn('logging warning', host_out) | ||
self.assertIn('logging error', host_out) | ||
self.assertNotIn('logging debug', host_out) |