fix(agent): Full fix for CLI breakage introduced in cf00c33
parent
3d10637a5d
commit
706bff4778
|
@ -102,6 +102,7 @@ async def run_auto_gpt(
|
||||||
level=log_level,
|
level=log_level,
|
||||||
log_format=log_format,
|
log_format=log_format,
|
||||||
log_file_format=log_file_format,
|
log_file_format=log_file_format,
|
||||||
|
config=config.logging,
|
||||||
tts_config=config.tts_config,
|
tts_config=config.tts_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -384,6 +385,7 @@ async def run_auto_gpt_server(
|
||||||
level=log_level,
|
level=log_level,
|
||||||
log_format=log_format,
|
log_format=log_format,
|
||||||
log_file_format=log_file_format,
|
log_file_format=log_file_format,
|
||||||
|
config=config.logging,
|
||||||
tts_config=config.tts_config,
|
tts_config=config.tts_config,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ from autogpt.core.resource.model_providers.openai import (
|
||||||
OpenAIModelName,
|
OpenAIModelName,
|
||||||
)
|
)
|
||||||
from autogpt.file_storage import FileStorageBackendName
|
from autogpt.file_storage import FileStorageBackendName
|
||||||
|
from autogpt.logs.config import LoggingConfig
|
||||||
from autogpt.plugins.plugins_config import PluginsConfig
|
from autogpt.plugins.plugins_config import PluginsConfig
|
||||||
from autogpt.speech import TTSConfig
|
from autogpt.speech import TTSConfig
|
||||||
|
|
||||||
|
@ -58,6 +59,7 @@ class Config(SystemSettings, arbitrary_types_allowed=True):
|
||||||
)
|
)
|
||||||
|
|
||||||
# TTS configuration
|
# TTS configuration
|
||||||
|
logging: LoggingConfig = LoggingConfig()
|
||||||
tts_config: TTSConfig = TTSConfig()
|
tts_config: TTSConfig = TTSConfig()
|
||||||
|
|
||||||
# File storage
|
# File storage
|
||||||
|
|
|
@ -81,12 +81,14 @@ def configure_logging(
|
||||||
log_format: Optional[LogFormatName | str] = None,
|
log_format: Optional[LogFormatName | str] = None,
|
||||||
log_file_format: Optional[LogFormatName | str] = None,
|
log_file_format: Optional[LogFormatName | str] = None,
|
||||||
plain_console_output: Optional[bool] = None,
|
plain_console_output: Optional[bool] = None,
|
||||||
|
config: Optional[LoggingConfig] = None,
|
||||||
tts_config: Optional[TTSConfig] = None,
|
tts_config: Optional[TTSConfig] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Configure the native logging module, based on the environment config and any
|
"""Configure the native logging module, based on the environment config and any
|
||||||
specified overrides.
|
specified overrides.
|
||||||
|
|
||||||
Arguments override values specified in the environment.
|
Arguments override values specified in the environment.
|
||||||
|
Overrides are also applied to `config`, if passed.
|
||||||
|
|
||||||
Should be usable as `configure_logging(**config.logging.dict())`, where
|
Should be usable as `configure_logging(**config.logging.dict())`, where
|
||||||
`config.logging` is a `LoggingConfig` object.
|
`config.logging` is a `LoggingConfig` object.
|
||||||
|
@ -111,14 +113,16 @@ def configure_logging(
|
||||||
elif not isinstance(log_file_format, LogFormatName):
|
elif not isinstance(log_file_format, LogFormatName):
|
||||||
raise ValueError(f"Unknown log format '{log_format}'")
|
raise ValueError(f"Unknown log format '{log_format}'")
|
||||||
|
|
||||||
config = LoggingConfig.from_env()
|
config = config or LoggingConfig.from_env()
|
||||||
|
|
||||||
# Aggregate arguments + env config
|
# Aggregate env config + arguments
|
||||||
level = logging.DEBUG if debug else level or config.level
|
config.level = logging.DEBUG if debug else level or config.level
|
||||||
log_dir = log_dir or config.log_dir
|
config.log_dir = log_dir or config.log_dir
|
||||||
log_format = log_format or (LogFormatName.DEBUG if debug else config.log_format)
|
config.log_format = log_format or (
|
||||||
log_file_format = log_file_format or log_format or config.log_file_format
|
LogFormatName.DEBUG if debug else config.log_format
|
||||||
plain_console_output = (
|
)
|
||||||
|
config.log_file_format = log_file_format or log_format or config.log_file_format
|
||||||
|
config.plain_console_output = (
|
||||||
plain_console_output
|
plain_console_output
|
||||||
if plain_console_output is not None
|
if plain_console_output is not None
|
||||||
else config.plain_console_output
|
else config.plain_console_output
|
||||||
|
@ -127,17 +131,17 @@ def configure_logging(
|
||||||
# Structured logging is used for cloud environments,
|
# Structured logging is used for cloud environments,
|
||||||
# where logging to a file makes no sense.
|
# where logging to a file makes no sense.
|
||||||
if log_format == LogFormatName.STRUCTURED:
|
if log_format == LogFormatName.STRUCTURED:
|
||||||
plain_console_output = True
|
config.plain_console_output = True
|
||||||
log_file_format = None
|
config.log_file_format = None
|
||||||
|
|
||||||
# create log directory if it doesn't exist
|
# create log directory if it doesn't exist
|
||||||
if not log_dir.exists():
|
if not config.log_dir.exists():
|
||||||
log_dir.mkdir()
|
config.log_dir.mkdir()
|
||||||
|
|
||||||
log_handlers: list[logging.Handler] = []
|
log_handlers: list[logging.Handler] = []
|
||||||
|
|
||||||
if log_format in (LogFormatName.DEBUG, LogFormatName.SIMPLE):
|
if config.log_format in (LogFormatName.DEBUG, LogFormatName.SIMPLE):
|
||||||
console_format_template = TEXT_LOG_FORMAT_MAP[log_format]
|
console_format_template = TEXT_LOG_FORMAT_MAP[config.log_format]
|
||||||
console_formatter = AutoGptFormatter(console_format_template)
|
console_formatter = AutoGptFormatter(console_format_template)
|
||||||
else:
|
else:
|
||||||
console_formatter = StructuredLoggingFormatter()
|
console_formatter = StructuredLoggingFormatter()
|
||||||
|
@ -145,7 +149,7 @@ def configure_logging(
|
||||||
|
|
||||||
# Console output handlers
|
# Console output handlers
|
||||||
stdout = logging.StreamHandler(stream=sys.stdout)
|
stdout = logging.StreamHandler(stream=sys.stdout)
|
||||||
stdout.setLevel(level)
|
stdout.setLevel(config.level)
|
||||||
stdout.addFilter(BelowLevelFilter(logging.WARNING))
|
stdout.addFilter(BelowLevelFilter(logging.WARNING))
|
||||||
stdout.setFormatter(console_formatter)
|
stdout.setFormatter(console_formatter)
|
||||||
stderr = logging.StreamHandler()
|
stderr = logging.StreamHandler()
|
||||||
|
@ -162,7 +166,7 @@ def configure_logging(
|
||||||
user_friendly_output_logger = logging.getLogger(USER_FRIENDLY_OUTPUT_LOGGER)
|
user_friendly_output_logger = logging.getLogger(USER_FRIENDLY_OUTPUT_LOGGER)
|
||||||
user_friendly_output_logger.setLevel(logging.INFO)
|
user_friendly_output_logger.setLevel(logging.INFO)
|
||||||
user_friendly_output_logger.addHandler(
|
user_friendly_output_logger.addHandler(
|
||||||
typing_console_handler if not plain_console_output else stdout
|
typing_console_handler if not config.plain_console_output else stdout
|
||||||
)
|
)
|
||||||
if tts_config:
|
if tts_config:
|
||||||
user_friendly_output_logger.addHandler(TTSHandler(tts_config))
|
user_friendly_output_logger.addHandler(TTSHandler(tts_config))
|
||||||
|
@ -170,22 +174,26 @@ def configure_logging(
|
||||||
user_friendly_output_logger.propagate = False
|
user_friendly_output_logger.propagate = False
|
||||||
|
|
||||||
# File output handlers
|
# File output handlers
|
||||||
if log_file_format is not None:
|
if config.log_file_format is not None:
|
||||||
if level < logging.ERROR:
|
if config.level < logging.ERROR:
|
||||||
file_output_format_template = TEXT_LOG_FORMAT_MAP[log_file_format]
|
file_output_format_template = TEXT_LOG_FORMAT_MAP[config.log_file_format]
|
||||||
file_output_formatter = AutoGptFormatter(
|
file_output_formatter = AutoGptFormatter(
|
||||||
file_output_format_template, no_color=True
|
file_output_format_template, no_color=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# INFO log file handler
|
# INFO log file handler
|
||||||
activity_log_handler = logging.FileHandler(log_dir / LOG_FILE, "a", "utf-8")
|
activity_log_handler = logging.FileHandler(
|
||||||
activity_log_handler.setLevel(level)
|
config.log_dir / LOG_FILE, "a", "utf-8"
|
||||||
|
)
|
||||||
|
activity_log_handler.setLevel(config.level)
|
||||||
activity_log_handler.setFormatter(file_output_formatter)
|
activity_log_handler.setFormatter(file_output_formatter)
|
||||||
log_handlers += [activity_log_handler]
|
log_handlers += [activity_log_handler]
|
||||||
user_friendly_output_logger.addHandler(activity_log_handler)
|
user_friendly_output_logger.addHandler(activity_log_handler)
|
||||||
|
|
||||||
# ERROR log file handler
|
# ERROR log file handler
|
||||||
error_log_handler = logging.FileHandler(log_dir / ERROR_LOG_FILE, "a", "utf-8")
|
error_log_handler = logging.FileHandler(
|
||||||
|
config.log_dir / ERROR_LOG_FILE, "a", "utf-8"
|
||||||
|
)
|
||||||
error_log_handler.setLevel(logging.ERROR)
|
error_log_handler.setLevel(logging.ERROR)
|
||||||
error_log_handler.setFormatter(
|
error_log_handler.setFormatter(
|
||||||
AutoGptFormatter(DEBUG_LOG_FORMAT, no_color=True)
|
AutoGptFormatter(DEBUG_LOG_FORMAT, no_color=True)
|
||||||
|
@ -196,7 +204,7 @@ def configure_logging(
|
||||||
# Configure the root logger
|
# Configure the root logger
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
format=console_format_template,
|
format=console_format_template,
|
||||||
level=level,
|
level=config.level,
|
||||||
handlers=log_handlers,
|
handlers=log_handlers,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue