Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Factor out get_logger; fix access to sweenv log (#558)

Kilian Lieret1ffc7aadb7d8
diff --git a/run.py b/run.py
index 261a1250..ce5232cc 100644
--- a/run.py
+++ b/run.py
@@ -1,6 +1,9 @@
from __future__ import annotations
+import logging
+
from sweagent import CONFIG_DIR
+from sweagent.utils.log import get_logger
try:
import rich
@@ -11,7 +14,6 @@ except ModuleNotFoundError as e:
)
raise RuntimeError(msg) from e
import json
-import logging
import os
import re
import subprocess
@@ -32,7 +34,6 @@ from getpass import getuser
from pathlib import Path
import yaml
-from rich.logging import RichHandler
from rich.markdown import Markdown
from simple_parsing import parse
from simple_parsing.helpers.flatten import FlattenedAccess
@@ -63,12 +64,8 @@ python run.py --model_name "gpt4" --data_path "/path/to/my_issue.md" --repo_path
**For more information**: https://princeton-nlp.github.io/SWE-agent/usage/cl_tutorial/
"""
-handler = RichHandler(show_time=False, show_path=False)
-handler.setLevel(logging.DEBUG)
-logger = logging.getLogger("run_dev")
-logger.setLevel(logging.DEBUG)
-logger.addHandler(handler)
-logger.propagate = False
+
+logger = get_logger("swe-agent-run")
logging.getLogger("simple_parsing").setLevel(logging.WARNING)
diff --git a/sweagent/agent/agents.py b/sweagent/agent/agents.py
index ad688c5b..6bd0a5c1 100644
--- a/sweagent/agent/agents.py
+++ b/sweagent/agent/agents.py
@@ -1,7 +1,6 @@
from __future__ import annotations
import json
-import logging
import re
from dataclasses import dataclass
from pathlib import Path
@@ -23,10 +22,8 @@ from sweagent.agent.models import (
)
from sweagent.agent.parsing import FormatError, ParseFunction
from sweagent.environment.swe_env import SWEEnv
-from sweagent.environment.utils import LOGGER_NAME
from sweagent.utils.config import convert_paths_to_abspath
-
-logger = logging.getLogger(LOGGER_NAME)
+from sweagent.utils.log import get_logger
@dataclass(frozen=True)
@@ -256,6 +253,7 @@ class Agent:
self.history = []
self.last_container_id = None
self.hooks = []
+ self.logger = get_logger("agent")
def add_hook(self, hook: AgentHook):
"""Add hook to agent"""
@@ -274,7 +272,7 @@ class Agent:
self.instance_args = instance_args
system_msg = self.config.system_template.format(**self.system_args)
- logger.info(f"SYSTEM ({self.name})\n{system_msg}")
+ self.logger.info(f"SYSTEM ({self.name})\n{system_msg}")
self.history: list[dict[str, Any]] = []
self._append_history({"role": "system", "content": system_msg, "agent": self.name})
@@ -286,7 +284,7 @@ class Agent:
raise ValueError(msg)
# Load history
- logger.info(f"DEMONSTRATION: {demonstration_path}")
+ self.logger.info(f"DEMONSTRATION: {demonstration_path}")
demo_history = json.loads(Path(demonstration_path).read_text())["history"]
demo_history = [
entry
@@ -296,7 +294,7 @@ class Agent:
if self.config.put_demos_in_history:
if self.config.demonstration_template is not None:
- logger.warning("Demonstration template is ignored for put_demos_in_history=True")
+ self.logger.warning("Demonstration template is ignored for put_demos_in_history=True")
# Add demonstration to history directly as separate messages
for entry in demo_history:
if entry["role"] != "system":
@@ -493,8 +491,8 @@ class Agent:
},
)
- logger.info(f"πŸ’­ THOUGHT ({self.name})\n{thought}")
- logger.info(f"🎬 ACTION ({self.name})\n{action}")
+ self.logger.info(f"πŸ’­ THOUGHT ({self.name})\n{thought}")
+ self.logger.info(f"🎬 ACTION ({self.name})\n{action}")
return thought, action, output
@@ -536,7 +534,7 @@ class Agent:
message = "\n".join(messages)
- logger.info(f"πŸ€– MODEL INPUT\n{message}")
+ self.logger.info(f"πŸ€– MODEL INPUT\n{message}")
self._append_history({"role": "user", "content": message, "agent": self.name})
for hook in self.hooks:
@@ -547,8 +545,8 @@ class Agent:
"""Ask the model to correct (without committing to persistent history) after a malformatted model output"""
format_error_template = self.config.format_error_template
- logger.warning(f"MALFORMED OUTPUT\n{output}")
- logger.warning(f"FORMAT ERROR\n{format_error_template}")
+ self.logger.warning(f"MALFORMED OUTPUT\n{output}")
+ self.logger.warning(f"FORMAT ERROR\n{format_error_template}")
temp_history = self.local_history + [
{"role": "assistant", "content": output, "agent": self.name},
@@ -561,8 +559,8 @@ class Agent:
name = action.strip().split()[0]
blocklist_error_message = self.config.blocklist_error_template.format(name=name)
- logger.warning(f"BLOCKLISTED OUTPUT\n{output}")
- logger.warning(f"BLOCKLIST ERROR\n{blocklist_error_message}")
+ self.logger.warning(f"BLOCKLISTED OUTPUT\n{output}")
+ self.logger.warning(f"BLOCKLIST ERROR\n{blocklist_error_message}")
temp_history = self.local_history + [
{"role": "assistant", "content": output, "agent": self.name},
@@ -626,7 +624,7 @@ class Agent:
output = self.retry_after_blocklist_fail(output, action)
else:
return thought, action, output
- logger.warning(f"Malformat limit reached: \n{output}")
+ self.logger.warning(f"Malformat limit reached: \n{output}")
return "Exit due to format error", "exit_format", output
def forward_with_error_check(self, observation: str, state: str) -> tuple[str, str, str]:
@@ -643,20 +641,20 @@ class Agent:
except KeyboardInterrupt:
raise
except RuntimeError as e:
- logger.warning(f"Runtime error: {e}")
+ self.logger.warning(f"Runtime error: {e}")
return (
f"Exit due to runtime error: {e}",
"exit_error",
f"exit due to runtime error: {e}",
)
except ContextWindowExceededError:
- logger.warning("Context window exceeded")
+ self.logger.warning("Context window exceeded")
return "Exit due to context window", "exit_context", "Exit due to context window"
except CostLimitExceededError:
- logger.warning("Cost limit exceeded")
+ self.logger.warning("Cost limit exceeded")
return "Exit due to cost limit", "exit_cost", "Exit due to cost limit"
except RetryError as e:
- logger.warning(f"Retry error: {e}")
+ self.logger.warning(f"Retry error: {e}")
return (
f"Exit due to retry error: {e}",
"exit_api",
@@ -685,7 +683,7 @@ class Agent:
except KeyboardInterrupt:
raise
except Exception as e:
- logger.warning("Failed to set environment variables")
+ self.logger.warning("Failed to set environment variables")
raise e
command_files = list()
for file in self.config.command_files:
@@ -788,7 +786,7 @@ class Agent:
assert self.config is not None
if env.container_obj.id != self.last_container_id:
- logger.info(f"Initializing agent settings for container {env.container_obj.id}")
+ self.logger.info(f"Initializing agent settings for container {env.container_obj.id}")
self.init_environment_vars(env)
self.last_container_id = env.container_obj.id
# Re-initialize primary
@@ -801,7 +799,7 @@ class Agent:
trajectory = []
info = {}
traj_log_path = traj_dir / (env.record["instance_id"] + ".traj")
- logger.info("Trajectory will be saved to %s", traj_log_path)
+ self.logger.info("Trajectory will be saved to %s", traj_log_path)
while not done:
for hook in self.hooks:
hook.on_step_start()
@@ -850,7 +848,7 @@ class Agent:
for hook in self.hooks:
hook.on_run_done()
- logger.info("Trajectory saved to %s", traj_log_path)
+ self.logger.info("Trajectory saved to %s", traj_log_path)
if return_type == "info":
return info
diff --git a/sweagent/agent/models.py b/sweagent/agent/models.py
index b50eec51..0ba090f8 100644
--- a/sweagent/agent/models.py
+++ b/sweagent/agent/models.py
@@ -10,7 +10,6 @@ from pathlib import Path
import together
from anthropic import AI_PROMPT, HUMAN_PROMPT, Anthropic, AnthropicBedrock
from openai import AzureOpenAI, BadRequestError, OpenAI
-from rich.logging import RichHandler
from simple_parsing.helpers.serialization.serializable import FrozenSerializable, Serializable
from tenacity import (
retry,
@@ -21,12 +20,9 @@ from tenacity import (
from sweagent.agent.commands import Command
from sweagent.utils.config import keys_config
+from sweagent.utils.log import get_logger
-logger = logging.getLogger("api_models")
-handler = RichHandler(show_time=False, show_path=False)
-handler.setLevel(logging.DEBUG)
-logger.addHandler(handler)
-logger.propagate = False
+logger = get_logger("api_models")
@dataclass(frozen=True)
@@ -44,7 +40,7 @@ class ModelArguments(FrozenSerializable):
# Sampling top-p
top_p: float = 1.0
# Path to replay file when using the replay model
- replay_path: str = None
+ replay_path: str | None = None
# Host URL when using Ollama model
host_url: str = "localhost:11434"
diff --git a/sweagent/environment/swe_env.py b/sweagent/environment/swe_env.py
index 635fa20d..95b331a5 100644
--- a/sweagent/environment/swe_env.py
+++ b/sweagent/environment/swe_env.py
@@ -3,7 +3,6 @@ from __future__ import annotations
import datetime
import hashlib
import json
-import logging
import os
import random
import re
@@ -18,7 +17,6 @@ import gymnasium as gym
import yaml
from ghapi.all import GhApi
from git import Repo
-from rich.logging import RichHandler
from simple_parsing.helpers.serialization.serializable import FrozenSerializable
from swebench import MAP_VERSION_TO_INSTALL, get_environment_yml, get_requirements
@@ -27,7 +25,6 @@ import docker.errors
import docker.models.containers
from sweagent import REPO_ROOT
from sweagent.environment.utils import (
- LOGGER_NAME,
PROCESS_DONE_MARKER_END,
PROCESS_DONE_MARKER_START,
InvalidGithubURL,
@@ -43,18 +40,12 @@ from sweagent.environment.utils import (
read_with_timeout_experimental,
)
from sweagent.utils.config import keys_config
+from sweagent.utils.log import default_logger, get_logger
LONG_TIMEOUT = 500
PATH_TO_REQS = "/root/requirements.txt"
PATH_TO_ENV_YML = "/root/environment.yml"
-handler = RichHandler(show_time=False, show_path=False)
-handler.setLevel(logging.DEBUG)
-logger = logging.getLogger(LOGGER_NAME)
-logger.setLevel(logging.DEBUG)
-logger.addHandler(handler)
-logger.propagate = False
-
@dataclass(frozen=True)
class EnvironmentArguments(FrozenSerializable):
@@ -98,7 +89,7 @@ class EnvironmentArguments(FrozenSerializable):
def __post_init__(self):
if self.timeout is not None:
- logger.warning("The 'timeout' argument is deprecated and has no effect.")
+ default_logger.warning("The 'timeout' argument is deprecated and has no effect.")
if self.cache_task_images and self.container_name:
msg = (
"Not allowed to use persistent container with caching task images "
@@ -148,10 +139,11 @@ class SWEEnv(gym.Env):
self.communicate_output: str | None = None
self.container_name: str | None = args.container_name
self.install_environment = args.install_environment
- self.logger = logger
+ self.logger = get_logger("SWEEnv")
self.persistent = args.container_name is not None
self.returncode: None | int = None
if not self.args.verbose:
+ # fixme: This creates problems if we have multiple instances of this class
self.logger.disabled = True
#: The commit hash of the swe-agent repository
@@ -162,7 +154,7 @@ class SWEEnv(gym.Env):
except KeyboardInterrupt:
raise
except Exception as e:
- logger.exception("Failed to get commit hash for this repo: %s", str(e))
+ self.logger.exception("Failed to get commit hash for this repo: %s", str(e))
self._github_token: str = keys_config.get("GITHUB_TOKEN", "") # type: ignore
@@ -189,7 +181,7 @@ class SWEEnv(gym.Env):
self.clean_multi_line_functions = lambda x: x
self.hooks: list[EnvHook] = []
- logger.debug("Environment initialization took %.2f seconds", time.perf_counter() - t0)
+ self.logger.debug("Environment initialization took %.2f seconds", time.perf_counter() - t0)
def _get_cached_task_image_name(self) -> str:
assert self.record is not None
@@ -246,12 +238,12 @@ class SWEEnv(gym.Env):
self.logger.info(f"{self._repo_name} not found in container, cloning...")
clone_url = f"https://{token_prefix}github.com/swe-bench/{self._repo_name}.git"
else:
- logger.info("Trying to clone from non-mirror...")
+ self.logger.info("Trying to clone from non-mirror...")
clone_url = f"https://{token_prefix}github.com/{self.record['repo']}.git"
clone_method = keys_config.get("SWE_AGENT_CLONE_METHOD", default="sparse", choices=["sparse", "full"])
if len(self.data) > 1 or self.persistent:
msg = "Falling back to full cloning method due to multiple instances or persistent container"
- logger.debug(msg)
+ self.logger.debug(msg)
if clone_method == "full":
self.communicate_with_handling(
input=f"git clone {clone_url} {self._repo_name}",
@@ -311,17 +303,17 @@ class SWEEnv(gym.Env):
if self.args.cache_task_images:
cached_image = self._get_cached_task_image_name()
if image_exists(cached_image):
- logger.info(f"Restore environment from cached image {cached_image}")
+ self.logger.info(f"Restore environment from cached image {cached_image}")
self.close() # stop current container
self._init_container(cached_image=cached_image)
self.communicate("export $(xargs </.env)")
envs = self.communicate("env")
- logger.debug(f"Environment variables restored from the image:\n{envs}\n")
+ self.logger.debug(f"Environment variables restored from the image:\n{envs}\n")
if apply_test_patch:
self._apply_test_patch()
return None, info
else:
- logger.info(f"Cached image {cached_image} not found, rebuilding task environment...")
+ self.logger.info(f"Cached image {cached_image} not found, rebuilding task environment...")
# Clone repository if not already cloned
self.communicate(input="cd /")
@@ -380,11 +372,11 @@ class SWEEnv(gym.Env):
if self.args.cache_task_images:
envs = self.communicate("env")
- logger.debug(f"Environment variables to save:\n{envs}\n")
+ self.logger.debug(f"Environment variables to save:\n{envs}\n")
self.communicate("env >> /.env")
assert self.container_obj is not None # mypy
self.container_obj.commit(cached_image)
- logger.info(f"Container with environment {self.container_obj.id} cached as image {cached_image}")
+ self.logger.info(f"Container with environment {self.container_obj.id} cached as image {cached_image}")
if apply_test_patch:
self._apply_test_patch()
@@ -440,7 +432,7 @@ class SWEEnv(gym.Env):
info["exit_status"] = f"submitted ({action})"
info["submission"] = submission
observation = "Exited (autosubmitted)"
- logger.info("Exiting with autosubmission")
+ self.logger.info("Exiting with autosubmission")
return observation, 0, True, info
except KeyboardInterrupt:
raise
@@ -460,24 +452,24 @@ class SWEEnv(gym.Env):
except RuntimeError as e:
observation += "\nEXECUTION TIMED OUT AND INTERRUPT FAILED. RESTARTING PROCESS."
info["exit_status"] = "early_exit"
- logger.warning(f"Failed to interrupt container: {e}\nRESTARTING PROCESS.")
+ self.logger.warning(f"Failed to interrupt container: {e}\nRESTARTING PROCESS.")
self.reset_container()
return observation, 0, True, info
except RuntimeError as e:
observation += "\nCOMMAND FAILED TO EXECUTE. RESTARTING PROCESS."
info["exit_status"] = "early_exit"
- logger.warning(f"Failed to execute command: {e}\nRESTARTING PROCESS.")
+ self.logger.warning(f"Failed to execute command: {e}\nRESTARTING PROCESS.")
self.reset_container()
return observation, 0, True, info
except BrokenPipeError as e:
observation += "\nBROKEN PIPE ERROR. RESTARTING PROCESS."
info["exit_status"] = "early_exit"
- logger.error(f"Broken pipe error: {e}\nRESTARTING PROCESS.")
+ self.logger.error(f"Broken pipe error: {e}\nRESTARTING PROCESS.")
self.reset_container()
return observation, 0, True, info
except Exception:
observation += "\nEXECUTION FAILED OR COMMAND MALFORMED"
- logger.exception("Unknown exception")
+ self.logger.exception("Unknown exception")
# Record submission and end episode if `submit` keyword found
submission = self.get_submission(observation)
@@ -499,7 +491,7 @@ class SWEEnv(gym.Env):
except KeyboardInterrupt:
raise
except:
- logger.warning("Errors when exiting container", exc_info=True)
+ self.logger.warning("Errors when exiting container", exc_info=True)
assert self.container is not None # mypy
self.container.terminate()
if self.container_obj is None:
@@ -572,7 +564,7 @@ class SWEEnv(gym.Env):
image_name = self.image_name
if cached_image is not None:
image_name = cached_image
- logger.info(f"Using cached image: {image_name}")
+ self.logger.info(f"Using cached image: {image_name}")
if self.persistent:
assert self.container_name is not None
else:
@@ -594,7 +586,7 @@ class SWEEnv(gym.Env):
try:
self.container_obj = client.containers.get(self.container_name)
except docker.errors.NotFound:
- logger.debug("Couldn't find container. Let's wait and retry.")
+ self.logger.debug("Couldn't find container. Let's wait and retry.")
time.sleep(1)
else:
break
@@ -821,7 +813,7 @@ class SWEEnv(gym.Env):
if (
self.record["problem_statement_source"] != "swe-bench" or self.record["repo_type"] == "local"
) and self.args.environment_setup is None:
- logger.warning(
+ self.logger.warning(
"install_environment is set to True, but the data path is a GitHub URL "
"without an environment config file (environment_config key/flag). "
"Skipping conda environment installation.",
@@ -883,7 +875,7 @@ class SWEEnv(gym.Env):
error_msg="Failed to create conda environment",
timeout_duration=LONG_TIMEOUT,
)
- logger.debug("Created conda environment")
+ self.logger.debug("Created conda environment")
# Write reqs to requirements.txt in docker container
content_reqs = get_requirements(self.record)
copy_file_to_container(self.container_obj, content_reqs, PATH_TO_REQS)
@@ -897,7 +889,7 @@ class SWEEnv(gym.Env):
error_msg="Failed to install requirements.txt",
timeout_duration=LONG_TIMEOUT,
)
- logger.debug("Installed requirements from requirements.txt")
+ self.logger.debug("Installed requirements from requirements.txt")
self.communicate(f"rm {PATH_TO_REQS}")
elif packages == "environment.yml":
# Write environment.yml to file
@@ -917,14 +909,14 @@ class SWEEnv(gym.Env):
error_msg="Failed to create conda environment",
timeout_duration=LONG_TIMEOUT,
)
- logger.debug("Created conda environment")
+ self.logger.debug("Created conda environment")
# Install packages
self.communicate_with_handling(
f"conda env update -f {PATH_TO_ENV_YML}",
error_msg="Failed to install environment.yml",
timeout_duration=LONG_TIMEOUT,
)
- logger.debug("Installed packages from environment.yml")
+ self.logger.debug("Installed packages from environment.yml")
else:
# Create environment + install packages
self.communicate_with_handling(
@@ -932,7 +924,7 @@ class SWEEnv(gym.Env):
error_msg="Failed to create conda environment with environment.yml",
timeout_duration=LONG_TIMEOUT,
)
- logger.debug("Created conda environment with environment.yml")
+ self.logger.debug("Created conda environment with environment.yml")
self.communicate(f"rm {PATH_TO_ENV_YML}")
else:
python_env = f"python{install_configs['python']}"
@@ -942,7 +934,7 @@ class SWEEnv(gym.Env):
error_msg="Failed to clone conda environment",
timeout_duration=LONG_TIMEOUT,
)
- logger.debug("Cloned python conda environment")
+ self.logger.debug("Cloned python conda environment")
else:
self.communicate_with_handling(
f"conda create -n {env_name} python={install_configs['python']} -y",
@@ -959,7 +951,7 @@ class SWEEnv(gym.Env):
error_msg="Failed to install packages",
timeout_duration=LONG_TIMEOUT,
)
- logger.debug("Installed conda packages")
+ self.logger.debug("Installed conda packages")
# Install extra pip packages if specified
if install_configs.get("pip_packages"):
self.communicate_with_handling(
@@ -967,7 +959,7 @@ class SWEEnv(gym.Env):
error_msg="Failed to install pip packages",
timeout_duration=LONG_TIMEOUT,
)
- logger.debug("Installed extra pip dependencies")
+ self.logger.debug("Installed extra pip dependencies")
# Activate environment
self.communicate_with_handling(f"conda activate {env_name}", error_msg="Failed to activate conda environment")
@@ -980,7 +972,7 @@ class SWEEnv(gym.Env):
pre_install_cmd,
error_msg="Pre-install commands failed to execute successfully",
)
- logger.debug("Ran pre-install commands")
+ self.logger.debug("Ran pre-install commands")
self.logger.info(f"Installing {self._repo_name} at base commit...")
if install_configs.get("install"):
install_cmd = install_configs["install"]
@@ -989,7 +981,7 @@ class SWEEnv(gym.Env):
error_msg="Install command failed to execute successfully",
timeout_duration=LONG_TIMEOUT,
)
- logger.debug("Ran install command")
+ self.logger.debug("Ran install command")
if install_configs.get("post_install"):
self.logger.info("Running post-install commands...")
for post_install_cmd in install_configs["post_install"]:
@@ -997,9 +989,9 @@ class SWEEnv(gym.Env):
post_install_cmd,
error_msg="Post-install commands failed to execute successfully",
)
- logger.debug("Ran post-install commands")
+ self.logger.debug("Ran post-install commands")
- logger.info("Installation step took %.2f seconds", time.perf_counter() - t0)
+ self.logger.info("Installation step took %.2f seconds", time.perf_counter() - t0)
def add_commands(self, commands: list[dict]) -> None:
"""
@@ -1057,7 +1049,7 @@ class SWEEnv(gym.Env):
trajectory: Trajectory of actions taken by the agent
_dry_run: Whether to actually push anything or just simulate it
"""
- logger.info("Opening PR")
+ self.logger.info("Opening PR")
# TODO: have better way of handling this
# Adding random string suffix to avoid name conflicts if we had a previously failed run
issue_url = self.args.data_path
@@ -1108,7 +1100,7 @@ class SWEEnv(gym.Env):
if self._github_token:
token_prefix = f"{self._github_token}@"
fork_url = f"https://{token_prefix}github.com/{forker}/{repo}.git"
- logger.debug(f"Using fork: {fork_url}")
+ self.logger.debug(f"Using fork: {fork_url}")
self.communicate_with_handling(
input=f"git remote add fork {fork_url}",
error_msg="Failed to create new git remote",
@@ -1140,7 +1132,7 @@ class SWEEnv(gym.Env):
body=body,
draft=True,
)
- logger.info(
+ self.logger.info(
f"πŸŽ‰ PR created as a draft at {pr_info.html_url}. Please review it carefully, push "
"any required changes onto the branch and then click "
"'Ready for Review' to bring it to the attention of the maintainers.",
diff --git a/sweagent/environment/utils.py b/sweagent/environment/utils.py
index 0ef43aa7..07357f67 100644
--- a/sweagent/environment/utils.py
+++ b/sweagent/environment/utils.py
@@ -2,7 +2,6 @@ from __future__ import annotations
import hashlib
import json
-import logging
import os
import platform
import re
@@ -24,13 +23,13 @@ from git import InvalidGitRepositoryError, Repo
import docker
from docker.models.containers import Container
from sweagent.utils.config import keys_config
+from sweagent.utils.log import get_logger
-LOGGER_NAME = "intercode"
DOCKER_START_UP_DELAY = float(keys_config.get("SWE_AGENT_DOCKER_START_UP_DELAY", 1))
GITHUB_ISSUE_URL_PATTERN = re.compile(r"github\.com\/(.*?)\/(.*?)\/issues\/(\d+)")
GITHUB_REPO_URL_PATTERN = re.compile(r".*[/@]?github\.com\/([^/]+)\/([^/]+)")
-logger = logging.getLogger(LOGGER_NAME)
+logger = get_logger("env_utils")
def get_data_path_name(data_path: str) -> str:
diff --git a/sweagent/utils/config.py b/sweagent/utils/config.py
index 8e218390..1487cd90 100644
--- a/sweagent/utils/config.py
+++ b/sweagent/utils/config.py
@@ -1,14 +1,14 @@
from __future__ import annotations
-import logging
import os
from pathlib import Path
from typing import Any
import config as config_file
from sweagent import REPO_ROOT
+from sweagent.utils.log import get_logger
-logger = logging.getLogger("config")
+logger = get_logger("config")
def convert_path_to_abspath(path: Path | str) -> Path:
diff --git a/sweagent/utils/log.py b/sweagent/utils/log.py
new file mode 100644
index 00000000..bc736c4f
--- /dev/null
+++ b/sweagent/utils/log.py
@@ -0,0 +1,24 @@
+from __future__ import annotations
+
+import logging
+
+from rich.logging import RichHandler
+
+_SET_UP_LOGGERS = set()
+
+
+def get_logger(name: str) -> logging.Logger:
+ logger = logging.getLogger(name)
+ if name in _SET_UP_LOGGERS:
+ # Already set up
+ return logger
+ handler = RichHandler(show_time=False, show_path=False)
+ handler.setLevel(logging.DEBUG)
+ logger.setLevel(logging.DEBUG)
+ logger.addHandler(handler)
+ logger.propagate = False
+ _SET_UP_LOGGERS.add(name)
+ return logger
+
+
+default_logger = get_logger("swe-agent")