Skip to content

Commit fd8a4ce

Browse files
authored
Merge branch 'dev' into wangbill/lazy-format-logging
2 parents fe84ae6 + 6c5613d commit fd8a4ce

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

azure_functions_worker/logging.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@
2121
error_handler: Optional[logging.Handler] = None
2222

2323

24-
def format_exception(exception):
24+
def format_exception(exception: Exception) -> str:
2525
msg = str(exception) + "\n"
26-
msg += ''.join(traceback.format_exception(
27-
etype=type(exception), value=exception, tb=exception.__traceback__))
26+
if sys.version_info.minor < 10:
27+
msg += ''.join(traceback.format_exception(
28+
etype=type(exception),
29+
tb=exception.__traceback__,
30+
value=exception))
31+
elif sys.version_info.minor == 10:
32+
msg += ''.join(traceback.format_exception(exception))
33+
else:
34+
msg = str(exception)
2835
return msg
2936

3037

azure_functions_worker/utils/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ def is_true_like(setting: str) -> bool:
1111
if setting is None:
1212
return False
1313

14-
return setting.lower().strip() in ['1', 'true', 't', 'yes', 'y']
14+
return setting.lower().strip() in {'1', 'true', 't', 'yes', 'y'}
1515

1616

1717
def is_false_like(setting: str) -> bool:
1818
if setting is None:
1919
return False
2020

21-
return setting.lower().strip() in ['0', 'false', 'f', 'no', 'n']
21+
return setting.lower().strip() in {'0', 'false', 'f', 'no', 'n'}
2222

2323

2424
def is_envvar_true(env_key: str) -> bool:

tests/unittests/test_logging.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import unittest
44

55
from azure_functions_worker import logging as flog
6+
from azure_functions_worker.logging import format_exception
67

78

89
class TestLogging(unittest.TestCase):
@@ -33,3 +34,27 @@ def test_customer_log_namespace(self):
3334
self.assertFalse(flog.is_system_log_category('protobuf'))
3435
self.assertFalse(flog.is_system_log_category('root'))
3536
self.assertFalse(flog.is_system_log_category(''))
37+
38+
def test_format_exception(self):
39+
def call0(fn):
40+
call1(fn)
41+
42+
def call1(fn):
43+
call2(fn)
44+
45+
def call2(fn):
46+
fn()
47+
48+
def raising_function():
49+
raise ValueError("Value error being raised.", )
50+
51+
try:
52+
call0(raising_function)
53+
except ValueError as e:
54+
processed_exception = format_exception(e)
55+
self.assertIn("call0", processed_exception)
56+
self.assertIn("call1", processed_exception)
57+
self.assertIn("call2", processed_exception)
58+
self.assertIn("f", processed_exception)
59+
self.assertIn("tests/unittests/test_logging.py",
60+
processed_exception)

0 commit comments

Comments
 (0)