Update log file size calculation method

The code for calculating the size of the log file has been revised. Instead of using os.path.getsize, which simply captures the size of the file on disk, we're now calculating the size of the payload after it has been serialized and encoded, plus an overhead of 100 bytes. This change provides a more accurate measure of the data that will be sent.
This commit is contained in:
DevTekVE
2024-05-28 14:14:22 +02:00
parent 753bcce9a7
commit 52ea16a93a
+4 -4
View File
@@ -583,14 +583,14 @@ def add_log_to_queue(log_path, log_id, is_sunnylink = False):
cloudlog.warning(f"Log file {log_path} is empty.")
return
# Log the current size of the file
current_size = os.path.getsize(log_path)
cloudlog.info(f"Current size of log file {log_path}: {current_size} bytes")
# Initialize variables for encoding
payload = data
is_compressed = False
# Log the current size of the file
current_size = len(json.dumps(payload).encode("utf-8")) + len(log_id.encode("utf-8")) + 100 # Add 100 bytes to account for encoding overhead
cloudlog.info(f"Current size of log file {log_path}: {current_size} bytes")
if is_sunnylink and current_size > MAX_SIZE_BYTES:
# Compress and encode the data if it exceeds the maximum size
compressed_data = gzip.compress(data.encode())