feat(logging): JSON log config for Uvicorn when LOG_JSON=1 (#11264)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Graham Neubig
2025-10-08 11:26:45 -04:00
committed by GitHub
parent f3c6fd2122
commit 843cc00e79
7 changed files with 123 additions and 39 deletions

View File

@@ -1,7 +1,6 @@
import os
import re
import time
import traceback
import uuid
from enum import Enum
from typing import Any
@@ -46,8 +45,8 @@ def split_bash_commands(commands: str) -> list[str]:
logger.debug(
f'Failed to parse bash commands\n'
f'[input]: {commands}\n'
f'[warning]: {traceback.format_exc()}\n'
f'The original command will be returned as is.'
f'The original command will be returned as is.',
exc_info=True,
)
# If parsing fails, return the original commands
return [commands]
@@ -165,8 +164,8 @@ def escape_bash_special_chars(command: str) -> str:
logger.debug(
f'Failed to parse bash commands for special characters escape\n'
f'[input]: {command}\n'
f'[warning]: {traceback.format_exc()}\n'
f'The original command will be returned as is.'
f'The original command will be returned as is.',
exc_info=True,
)
return command

View File

@@ -6,7 +6,6 @@ way to manage PowerShell processes compared to using temporary script files.
import os
import time
import traceback
from pathlib import Path
from threading import RLock
@@ -155,8 +154,7 @@ class WindowsPowershellSession:
self._initialized = True # Set to True only on successful initialization
logger.info(f'PowerShell runspace created. Initial CWD set to: {self._cwd}')
except Exception as e:
logger.error(f'Failed to create or open PowerShell runspace: {e}')
logger.error(traceback.format_exc())
logger.exception(f'Failed to create or open PowerShell runspace: {e}')
self.close() # Ensure cleanup if init fails partially
raise RuntimeError(f'Failed to initialize PowerShell runspace: {e}')
@@ -177,8 +175,7 @@ class WindowsPowershellSession:
# Optional: Confirm CWD even on success for robustness
# self._confirm_cwd()
except Exception as e:
logger.error(f'Exception setting initial CWD: {e}')
logger.error(traceback.format_exc())
logger.exception(f'Exception setting initial CWD: {e}')
# Attempt to confirm CWD even if setting threw an exception
self._confirm_cwd()
finally:
@@ -945,8 +942,7 @@ class WindowsPowershellSession:
)
except Exception as parse_ex:
logger.error(f'Exception during PowerShell command parsing: {parse_ex}')
logger.error(traceback.format_exc())
logger.exception(f'Exception during PowerShell command parsing: {parse_ex}')
return ErrorObservation(
content=f'ERROR: An exception occurred while parsing the command: {parse_ex}'
)
@@ -1118,10 +1114,9 @@ class WindowsPowershellSession:
with self._job_lock:
self.active_job = None
except AttributeError as e:
logger.error(
logger.exception(
f'Get-Job returned an object without expected properties on BaseObject: {e}'
)
logger.error(traceback.format_exc())
all_errors.append('Get-Job did not return a valid Job object.')
job_start_failed = True
@@ -1131,8 +1126,7 @@ class WindowsPowershellSession:
job_start_failed = True
except Exception as start_ex:
logger.error(f'Exception during job start/retrieval: {start_ex}')
logger.error(traceback.format_exc())
logger.exception(f'Exception during job start/retrieval: {start_ex}')
all_errors.append(f'[Job Start/Get Exception: {start_ex}]')
job_start_failed = True
finally:
@@ -1403,8 +1397,7 @@ class WindowsPowershellSession:
self.runspace.Dispose()
logger.info('PowerShell runspace closed and disposed.')
except Exception as e:
logger.error(f'Error closing/disposing PowerShell runspace: {e}')
logger.error(traceback.format_exc())
logger.exception(f'Error closing/disposing PowerShell runspace: {e}')
self.runspace = None
self._initialized = False