forked from Azure/azure-sdk-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdo_not_log_exceptions.py
More file actions
96 lines (82 loc) · 2.64 KB
/
do_not_log_exceptions.py
File metadata and controls
96 lines (82 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from plugin import logger
# test_logging_levels_logged_str_exception
def test_logging_levels_logged_str_exception():
try: # @
add = 1 + 2
except Exception as ex:
logger.error("Error" + str(ex)) # @
logger.warning(str(ex))
logger.info(str(ex))
logger.debug(str(ex))
# test_logging_levels_logged_repr_exception
def test_logging_levels_logged_repr_exception():
try: # @
add = 1 + 2
except Exception as ex:
logger.error(repr(ex)) # @
logger.warning(repr(ex))
logger.info(repr(ex))
logger.debug(repr(ex))
# test_regular_logging_ok
def test_regular_logging_ok():
try: # @
add = 1 + 2
except Exception as ex:
logger.error("Example 1") # @
logger.warning("This is another example")
logger.info("Random logging")
logger.debug("Logging")
# test_logging_str_exception_branches
def test_logging_str_exception_branches():
try: # @
add = 1 + 2
except Exception as ex:
if ex.code == "Retryable":
logger.error(str(ex))
return True
elif Exception != BaseException:
logger.warning(repr(ex))
return False
else:
logger.info(str(ex)) # @
# test_other_logging_fails
def test_other_logging_fails():
try: # @
add = 1 + 2
except Exception as ex:
if ex.code == "Retryable":
logger.error("Something went wrong: {ex}. Try again")
return True
else:
logger.warning(ex)
return False
# test_no_logging_and_no_exception_name_ok
def test_no_logging_and_no_exception_name_ok():
try:
add = 1 + 2
except Exception as ex:
self.errors.appendleft(ex)
except Exception as ex: # pylint: disable=broad-except
_logger.warning(
"Exception occurred when instrumenting: %s.",
lib_name,
exc_info=ex,
)
except (OSError, PermissionError) as e:
logger.warning(
"Failed to read on-disk cache for component due to %s. "
"Please check if the file %s is in use or current user doesn't have the permission.",
type(e).__name__,
on_disk_cache_path.as_posix(),
)
# test_logging_without_exception_name
def test_logging_without_exception_name():
try:
add = 1 + 2
except Exception as exception:
if exception.code == "Retryable":
_LOGGER.info(
"%r returns an exception %r", self._container_id, last_exception
)
else:
module_logger.debug("Skipping file upload, reason: %s", str(e.reason))