aboutsummaryrefslogtreecommitdiff
path: root/autogpts/autogpt/autogpt/logs/formatters.py
diff options
context:
space:
mode:
Diffstat (limited to 'autogpts/autogpt/autogpt/logs/formatters.py')
-rw-r--r--autogpts/autogpt/autogpt/logs/formatters.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/autogpts/autogpt/autogpt/logs/formatters.py b/autogpts/autogpt/autogpt/logs/formatters.py
index 4930d3c73..a51112573 100644
--- a/autogpts/autogpt/autogpt/logs/formatters.py
+++ b/autogpts/autogpt/autogpt/logs/formatters.py
@@ -1,6 +1,7 @@
import logging
from colorama import Style
+from google.cloud.logging_v2.handlers import CloudLoggingFilter, StructuredLogHandler
from autogpt.core.runner.client_lib.logging import FancyConsoleFormatter
@@ -16,7 +17,7 @@ class AutoGptFormatter(FancyConsoleFormatter):
# Make sure `msg` is a string
if not hasattr(record, "msg"):
record.msg = ""
- elif not type(record.msg) == str:
+ elif not type(record.msg) is str:
record.msg = str(record.msg)
# Strip color from the message to prevent color spoofing
@@ -37,3 +38,16 @@ class AutoGptFormatter(FancyConsoleFormatter):
return remove_color_codes(super().format(record))
else:
return super().format(record)
+
+
+class StructuredLoggingFormatter(StructuredLogHandler, logging.Formatter):
+ def __init__(self):
+ # Set up CloudLoggingFilter to add diagnostic info to the log records
+ self.cloud_logging_filter = CloudLoggingFilter()
+
+ # Init StructuredLogHandler
+ super().__init__()
+
+ def format(self, record: logging.LogRecord) -> str:
+ self.cloud_logging_filter.filter(record)
+ return super().format(record)