Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ def speech_to_text(self, audio_file):


except TencentCloudSDKException as err:
print(err)
maxkb_logger.error(f":Error: {str(err)}: {traceback.format_exc()}")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code looks mostly correct for logging errors using maxkb_logger. However, there're a few minor improvements you can make to enhance clarity and ensure proper formatting:

  1. Consistent Logging Format: Ensure that both print statements use the same format string to avoid any inconsistencies.

    Update the line with the error printing to match the other log entry formats:

            maxkb_logger.error(f":Error: {str(err)}\n{traceback.format_exc()}")
  2. Logging Level: If this is intended to be the default behavior of catching all exceptions during speech-to-text conversion, it might be more appropriate to use an informational level (logger.info) instead of error if no critical action needs to be taken immediately upon encountering an exception.

  3. Exception Handling Context: The original code seems to be handling only specific exceptions (assuming TencentCloudSDKException). Consider whether additional types of exceptions should also be caught and logged, especially depending on how robust your application needs to be.

Here's the revised code based on these considerations:

@@ -77,4 +77,4 @@ def speech_to_text(self, audio_file):
 
 
         except TencentCloudSDKException as err:
-            maxkb_logger.error(f":Error: {str(err)}")
+            maxkb_logger.exception(f":Error: {str(err)}")

or

@@ -77,4 +77,4 @@ def speech_to_text(self, audio_file):
 
 
         except Exception as err:
             maxkb_logger.error(f":Error: {str(err)}")

This change switches from print() to exception(), which logs the full traceback along with the error message at the ERROR level, providing better context about where the exception originated. Adjust the verbosity further up or down if needed based on your application requirements.

Loading