python-sdk-local 0.0.24__tar.gz → 0.0.26__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python-sdk-local-0.0.24 → python-sdk-local-0.0.26}/PKG-INFO +1 -1
- {python-sdk-local-0.0.24 → python-sdk-local-0.0.26}/python_sdk_local.egg-info/PKG-INFO +1 -1
- {python-sdk-local-0.0.24 → python-sdk-local-0.0.26}/sdk/src/LoggerOutputEnum.py +3 -3
- python-sdk-local-0.0.26/sdk/src/debug_mode.py +82 -0
- {python-sdk-local-0.0.24 → python-sdk-local-0.0.26}/sdk/src/utilities.py +9 -21
- python-sdk-local-0.0.26/sdk/tests/debug_mode_test.py +190 -0
- {python-sdk-local-0.0.24 → python-sdk-local-0.0.26}/setup.py +1 -1
- python-sdk-local-0.0.24/sdk/src/debug_mode.py +0 -66
- python-sdk-local-0.0.24/sdk/tests/debug_mode_test.py +0 -131
- {python-sdk-local-0.0.24 → python-sdk-local-0.0.26}/README.md +0 -0
- {python-sdk-local-0.0.24 → python-sdk-local-0.0.26}/pyproject.toml +0 -0
- {python-sdk-local-0.0.24 → python-sdk-local-0.0.26}/python_sdk_local.egg-info/SOURCES.txt +0 -0
- {python-sdk-local-0.0.24 → python-sdk-local-0.0.26}/python_sdk_local.egg-info/dependency_links.txt +0 -0
- {python-sdk-local-0.0.24 → python-sdk-local-0.0.26}/python_sdk_local.egg-info/top_level.txt +0 -0
- {python-sdk-local-0.0.24 → python-sdk-local-0.0.26}/sdk/__init__.py +0 -0
- {python-sdk-local-0.0.24 → python-sdk-local-0.0.26}/sdk/src/__init__.py +0 -0
- {python-sdk-local-0.0.24 → python-sdk-local-0.0.26}/sdk/tests/__init__.py +0 -0
- {python-sdk-local-0.0.24 → python-sdk-local-0.0.26}/sdk/tests/utilities_test.py +0 -0
- {python-sdk-local-0.0.24 → python-sdk-local-0.0.26}/setup.cfg +0 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
from dotenv import load_dotenv
|
|
5
|
+
load_dotenv()
|
|
6
|
+
from logger_local.LoggerComponentEnum import LoggerComponentEnum
|
|
7
|
+
from logger_local.Logger import Logger
|
|
8
|
+
from logger_local.MessageSeverity import MessageSeverity
|
|
9
|
+
sys.path.append(os.getcwd())
|
|
10
|
+
from python_sdk_local.sdk.src.LoggerOutputEnum import LoggerOutputEnum
|
|
11
|
+
|
|
12
|
+
PYTHON_SDK_LOCAL_COMPONENT_ID = 202
|
|
13
|
+
PYTHON_SDK_LOCAL_COMPONENT_NAME = 'python_sdk_local/src/debug_mode.py'
|
|
14
|
+
LOGGER_CONFIGURATION_JSON = '.logger.json'
|
|
15
|
+
LOGGER_MINIMUM_SEVERITY = os.getenv('LOGGER_MINIMUM_SEVERITY')
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
obj = {
|
|
19
|
+
'component_id': PYTHON_SDK_LOCAL_COMPONENT_ID,
|
|
20
|
+
'component_name': PYTHON_SDK_LOCAL_COMPONENT_NAME,
|
|
21
|
+
'component_category': LoggerComponentEnum.ComponentCategory.Code.value,
|
|
22
|
+
'developer_email': 'yoav.e@circ.zone'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
logger = Logger.create_logger(object=obj)
|
|
26
|
+
class DebugMode:
|
|
27
|
+
def __init__(self):
|
|
28
|
+
self.logger_json = {}
|
|
29
|
+
self.debug_everything = False
|
|
30
|
+
self._init()
|
|
31
|
+
|
|
32
|
+
def _init(self):
|
|
33
|
+
INIT_METHOD_NAME = "_init()"
|
|
34
|
+
logger.start(INIT_METHOD_NAME)
|
|
35
|
+
|
|
36
|
+
global LOGGER_MINIMUM_SEVERITY
|
|
37
|
+
if not LOGGER_MINIMUM_SEVERITY:
|
|
38
|
+
LOGGER_MINIMUM_SEVERITY = 0
|
|
39
|
+
else:
|
|
40
|
+
if hasattr(MessageSeverity, LOGGER_MINIMUM_SEVERITY):
|
|
41
|
+
LOGGER_MINIMUM_SEVERITY = MessageSeverity[LOGGER_MINIMUM_SEVERITY].value
|
|
42
|
+
elif LOGGER_MINIMUM_SEVERITY.isdigit():
|
|
43
|
+
LOGGER_MINIMUM_SEVERITY = int(LOGGER_MINIMUM_SEVERITY)
|
|
44
|
+
else:
|
|
45
|
+
raise Exception("LOGGER_MINIMUM_SEVERITY must be a valid LoggerOutputEnum or a number or None")
|
|
46
|
+
|
|
47
|
+
try:
|
|
48
|
+
with open(LOGGER_CONFIGURATION_JSON, 'r') as file:
|
|
49
|
+
self.logger_json = json.load(file)
|
|
50
|
+
except FileNotFoundError:
|
|
51
|
+
self.debug_everything = True
|
|
52
|
+
logger.info("could not find .logger.json file, debugging everything")
|
|
53
|
+
except Exception as exception:
|
|
54
|
+
logger.exception("encounteredthe following error", object={'exception': exception})
|
|
55
|
+
logger.end(INIT_METHOD_NAME)
|
|
56
|
+
raise
|
|
57
|
+
logger.end(INIT_METHOD_NAME)
|
|
58
|
+
|
|
59
|
+
def is_logger_output(self, component_id:str, logger_output: LoggerOutputEnum, severity_level:int)->bool:
|
|
60
|
+
IS_LOGGER_OUTPUT_METHOD_NAME = "is_logger_output()"
|
|
61
|
+
logger.start(IS_LOGGER_OUTPUT_METHOD_NAME, object={'component_id': component_id, 'logger_output': str(logger_output), 'severity_level': severity_level})
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
#Debug everything that has a severity level higher than the minimum required
|
|
65
|
+
if self.debug_everything:
|
|
66
|
+
result = severity_level >= LOGGER_MINIMUM_SEVERITY
|
|
67
|
+
logger.end(IS_LOGGER_OUTPUT_METHOD_NAME, object={'result': result})
|
|
68
|
+
return result
|
|
69
|
+
|
|
70
|
+
severity_level = max(severity_level, LOGGER_MINIMUM_SEVERITY)
|
|
71
|
+
if component_id in self.logger_json:
|
|
72
|
+
output_info = self.logger_json[component_id]
|
|
73
|
+
if logger_output in output_info:
|
|
74
|
+
result = severity_level >= output_info[logger_output]
|
|
75
|
+
logger.end(IS_LOGGER_OUTPUT_METHOD_NAME, object={'result': result})
|
|
76
|
+
return result
|
|
77
|
+
|
|
78
|
+
# In case the component do not exist in the logger configuration file or the
|
|
79
|
+
# logger_output was not specif
|
|
80
|
+
result = True
|
|
81
|
+
logger.end(IS_LOGGER_OUTPUT_METHOD_NAME, object={'result': result})
|
|
82
|
+
return result
|
|
@@ -41,26 +41,14 @@ def is_list_of_dicts(obj):
|
|
|
41
41
|
IS_LIST_OF_DICTS_FUNCTION_NAME = "is_list_of_dicts()"
|
|
42
42
|
logger.start(IS_LIST_OF_DICTS_FUNCTION_NAME,object = {"obj":obj})
|
|
43
43
|
if not isinstance(obj, list):
|
|
44
|
-
|
|
45
|
-
logger.end(IS_LIST_OF_DICTS_FUNCTION_NAME,object = {"
|
|
46
|
-
return
|
|
44
|
+
is_list_of_dicts_result = False
|
|
45
|
+
logger.end(IS_LIST_OF_DICTS_FUNCTION_NAME,object = {"is_list_of_dicts_result": is_list_of_dicts_result})
|
|
46
|
+
return is_list_of_dicts_result
|
|
47
47
|
for item in obj:
|
|
48
48
|
if not isinstance(item, dict):
|
|
49
|
-
|
|
50
|
-
logger.end(IS_LIST_OF_DICTS_FUNCTION_NAME,object = {'
|
|
51
|
-
return
|
|
52
|
-
|
|
53
|
-
logger.end(IS_LIST_OF_DICTS_FUNCTION_NAME,object = {'
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
# componet id
|
|
61
|
-
# sevirity
|
|
62
|
-
# output
|
|
63
|
-
#minimum sevirity
|
|
64
|
-
|
|
65
|
-
# init from debug file
|
|
66
|
-
# get from
|
|
49
|
+
is_list_of_dicts_result = False
|
|
50
|
+
logger.end(IS_LIST_OF_DICTS_FUNCTION_NAME,object = {'is_list_of_dicts_result': is_list_of_dicts_result})
|
|
51
|
+
return is_list_of_dicts_result
|
|
52
|
+
is_list_of_dicts_result = True
|
|
53
|
+
logger.end(IS_LIST_OF_DICTS_FUNCTION_NAME,object = {'is_list_of_dicts_result': is_list_of_dicts_result})
|
|
54
|
+
return is_list_of_dicts_result
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from dotenv import load_dotenv
|
|
3
|
+
load_dotenv()
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
sys.path.append(os.getcwd())
|
|
7
|
+
|
|
8
|
+
import python_sdk_local.sdk.src.debug_mode as debug_mode
|
|
9
|
+
from python_sdk_local.sdk.src.LoggerOutputEnum import LoggerOutputEnum
|
|
10
|
+
from logger_local.LoggerComponentEnum import LoggerComponentEnum
|
|
11
|
+
from logger_local.Logger import Logger
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
PYTHON_SDK_LOCAL_COMPONENT_ID = 184
|
|
15
|
+
PYTHON_SDK_LOCAL_COMPONENT_NAME = 'python_sdk_local/tests/debug_mode_test.py'
|
|
16
|
+
|
|
17
|
+
obj = {
|
|
18
|
+
'component_id': PYTHON_SDK_LOCAL_COMPONENT_ID,
|
|
19
|
+
'component_name': PYTHON_SDK_LOCAL_COMPONENT_NAME,
|
|
20
|
+
'component_category': LoggerComponentEnum.ComponentCategory.Code.value,
|
|
21
|
+
'developer_email': 'yoav.e@circ.zone'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
logger = Logger.create_logger(object=obj)
|
|
25
|
+
|
|
26
|
+
with open('python_sdk_local/.logger.json.example1', 'r') as file:
|
|
27
|
+
EXAMPLE_DATA_1 = json.load(file)
|
|
28
|
+
|
|
29
|
+
with open('python_sdk_local/.logger.json.example2', 'r') as file:
|
|
30
|
+
EXAMPLE_DATA_2 = json.load(file)
|
|
31
|
+
|
|
32
|
+
def add_debug_file(data):
|
|
33
|
+
|
|
34
|
+
ADD_DEBUG_FILE_FUNCTION_NAME = 'add_debug_file()'
|
|
35
|
+
logger.start(ADD_DEBUG_FILE_FUNCTION_NAME)
|
|
36
|
+
|
|
37
|
+
with open(debug_mode.LOGGER_CONFIGURATION_JSON, 'w') as file:
|
|
38
|
+
json.dump(data, file)
|
|
39
|
+
|
|
40
|
+
logger.end(ADD_DEBUG_FILE_FUNCTION_NAME)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def remove_debug_file():
|
|
44
|
+
REMOVE_DEBUG_FILE_FUNCTION_NAME = 'remove_debug_file()'
|
|
45
|
+
logger.start(REMOVE_DEBUG_FILE_FUNCTION_NAME)
|
|
46
|
+
|
|
47
|
+
os.remove(debug_mode.LOGGER_CONFIGURATION_JSON)
|
|
48
|
+
|
|
49
|
+
logger.end(REMOVE_DEBUG_FILE_FUNCTION_NAME)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_debug_mode_init():
|
|
53
|
+
|
|
54
|
+
#set env variable
|
|
55
|
+
TEST_DEBUG_MODE_INIT_FUNCTION_NAME = 'test_debug_mode_init()'
|
|
56
|
+
logger.start(TEST_DEBUG_MODE_INIT_FUNCTION_NAME)
|
|
57
|
+
|
|
58
|
+
add_debug_file(EXAMPLE_DATA_1)
|
|
59
|
+
|
|
60
|
+
debug = debug_mode.DebugMode()
|
|
61
|
+
|
|
62
|
+
remove_debug_file()
|
|
63
|
+
|
|
64
|
+
result = debug.logger_json == EXAMPLE_DATA_1
|
|
65
|
+
logger.end(TEST_DEBUG_MODE_INIT_FUNCTION_NAME, object={'result': result})
|
|
66
|
+
|
|
67
|
+
assert result
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_is_logger_output_debug_info_1():
|
|
71
|
+
|
|
72
|
+
TEST_is_logger_output_DEBUG_INFO_1_FUNCTION_NAME = 'test_is_logger_output_debug_info_1()'
|
|
73
|
+
logger.start(TEST_is_logger_output_DEBUG_INFO_1_FUNCTION_NAME)
|
|
74
|
+
|
|
75
|
+
add_debug_file(EXAMPLE_DATA_1)
|
|
76
|
+
|
|
77
|
+
debug = debug_mode.DebugMode()
|
|
78
|
+
|
|
79
|
+
remove_debug_file()
|
|
80
|
+
|
|
81
|
+
result = debug.is_logger_output('1', LoggerOutputEnum.Console.value, 501) == True
|
|
82
|
+
logger.end(TEST_is_logger_output_DEBUG_INFO_1_FUNCTION_NAME,
|
|
83
|
+
object={'result': result})
|
|
84
|
+
|
|
85
|
+
assert result
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_is_logger_output_debug_mode_2():
|
|
89
|
+
|
|
90
|
+
TEST_is_logger_output_DEBUG_MODE_2_FUNCTION_NAME = 'test_is_logger_output_debug_mode_2()'
|
|
91
|
+
logger.start(TEST_is_logger_output_DEBUG_MODE_2_FUNCTION_NAME)
|
|
92
|
+
|
|
93
|
+
add_debug_file(EXAMPLE_DATA_2)
|
|
94
|
+
|
|
95
|
+
debug = debug_mode.DebugMode()
|
|
96
|
+
|
|
97
|
+
remove_debug_file()
|
|
98
|
+
|
|
99
|
+
result1 = debug.is_logger_output('2', LoggerOutputEnum.Logzio.value, 502) == True
|
|
100
|
+
result2 = debug.is_logger_output('2', LoggerOutputEnum.MySQLDatabase.value, 503) == True
|
|
101
|
+
result3 = debug.is_logger_output('2', LoggerOutputEnum.Console.value, 499) == False
|
|
102
|
+
|
|
103
|
+
result = result1 and result2 and result3
|
|
104
|
+
logger.end(TEST_is_logger_output_DEBUG_MODE_2_FUNCTION_NAME,
|
|
105
|
+
object={'result': result})
|
|
106
|
+
assert result
|
|
107
|
+
|
|
108
|
+
def test_minimum_sevirity():
|
|
109
|
+
|
|
110
|
+
TEST_MINIMUM_SEVIRITY_FUNCTION_NAME = 'test_minimum_sevirity()'
|
|
111
|
+
logger.start(TEST_MINIMUM_SEVIRITY_FUNCTION_NAME)
|
|
112
|
+
|
|
113
|
+
add_debug_file(EXAMPLE_DATA_2)
|
|
114
|
+
|
|
115
|
+
debug = debug_mode.DebugMode()
|
|
116
|
+
print(debug.logger_json)
|
|
117
|
+
|
|
118
|
+
remove_debug_file()
|
|
119
|
+
|
|
120
|
+
result1 = debug.is_logger_output('2', LoggerOutputEnum.Logzio.value, 501) == False
|
|
121
|
+
result2 = debug.is_logger_output('2', LoggerOutputEnum.Logzio.value, 502) == True
|
|
122
|
+
|
|
123
|
+
debug_mode.LOGGER_MINIMUM_SEVERITY = 0
|
|
124
|
+
|
|
125
|
+
result = result1 and result2
|
|
126
|
+
logger.end(TEST_MINIMUM_SEVIRITY_FUNCTION_NAME, object={'result': result})
|
|
127
|
+
assert result
|
|
128
|
+
|
|
129
|
+
def test_debug_everything():
|
|
130
|
+
|
|
131
|
+
TEST_DEBUG_EVERYTHING_FUNCTION_NAME = 'test_debug_everything()'
|
|
132
|
+
logger.start(TEST_DEBUG_EVERYTHING_FUNCTION_NAME)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
debug = debug_mode.DebugMode() # file DNE, so debug_everything = True
|
|
136
|
+
|
|
137
|
+
result1 = debug.is_logger_output('2', LoggerOutputEnum.Logzio.value, 501) == True
|
|
138
|
+
result2 = debug.is_logger_output('2', LoggerOutputEnum.Logzio.value, 502) == True
|
|
139
|
+
|
|
140
|
+
debug_mode.LOGGER_MINIMUM_SEVERITY = 0
|
|
141
|
+
|
|
142
|
+
result = result1 and result2
|
|
143
|
+
logger.end(TEST_DEBUG_EVERYTHING_FUNCTION_NAME, object={'result': result})
|
|
144
|
+
assert result
|
|
145
|
+
|
|
146
|
+
def test_invalid_logger_minimum_sevirity():
|
|
147
|
+
|
|
148
|
+
TEST_INVALID_LOGGER_MINIMUM_SEVIRITY_FUNCTION_NAME = 'test_invalid_logger_minimum_sevirity()'
|
|
149
|
+
logger.start(TEST_INVALID_LOGGER_MINIMUM_SEVIRITY_FUNCTION_NAME)
|
|
150
|
+
|
|
151
|
+
debug_mode.LOGGER_MINIMUM_SEVERITY = 'invalid'
|
|
152
|
+
|
|
153
|
+
try:
|
|
154
|
+
debug = debug_mode.DebugMode()
|
|
155
|
+
except Exception as e:
|
|
156
|
+
result = True
|
|
157
|
+
else:
|
|
158
|
+
result = False
|
|
159
|
+
|
|
160
|
+
logger.end(TEST_INVALID_LOGGER_MINIMUM_SEVIRITY_FUNCTION_NAME, object={'result': result})
|
|
161
|
+
assert result
|
|
162
|
+
|
|
163
|
+
def test_alpha_numeric_minimum_severity():
|
|
164
|
+
|
|
165
|
+
TEST_ALPHA_NUMERIC_MINIMUM_SEVERITY_FUNCTION_NAME = 'test_alpha_numeric_minimum_severity()'
|
|
166
|
+
logger.start(TEST_ALPHA_NUMERIC_MINIMUM_SEVERITY_FUNCTION_NAME)
|
|
167
|
+
|
|
168
|
+
debug_mode.LOGGER_MINIMUM_SEVERITY = '13'
|
|
169
|
+
|
|
170
|
+
debug = debug_mode.DebugMode()
|
|
171
|
+
|
|
172
|
+
result =debug_mode.LOGGER_MINIMUM_SEVERITY = 13
|
|
173
|
+
|
|
174
|
+
logger.end(TEST_ALPHA_NUMERIC_MINIMUM_SEVERITY_FUNCTION_NAME, object={'result': result})
|
|
175
|
+
assert result
|
|
176
|
+
|
|
177
|
+
def test_enum_minimal_severity():
|
|
178
|
+
TEST_ENUM_MINIMAL_SEVERITY_FUNCTION_NAME = 'test_enum_minimal_severity()'
|
|
179
|
+
logger.start(TEST_ENUM_MINIMAL_SEVERITY_FUNCTION_NAME)
|
|
180
|
+
|
|
181
|
+
debug_mode.LOGGER_MINIMUM_SEVERITY = 'Information'
|
|
182
|
+
|
|
183
|
+
debug = debug_mode.DebugMode()
|
|
184
|
+
|
|
185
|
+
result =debug_mode.LOGGER_MINIMUM_SEVERITY == 500
|
|
186
|
+
|
|
187
|
+
logger.end(TEST_ENUM_MINIMAL_SEVERITY_FUNCTION_NAME, object={'result': result})
|
|
188
|
+
assert result
|
|
189
|
+
|
|
190
|
+
test_debug_everything()
|
|
@@ -3,7 +3,7 @@ import setuptools
|
|
|
3
3
|
# python -m build needs pyproject.toml or setup.py
|
|
4
4
|
setuptools.setup(
|
|
5
5
|
name='python-sdk-local',
|
|
6
|
-
version='0.0.
|
|
6
|
+
version='0.0.26', # https://pypi.org/project/python-sdk-local/
|
|
7
7
|
author="Circles",
|
|
8
8
|
author_email="info@circles.life",
|
|
9
9
|
description="PyPI Package for Circles Python SDK Local Python",
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import os
|
|
3
|
-
import sys
|
|
4
|
-
from dotenv import load_dotenv
|
|
5
|
-
load_dotenv()
|
|
6
|
-
from logger_local.LoggerComponentEnum import LoggerComponentEnum
|
|
7
|
-
from logger_local.Logger import Logger
|
|
8
|
-
sys.path.append(os.getcwd())
|
|
9
|
-
from python_sdk_local.sdk.src.LoggerOutputEnum import LoggerOutputEnum
|
|
10
|
-
|
|
11
|
-
PYTHON_SDK_LOCAL_COMPONENT_ID = 184
|
|
12
|
-
PYTHON_SDK_LOCAL_COMPONENT_NAME = 'python_sdk_local/src/debug_mode.py'
|
|
13
|
-
LOGGER_CONFIGURATION_JSON = '.logger.json'
|
|
14
|
-
LOGGER_MINIMUM_SEVERITY = os.getenv('LOGGER_MINIMUM_SEVERITY')
|
|
15
|
-
|
|
16
|
-
if not LOGGER_MINIMUM_SEVERITY:
|
|
17
|
-
LOGGER_MINIMUM_SEVERITY = 0
|
|
18
|
-
else:
|
|
19
|
-
LOGGER_MINIMUM_SEVERITY = int(LOGGER_MINIMUM_SEVERITY)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
obj = {
|
|
23
|
-
'component_id': PYTHON_SDK_LOCAL_COMPONENT_ID,
|
|
24
|
-
'component_name': PYTHON_SDK_LOCAL_COMPONENT_NAME,
|
|
25
|
-
'component_category': LoggerComponentEnum.ComponentCategory.Code.value,
|
|
26
|
-
'developer_email': 'yoav.e@circ.zone'
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
logger = Logger.create_logger(object=obj)
|
|
30
|
-
class DebugMode:
|
|
31
|
-
def __init__(self):
|
|
32
|
-
self.logger_json = {}
|
|
33
|
-
self._init()
|
|
34
|
-
|
|
35
|
-
def _init(self):
|
|
36
|
-
INIT_METHOD_NAME = "_init()"
|
|
37
|
-
logger.start(INIT_METHOD_NAME)
|
|
38
|
-
|
|
39
|
-
try:
|
|
40
|
-
with open(LOGGER_CONFIGURATION_JSON, 'r') as file:
|
|
41
|
-
self.logger_json = json.load(file)
|
|
42
|
-
except Exception as e:
|
|
43
|
-
logger.exception("got exception while reading json from file", object={'exception': e})
|
|
44
|
-
logger.end(INIT_METHOD_NAME)
|
|
45
|
-
return
|
|
46
|
-
|
|
47
|
-
logger.end(INIT_METHOD_NAME)
|
|
48
|
-
|
|
49
|
-
def fetch(self, component_id:str, logger_output: LoggerOutputEnum, severity_level:int):
|
|
50
|
-
|
|
51
|
-
severity_level = max(severity_level, LOGGER_MINIMUM_SEVERITY)
|
|
52
|
-
|
|
53
|
-
FETCH_METHOD_NAME = "fetch()"
|
|
54
|
-
logger.start(FETCH_METHOD_NAME, object={'component_id': component_id, 'logger_output': str(logger_output), 'severity_level': severity_level})
|
|
55
|
-
|
|
56
|
-
if component_id in self.logger_json:
|
|
57
|
-
output_info = self.logger_json[component_id]
|
|
58
|
-
if logger_output in output_info:
|
|
59
|
-
result = severity_level >= output_info[logger_output]
|
|
60
|
-
logger.end(FETCH_METHOD_NAME, object={'result': result})
|
|
61
|
-
return result
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
result = False
|
|
65
|
-
logger.end(FETCH_METHOD_NAME, object={'result': result})
|
|
66
|
-
return result
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
from dotenv import load_dotenv
|
|
3
|
-
load_dotenv()
|
|
4
|
-
import os
|
|
5
|
-
import sys
|
|
6
|
-
sys.path.append(os.getcwd())
|
|
7
|
-
|
|
8
|
-
import python_sdk_local.sdk.src.debug_mode as debug_mode
|
|
9
|
-
from python_sdk_local.sdk.src.LoggerOutputEnum import LoggerOutputEnum
|
|
10
|
-
from logger_local.LoggerComponentEnum import LoggerComponentEnum
|
|
11
|
-
from logger_local.Logger import Logger
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
PYTHON_SDK_LOCAL_COMPONENT_ID = 184
|
|
15
|
-
PYTHON_SDK_LOCAL_COMPONENT_NAME = 'python_sdk_local/tests/debug_mode_test.py'
|
|
16
|
-
|
|
17
|
-
obj = {
|
|
18
|
-
'component_id': PYTHON_SDK_LOCAL_COMPONENT_ID,
|
|
19
|
-
'component_name': PYTHON_SDK_LOCAL_COMPONENT_NAME,
|
|
20
|
-
'component_category': LoggerComponentEnum.ComponentCategory.Code.value,
|
|
21
|
-
'developer_email': 'yoav.e@circ.zone'
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
logger = Logger.create_logger(object=obj)
|
|
25
|
-
|
|
26
|
-
with open('python_sdk_local/.logger.json.example1', 'r') as file:
|
|
27
|
-
EXAMPLE_DATA_1 = json.load(file)
|
|
28
|
-
|
|
29
|
-
with open('python_sdk_local/.logger.json.example2', 'r') as file:
|
|
30
|
-
EXAMPLE_DATA_2 = json.load(file)
|
|
31
|
-
|
|
32
|
-
def add_debug_file(data):
|
|
33
|
-
|
|
34
|
-
ADD_DEBUG_FILE_FUNCTION_NAME = 'add_debug_file()'
|
|
35
|
-
logger.start(ADD_DEBUG_FILE_FUNCTION_NAME)
|
|
36
|
-
|
|
37
|
-
with open(debug_mode.LOGGER_CONFIGURATION_JSON, 'w') as file:
|
|
38
|
-
json.dump(data, file)
|
|
39
|
-
|
|
40
|
-
logger.end(ADD_DEBUG_FILE_FUNCTION_NAME)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def remove_debug_file():
|
|
44
|
-
REMOVE_DEBUG_FILE_FUNCTION_NAME = 'remove_debug_file()'
|
|
45
|
-
logger.start(REMOVE_DEBUG_FILE_FUNCTION_NAME)
|
|
46
|
-
|
|
47
|
-
os.remove(debug_mode.LOGGER_CONFIGURATION_JSON)
|
|
48
|
-
|
|
49
|
-
logger.end(REMOVE_DEBUG_FILE_FUNCTION_NAME)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def test_debug_mode_init():
|
|
53
|
-
|
|
54
|
-
#set env variable
|
|
55
|
-
TEST_DEBUG_MODE_INIT_FUNCTION_NAME = 'test_debug_mode_init()'
|
|
56
|
-
logger.start(TEST_DEBUG_MODE_INIT_FUNCTION_NAME)
|
|
57
|
-
|
|
58
|
-
add_debug_file(EXAMPLE_DATA_1)
|
|
59
|
-
|
|
60
|
-
debug = debug_mode.DebugMode()
|
|
61
|
-
|
|
62
|
-
remove_debug_file()
|
|
63
|
-
|
|
64
|
-
result = debug.logger_json == EXAMPLE_DATA_1
|
|
65
|
-
logger.end(TEST_DEBUG_MODE_INIT_FUNCTION_NAME, object={'result': result})
|
|
66
|
-
|
|
67
|
-
assert result
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
def test_fetch_debug_info_1():
|
|
71
|
-
|
|
72
|
-
TEST_FETCH_DEBUG_INFO_1_FUNCTION_NAME = 'test_fetch_debug_info_1()'
|
|
73
|
-
logger.start(TEST_FETCH_DEBUG_INFO_1_FUNCTION_NAME)
|
|
74
|
-
|
|
75
|
-
add_debug_file(EXAMPLE_DATA_1)
|
|
76
|
-
|
|
77
|
-
debug = debug_mode.DebugMode()
|
|
78
|
-
|
|
79
|
-
remove_debug_file()
|
|
80
|
-
|
|
81
|
-
result = debug.fetch('1', LoggerOutputEnum.Console.value, 501) == True
|
|
82
|
-
logger.end(TEST_FETCH_DEBUG_INFO_1_FUNCTION_NAME,
|
|
83
|
-
object={'result': result})
|
|
84
|
-
|
|
85
|
-
assert result
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
def test_fetch_debug_mode_2():
|
|
89
|
-
|
|
90
|
-
TEST_FETCH_DEBUG_MODE_2_FUNCTION_NAME = 'test_fetch_debug_mode_2()'
|
|
91
|
-
logger.start(TEST_FETCH_DEBUG_MODE_2_FUNCTION_NAME)
|
|
92
|
-
|
|
93
|
-
add_debug_file(EXAMPLE_DATA_2)
|
|
94
|
-
|
|
95
|
-
debug = debug_mode.DebugMode()
|
|
96
|
-
|
|
97
|
-
remove_debug_file()
|
|
98
|
-
|
|
99
|
-
result1 = debug.fetch('2', LoggerOutputEnum.Logzio.value, 502) == True
|
|
100
|
-
result2 = debug.fetch('2', LoggerOutputEnum.MySQLDatabase.value, 503) == True
|
|
101
|
-
result3 = debug.fetch('2', LoggerOutputEnum.Console.value, 499) == False
|
|
102
|
-
|
|
103
|
-
result = result1 and result2 and result3
|
|
104
|
-
logger.end(TEST_FETCH_DEBUG_MODE_2_FUNCTION_NAME,
|
|
105
|
-
object={'result': result})
|
|
106
|
-
assert result
|
|
107
|
-
|
|
108
|
-
def test_minimum_sevirity():
|
|
109
|
-
|
|
110
|
-
TEST_MINIMUM_SEVIRITY_FUNCTION_NAME = 'test_minimum_sevirity()'
|
|
111
|
-
logger.start(TEST_MINIMUM_SEVIRITY_FUNCTION_NAME)
|
|
112
|
-
|
|
113
|
-
add_debug_file(EXAMPLE_DATA_2)
|
|
114
|
-
|
|
115
|
-
debug = debug_mode.DebugMode()
|
|
116
|
-
print(debug.logger_json)
|
|
117
|
-
|
|
118
|
-
remove_debug_file()
|
|
119
|
-
|
|
120
|
-
result1 = debug.fetch('2', LoggerOutputEnum.Logzio.value, 501) == False
|
|
121
|
-
result2 = debug.fetch('2', LoggerOutputEnum.Logzio.value, 502) == True
|
|
122
|
-
|
|
123
|
-
debug_mode.LOGGER_MINIMUM_SEVERITY = 0
|
|
124
|
-
|
|
125
|
-
result = result1 and result2
|
|
126
|
-
logger.end(TEST_MINIMUM_SEVIRITY_FUNCTION_NAME, object={'result': result})
|
|
127
|
-
assert result
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
test_minimum_sevirity()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python-sdk-local-0.0.24 → python-sdk-local-0.0.26}/python_sdk_local.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|