wingify-fme-python-sdk 1.70.0__py3-none-any.whl

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.
Files changed (186) hide show
  1. tests/data/__init__.py +13 -0
  2. tests/data/dummy_test_data_reader.py +63 -0
  3. tests/data/user_storage.py +48 -0
  4. tests/e2e/__init__.py +13 -0
  5. tests/e2e/custom_bucketing_test.py +514 -0
  6. tests/e2e/force_users_test.py +368 -0
  7. tests/e2e/get_flag_test.py +195 -0
  8. tests/unit/__init__.py +13 -0
  9. tests/unit/packages/__init__.py +13 -0
  10. tests/unit/packages/decision_maker/__init__.py +13 -0
  11. tests/unit/packages/decision_maker/decision_maker_test.py +83 -0
  12. tests/unit/packages/segmentation_evaluator/__init__.py +13 -0
  13. tests/unit/packages/segmentation_evaluator/segmentation_evaluator_test.py +284 -0
  14. tests/unit/packages/segmentation_evaluator/segmentation_manager_test.py +215 -0
  15. tests/unit/packages/segmentation_evaluator/web_testing_segment_test.py +216 -0
  16. tests/unit/services/__init__.py +0 -0
  17. tests/unit/services/hooks_manager_test.py +80 -0
  18. tests/unit/services/internal_events_sampling_service_test.py +160 -0
  19. tests/unit/settings/__init__.py +13 -0
  20. tests/unit/settings/settings_schema_validation_test.py +67 -0
  21. tests/unit/utils/__init__.py +0 -0
  22. tests/unit/utils/campaign_util_test.py +248 -0
  23. tests/unit/utils/decision_util_force_users_test.py +790 -0
  24. tests/unit/utils/log_message_test.py +65 -0
  25. tests/unit/vwo_wingify_test.py +175 -0
  26. tests/unit/wingify_client_validation_test.py +72 -0
  27. vwo/__init__.py +35 -0
  28. vwo/models/__init__.py +13 -0
  29. vwo/models/batch_event_data.py +19 -0
  30. vwo/models/user/__init__.py +13 -0
  31. vwo/models/user/context_vwo_model.py +21 -0
  32. vwo/models/user/get_flag.py +19 -0
  33. vwo/models/vwo_options_model.py +21 -0
  34. vwo/packages/__init__.py +13 -0
  35. vwo/packages/logger/__init__.py +13 -0
  36. vwo/packages/logger/enums/__init__.py +13 -0
  37. vwo/packages/logger/enums/log_level_enum.py +19 -0
  38. vwo/packages/storage/__init__.py +13 -0
  39. vwo/packages/storage/connector.py +19 -0
  40. vwo/vwo.py +58 -0
  41. vwo/vwo_builder.py +21 -0
  42. vwo/vwo_client.py +22 -0
  43. wingify/__init__.py +36 -0
  44. wingify/api/__init__.py +13 -0
  45. wingify/api/get_flag_api.py +727 -0
  46. wingify/api/set_attribute_api.py +60 -0
  47. wingify/api/track_api.py +99 -0
  48. wingify/constants/Constants.py +94 -0
  49. wingify/constants/__init__.py +13 -0
  50. wingify/constants/sampled_debug_error_template_keys.py +34 -0
  51. wingify/decorators/__init__.py +13 -0
  52. wingify/decorators/storage_decorator.py +92 -0
  53. wingify/enums/__init__.py +13 -0
  54. wingify/enums/api_enum.py +26 -0
  55. wingify/enums/campaign_type_enum.py +22 -0
  56. wingify/enums/debug_category_enum.py +24 -0
  57. wingify/enums/event_enum.py +26 -0
  58. wingify/enums/headers_enum.py +21 -0
  59. wingify/enums/hooks_enum.py +24 -0
  60. wingify/enums/status_enum.py +21 -0
  61. wingify/enums/storage_enum.py +25 -0
  62. wingify/enums/url_enum.py +29 -0
  63. wingify/models/Alias.py +60 -0
  64. wingify/models/AliasSetResponse.py +43 -0
  65. wingify/models/__init__.py +13 -0
  66. wingify/models/batch_event_data.py +68 -0
  67. wingify/models/campaign/__init__.py +13 -0
  68. wingify/models/campaign/campaign_model.py +140 -0
  69. wingify/models/campaign/feature_model.py +95 -0
  70. wingify/models/campaign/holdout_model.py +94 -0
  71. wingify/models/campaign/impact_campaign_model.py +60 -0
  72. wingify/models/campaign/metric_model.py +42 -0
  73. wingify/models/campaign/rule_model.py +42 -0
  74. wingify/models/campaign/variable_model.py +44 -0
  75. wingify/models/campaign/variation_model.py +109 -0
  76. wingify/models/gateway_service_model.py +48 -0
  77. wingify/models/schemas/__init__.py +13 -0
  78. wingify/models/schemas/campaign_group_schema.py +19 -0
  79. wingify/models/schemas/campaign_metric_schema.py +26 -0
  80. wingify/models/schemas/campaign_schema.py +37 -0
  81. wingify/models/schemas/campaign_variation_schema.py +34 -0
  82. wingify/models/schemas/empty_object_schema.py +15 -0
  83. wingify/models/schemas/feature_schema.py +38 -0
  84. wingify/models/schemas/group_schema.py +37 -0
  85. wingify/models/schemas/holdout_schema.py +29 -0
  86. wingify/models/schemas/rule_schema.py +24 -0
  87. wingify/models/schemas/settings_schema.py +47 -0
  88. wingify/models/schemas/variable_schema.py +24 -0
  89. wingify/models/settings/__init__.py +13 -0
  90. wingify/models/settings/internal_event_sampling_settings_model.py +53 -0
  91. wingify/models/settings/settings_model.py +127 -0
  92. wingify/models/storage/__init__.py +13 -0
  93. wingify/models/storage/storage_model.py +84 -0
  94. wingify/models/user/__init__.py +13 -0
  95. wingify/models/user/context_model.py +113 -0
  96. wingify/models/user/context_vwo_model.py +34 -0
  97. wingify/models/user/get_flag.py +47 -0
  98. wingify/models/vwo_options_model.py +21 -0
  99. wingify/models/wingify_options_model.py +129 -0
  100. wingify/packages/__init__.py +13 -0
  101. wingify/packages/decision_maker/__init__.py +13 -0
  102. wingify/packages/decision_maker/decision_maker.py +89 -0
  103. wingify/packages/logger/__init__.py +13 -0
  104. wingify/packages/logger/core/__init__.py +13 -0
  105. wingify/packages/logger/core/log_manager.py +123 -0
  106. wingify/packages/logger/core/log_transport_manager.py +57 -0
  107. wingify/packages/logger/enums/__init__.py +13 -0
  108. wingify/packages/logger/enums/log_level_enum.py +24 -0
  109. wingify/packages/logger/enums/log_level_number_enum.py +21 -0
  110. wingify/packages/logger/log_message_builder.py +70 -0
  111. wingify/packages/logger/logger.py +38 -0
  112. wingify/packages/logger/transports/__init__.py +13 -0
  113. wingify/packages/logger/transports/console_transport.py +43 -0
  114. wingify/packages/network_layer/__init__.py +13 -0
  115. wingify/packages/network_layer/client/__init__.py +13 -0
  116. wingify/packages/network_layer/client/network_client.py +167 -0
  117. wingify/packages/network_layer/handlers/__init__.py +13 -0
  118. wingify/packages/network_layer/handlers/request_handler.py +40 -0
  119. wingify/packages/network_layer/manager/__init__.py +13 -0
  120. wingify/packages/network_layer/manager/network_manager.py +79 -0
  121. wingify/packages/network_layer/models/__init__.py +13 -0
  122. wingify/packages/network_layer/models/global_request_model.py +70 -0
  123. wingify/packages/network_layer/models/request_model.py +133 -0
  124. wingify/packages/network_layer/models/response_model.py +55 -0
  125. wingify/packages/segmentation_evaluator/__init__.py +13 -0
  126. wingify/packages/segmentation_evaluator/core/__init__.py +13 -0
  127. wingify/packages/segmentation_evaluator/core/segmentation_manager.py +140 -0
  128. wingify/packages/segmentation_evaluator/enums/__init__.py +13 -0
  129. wingify/packages/segmentation_evaluator/enums/segment_operand_regex_enum.py +31 -0
  130. wingify/packages/segmentation_evaluator/enums/segment_operand_value_enum.py +29 -0
  131. wingify/packages/segmentation_evaluator/enums/segment_operator_value_enum.py +37 -0
  132. wingify/packages/segmentation_evaluator/evaluators/__init__.py +13 -0
  133. wingify/packages/segmentation_evaluator/evaluators/segment_evaluator.py +237 -0
  134. wingify/packages/segmentation_evaluator/evaluators/segment_operand_evaluator.py +518 -0
  135. wingify/packages/segmentation_evaluator/utils/__init__.py +13 -0
  136. wingify/packages/segmentation_evaluator/utils/segment_util.py +33 -0
  137. wingify/packages/segmentation_evaluator/utils/web_testing_segment_util.py +295 -0
  138. wingify/packages/storage/__init__.py +13 -0
  139. wingify/packages/storage/connector.py +25 -0
  140. wingify/packages/storage/storage.py +39 -0
  141. wingify/resources/__init__.py +13 -0
  142. wingify/resources/debug-messages.json +21 -0
  143. wingify/resources/error-messages.json +62 -0
  144. wingify/resources/info-message.json +47 -0
  145. wingify/resources/trace-messages.json +1 -0
  146. wingify/resources/warn-messages.json +1 -0
  147. wingify/services/__init__.py +13 -0
  148. wingify/services/batch_event_queue.py +140 -0
  149. wingify/services/campaign_decision_service.py +268 -0
  150. wingify/services/hooks_manager.py +65 -0
  151. wingify/services/internal_events_sampling_service.py +62 -0
  152. wingify/services/settings_manager.py +293 -0
  153. wingify/services/storage_service.py +58 -0
  154. wingify/services/url_service.py +51 -0
  155. wingify/utils/__init__.py +13 -0
  156. wingify/utils/aliasing_util.py +108 -0
  157. wingify/utils/brand_context.py +26 -0
  158. wingify/utils/brand_util.py +37 -0
  159. wingify/utils/campaign_util.py +592 -0
  160. wingify/utils/data_type_util.py +125 -0
  161. wingify/utils/debugger_service_util.py +58 -0
  162. wingify/utils/decision_util.py +589 -0
  163. wingify/utils/event_util.py +85 -0
  164. wingify/utils/function_util.py +188 -0
  165. wingify/utils/gateway_service_util.py +179 -0
  166. wingify/utils/holdout_util.py +264 -0
  167. wingify/utils/impression_util.py +151 -0
  168. wingify/utils/internal_events_sampling_util.py +106 -0
  169. wingify/utils/log_message_util.py +95 -0
  170. wingify/utils/meg_util.py +561 -0
  171. wingify/utils/model_utils.py +136 -0
  172. wingify/utils/network_util.py +706 -0
  173. wingify/utils/rule_evaluation_util.py +102 -0
  174. wingify/utils/settings_util.py +39 -0
  175. wingify/utils/usage_stats_util.py +116 -0
  176. wingify/utils/uuid_util.py +81 -0
  177. wingify/vwo_client.py +21 -0
  178. wingify/wingify.py +159 -0
  179. wingify/wingify_builder.py +282 -0
  180. wingify/wingify_client.py +520 -0
  181. wingify_fme_python_sdk-1.70.0.dist-info/METADATA +1415 -0
  182. wingify_fme_python_sdk-1.70.0.dist-info/RECORD +186 -0
  183. wingify_fme_python_sdk-1.70.0.dist-info/WHEEL +5 -0
  184. wingify_fme_python_sdk-1.70.0.dist-info/licenses/LICENSE +202 -0
  185. wingify_fme_python_sdk-1.70.0.dist-info/licenses/NOTICE +18 -0
  186. wingify_fme_python_sdk-1.70.0.dist-info/top_level.txt +3 -0
@@ -0,0 +1,89 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ from murmurhash import mrmr
17
+ import math
18
+
19
+ SEED_VALUE = 1 # Seed value for the hash function
20
+
21
+
22
+ class DecisionMaker:
23
+
24
+ def __init__(self):
25
+ self.seed_value = SEED_VALUE
26
+
27
+ def generate_bucket_value(
28
+ self, hash_value: int, max_value: int, multiplier: int = 1
29
+ ) -> int:
30
+ """
31
+ Generates a bucket value based on the hash value, maximum value, and an optional multiplier.
32
+
33
+ :param hash_value: The hash value used for calculation.
34
+ :param max_value: The maximum value for bucket scaling.
35
+ :param multiplier: Optional multiplier to adjust the value.
36
+ :return: The calculated bucket value.
37
+ """
38
+ # Calculate the ratio based on the hash value
39
+ ratio = hash_value / (2**32)
40
+ # Calculate the multiplied value
41
+ multiplied_value = (max_value * ratio + 1) * multiplier
42
+ # Round down to get the final value
43
+ value = math.floor(multiplied_value)
44
+
45
+ return value
46
+
47
+ def get_bucket_value_for_user(self, hash_key: str, max_value: int = 100) -> int:
48
+ """
49
+ Gets the bucket value for a user based on the hash key and maximum value.
50
+
51
+ :param hash_key: The hash key for the user.
52
+ :param max_value: The maximum value for bucket scaling.
53
+ :return: The calculated bucket value for the user.
54
+ """
55
+ hash_value = self.generate_hash_value(hash_key) # Calculate the hash value
56
+ bucket_value = self.generate_bucket_value(
57
+ hash_value, max_value
58
+ ) # Calculate the bucket value
59
+
60
+ return bucket_value # Return the calculated bucket value
61
+
62
+ def calculate_bucket_value(
63
+ self, string: str, multiplier: int = 1, max_value: int = 10000
64
+ ) -> int:
65
+ """
66
+ Calculates the bucket value for a given string with optional multiplier and maximum value.
67
+
68
+ :param string: The input string to calculate the bucket value for.
69
+ :param multiplier: Optional multiplier to adjust the value.
70
+ :param max_value: The maximum value for bucket scaling.
71
+ :return: The calculated bucket value.
72
+ """
73
+ hash_value = self.generate_hash_value(
74
+ string
75
+ ) # Generate the hash value for the input string
76
+ return self.generate_bucket_value(
77
+ hash_value, max_value, multiplier
78
+ ) # Generate and return the bucket value
79
+
80
+ def generate_hash_value(self, hash_key: str) -> int:
81
+ """
82
+ Generates the hash value for a given hash key using MurmurHash v3.
83
+
84
+ :param hash_key: The hash key for which the hash value is generated.
85
+ :return: The generated hash value.
86
+ """
87
+ # Ensure the hash is treated as an unsigned 32-bit integer
88
+ hash_value = mrmr.hash(hash_key, self.seed_value)
89
+ return hash_value & 0xFFFFFFFF # Convert to unsigned 32-bit integer
@@ -0,0 +1,13 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
@@ -0,0 +1,13 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
@@ -0,0 +1,123 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ import uuid
17
+ from ..enums.log_level_enum import LogLevelEnum
18
+ from .log_transport_manager import LogTransportManager
19
+ from ..transports.console_transport import ConsoleTransport
20
+ from typing import List
21
+ from ..logger import Logger
22
+ import datetime
23
+ from typing import Dict, Any, Union
24
+ from ....enums.event_enum import EventEnum
25
+ from ....constants.Constants import Constants
26
+ from ....enums.debug_category_enum import DebugCategoryEnum
27
+ from ....utils.log_message_util import error_messages
28
+ from ....utils.debugger_service_util import send_debug_event_to_vwo
29
+ from ....utils.brand_context import get_is_via_vwo
30
+ from ....utils.brand_util import get_brand, get_log_prefix
31
+
32
+
33
+ class LogManager(Logger):
34
+ _instance = None
35
+ stored_messages = (
36
+ set()
37
+ ) # Set to store already logged messages for duplicate prevention
38
+
39
+ def __new__(cls, *args, **kwargs):
40
+ if cls._instance is None:
41
+ cls._instance = super().__new__(cls)
42
+ return cls._instance
43
+
44
+ def __init__(self, config: Dict[str, Any] = None):
45
+ if "initialized" in self.__dict__:
46
+ return
47
+ self.__dict__["initialized"] = True
48
+ self.config = config or {}
49
+ is_via_vwo = get_is_via_vwo()
50
+ self.name = self.config.get("name", f"{get_brand(is_via_vwo)} Logger")
51
+ self.request_id = self.config.get("requestId", "unique-request-id")
52
+ self.level = self.config.get("level", LogLevelEnum.ERROR)
53
+ self.prefix = self.config.get("prefix", get_log_prefix(is_via_vwo))
54
+ self.date_time_format = self.config.get(
55
+ "dateTimeFormat", lambda: datetime.datetime.utcnow().isoformat()
56
+ )
57
+ self.is_ansi_color_enabled = self.config.get("isAnsiColorEnabled", False)
58
+
59
+ self.transport_manager = LogTransportManager(self.config)
60
+ self.handle_transports()
61
+
62
+ @staticmethod
63
+ def get_instance() -> "LogManager":
64
+ return LogManager()
65
+
66
+ def handle_transports(self) -> None:
67
+ transports = self.config.get("transports", [])
68
+
69
+ if transports:
70
+ self.add_transports(transports)
71
+ else:
72
+ transport = self.config.get("transport")
73
+ if transport:
74
+ self.add_transport(transport)
75
+ else:
76
+ self.add_transport(
77
+ ConsoleTransport(
78
+ {
79
+ "level": self.level,
80
+ "isAnsiColorEnabled": self.is_ansi_color_enabled,
81
+ }
82
+ )
83
+ )
84
+
85
+ def add_transport(self, transport: Union[Logger, Dict[str, Any]]) -> None:
86
+ if isinstance(transport, Dict):
87
+ self.transport_manager.add_transport(ConsoleTransport(transport))
88
+ else:
89
+ self.transport_manager.add_transport(transport)
90
+
91
+ def add_transports(self, transports: List[Union[Logger, Dict[str, Any]]]) -> None:
92
+ for transport in transports:
93
+ self.add_transport(transport)
94
+
95
+ def trace(self, message: str) -> None:
96
+ self.transport_manager.log(LogLevelEnum.TRACE, message)
97
+
98
+ def debug(self, message: str) -> None:
99
+ self.transport_manager.log(LogLevelEnum.DEBUG, message)
100
+
101
+ def info(self, message: str) -> None:
102
+ self.transport_manager.log(LogLevelEnum.INFO, message)
103
+
104
+ def warn(self, message: str) -> None:
105
+ self.transport_manager.log(LogLevelEnum.WARN, message)
106
+
107
+ def error(self, message: str) -> None:
108
+ self.transport_manager.log(LogLevelEnum.ERROR, message)
109
+
110
+ def error_log(self, template: str, data: Dict[str, Any] = {}, debug_data: Dict[str, Any] = {}, should_send_log_to_vwo: bool = True) -> None:
111
+ try:
112
+ message = error_messages.get(template).format(**data)
113
+ self.error(message)
114
+ if (should_send_log_to_vwo):
115
+ debug_event_props = {}
116
+ debug_event_props.update(debug_data)
117
+ debug_event_props["msg_t"] = template
118
+ debug_event_props["msg"] = message
119
+ debug_event_props["lt"] = LogLevelEnum.ERROR.value
120
+ debug_event_props["cg"] = DebugCategoryEnum.ERROR.value
121
+ send_debug_event_to_vwo(debug_event_props)
122
+ except Exception as e:
123
+ print(f"[{get_log_prefix(get_is_via_vwo())}]: Error logging message: {e}")
@@ -0,0 +1,57 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ from ..enums.log_level_number_enum import LogLevelNumberEnum
17
+ from ..enums.log_level_enum import LogLevelEnum
18
+ from ..logger import Logger
19
+ from ..log_message_builder import LogMessageBuilder
20
+ from typing import Any, Dict
21
+
22
+
23
+ class LogTransportManager:
24
+ def __init__(self, config: Dict[str, Any]):
25
+ self.transports = []
26
+ self.config = config
27
+
28
+ def add_transport(self, transport: Logger) -> None:
29
+ self.transports.append(transport)
30
+
31
+ def should_log(self, transport_level: str, config_level: str) -> bool:
32
+ target_level = getattr(
33
+ LogLevelNumberEnum, transport_level.upper(), LogLevelNumberEnum.ERROR
34
+ )
35
+ desired_level = getattr(
36
+ LogLevelNumberEnum,
37
+ config_level.upper(),
38
+ str(self.config.get("level", LogLevelNumberEnum.ERROR)).upper(),
39
+ )
40
+ return target_level >= desired_level
41
+
42
+ def log(self, level: str, message: str) -> None:
43
+ for transport in self.transports:
44
+ if self.should_log(level, transport.level):
45
+ log_message_builder = LogMessageBuilder(self.config, transport.config)
46
+ formatted_message = log_message_builder.format_message(level, message)
47
+ # Check if transport has a custom log method
48
+ if hasattr(transport, "log") and callable(transport.log):
49
+ # Use custom log handler if available
50
+ # if the type if level is LogLevelEnum, then use the name of the level
51
+ if isinstance(level, LogLevelEnum):
52
+ level = level.name
53
+ transport.log(level, message)
54
+ else:
55
+ # Otherwise, use the default log method
56
+ if hasattr(transport, level):
57
+ getattr(transport, level)(formatted_message)
@@ -0,0 +1,13 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
@@ -0,0 +1,24 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ from enum import Enum
17
+
18
+
19
+ class LogLevelEnum(str, Enum):
20
+ TRACE = "trace"
21
+ DEBUG = "debug"
22
+ INFO = "info"
23
+ WARN = "warn"
24
+ ERROR = "error"
@@ -0,0 +1,21 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ class LogLevelNumberEnum:
17
+ TRACE = 0
18
+ DEBUG = 1
19
+ INFO = 2
20
+ WARN = 3
21
+ ERROR = 4
@@ -0,0 +1,70 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ from .enums.log_level_enum import LogLevelEnum
17
+ from typing import Any, Dict
18
+ import datetime
19
+
20
+ from ...constants.Constants import Constants
21
+ from ...utils.brand_context import get_is_via_vwo
22
+ from ...utils.brand_util import get_log_prefix
23
+
24
+
25
+ class LogMessageBuilder:
26
+ ANSI_COLOR_ENUM = {
27
+ "BOLD": "\033[1m",
28
+ "CYAN": "\033[36m",
29
+ "GREEN": "\033[32m",
30
+ "LIGHTBLUE": "\033[94m",
31
+ "RED": "\033[31m",
32
+ "RESET": "\033[0m",
33
+ "WHITE": "\033[97m", # Bright white
34
+ "YELLOW": "\033[33m",
35
+ }
36
+
37
+ def __init__(self, logger_config: Dict[str, Any], transport_config: Dict[str, Any]):
38
+ self.logger_config = logger_config
39
+ self.transport_config = transport_config
40
+ self.prefix = self.transport_config.get(
41
+ "prefix", self.logger_config.get("prefix", get_log_prefix(get_is_via_vwo()))
42
+ )
43
+ self.date_time_format = self.transport_config.get(
44
+ "dateTimeFormat",
45
+ self.logger_config.get("dateTimeFormat", self.default_date_time_format),
46
+ )
47
+ # Determine if ANSI color is enabled
48
+ self.is_ansi_color_enabled = self.logger_config.get("isAnsiColorEnabled", False)
49
+
50
+ def format_message(self, level: str, message: str) -> str:
51
+ color_code = self.get_color_code(level) if self.is_ansi_color_enabled else ""
52
+ reset_code = "\033[0m" if self.is_ansi_color_enabled else ""
53
+ timestamp = self.get_formatted_date_time()
54
+ return f"{color_code}[{level.upper()}] {self.prefix} {reset_code}{timestamp} {message}"
55
+
56
+ def get_color_code(self, level: str) -> str:
57
+ color_map = {
58
+ LogLevelEnum.TRACE: "\033[37m", # White
59
+ LogLevelEnum.DEBUG: "\033[94m", # Light Blue
60
+ LogLevelEnum.INFO: "\033[36m", # Cyan
61
+ LogLevelEnum.WARN: "\033[33m", # Yellow
62
+ LogLevelEnum.ERROR: "\033[31m", # Red
63
+ }
64
+ return color_map.get(level, "\033[0m") # Default to reset if level not found
65
+
66
+ def get_formatted_date_time(self) -> str:
67
+ return self.date_time_format()
68
+
69
+ def default_date_time_format(self) -> str:
70
+ return datetime.datetime.utcnow().isoformat()
@@ -0,0 +1,38 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ from abc import ABC, abstractmethod
17
+
18
+
19
+ class Logger(ABC):
20
+ @abstractmethod
21
+ def trace(self, message: str) -> None:
22
+ pass
23
+
24
+ @abstractmethod
25
+ def debug(self, message: str) -> None:
26
+ pass
27
+
28
+ @abstractmethod
29
+ def info(self, message: str) -> None:
30
+ pass
31
+
32
+ @abstractmethod
33
+ def warn(self, message: str) -> None:
34
+ pass
35
+
36
+ @abstractmethod
37
+ def error(self, message: str) -> None:
38
+ pass
@@ -0,0 +1,13 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
@@ -0,0 +1,43 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ from ..logger import Logger
17
+ from ..enums.log_level_enum import LogLevelEnum
18
+ from typing import Any, Dict
19
+
20
+
21
+ class ConsoleTransport(Logger):
22
+ def __init__(self, config: Dict[str, Any] = None):
23
+ self.config = config or {}
24
+ self.level = self.config.get("level", LogLevelEnum.ERROR)
25
+ self.is_ansi_color_enabled = self.config.get("isAnsiColorEnabled", False)
26
+
27
+ def trace(self, message: str) -> None:
28
+ self.console_log(message)
29
+
30
+ def debug(self, message: str) -> None:
31
+ self.console_log(message)
32
+
33
+ def info(self, message: str) -> None:
34
+ self.console_log(message)
35
+
36
+ def warn(self, message: str) -> None:
37
+ self.console_log(message)
38
+
39
+ def error(self, message: str) -> None:
40
+ self.console_log(message)
41
+
42
+ def console_log(self, message: str) -> None:
43
+ print(message)
@@ -0,0 +1,13 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
@@ -0,0 +1,13 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.