1717import json
1818import os
1919from typing import Dict , Any
20+ from ..enums .event_enum import EventEnum
21+ from ..constants .Constants import Constants
2022
2123# Determine the base directory (the directory containing this script)
2224base_dir = os .path .dirname (__file__ )
2325
26+ # Set to store already logged messages (to avoid duplicates)
27+ stored_messages = set ()
28+
2429def load_json_file (filename : str ) -> Dict [str , str ]:
2530 """
2631 Loads a JSON file and returns its content as a dictionary.
@@ -37,4 +42,33 @@ def load_json_file(filename: str) -> Dict[str, str]:
3742error_messages = load_json_file ('error-messages.json' )
3843info_messages = load_json_file ('info-message.json' )
3944trace_messages = load_json_file ('trace-messages.json' )
40- warn_messages = load_json_file ('warn-messages.json' )
45+ warn_messages = load_json_file ('warn-messages.json' )
46+
47+ def send_log_to_vwo (message : str , message_type : str ) -> None :
48+ """
49+ Sends a log message to VWO.
50+
51+ :param message: The message to send.
52+ :param message_type: The type of message (e.g., ERROR, INFO).
53+ """
54+ from ..utils .network_util import get_events_base_properties , get_messaging_event_payload , send_messaging_event
55+
56+ if os .getenv ('TEST_ENV' ) == 'true' :
57+ return # Skip logging in test environment
58+
59+ # Construct the message to check for duplicates
60+ message_to_send = f"{ message } -{ Constants .SDK_NAME } -{ Constants .SDK_VERSION } "
61+
62+ # Avoid sending duplicate messages
63+ if message_to_send not in stored_messages :
64+ # Add the message to the stored set to prevent duplicates
65+ stored_messages .add (message_to_send )
66+
67+ # Get event properties for the error event
68+ properties = get_events_base_properties (EventEnum .VWO_LOG_EVENT .value )
69+
70+ # Create the payload for the messaging event
71+ payload = get_messaging_event_payload (message_type , message , EventEnum .VWO_LOG_EVENT .value )
72+
73+ # Send the message via HTTP request
74+ send_messaging_event (properties , payload )
0 commit comments