parent
0bc66981fc
commit
5429ff312d
@ -1,23 +1,30 @@
|
|||||||
import os
|
import os
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
from swarms.utils.workspace_manager import WorkspaceManager
|
||||||
|
|
||||||
|
try:
|
||||||
WORKSPACE_DIR = os.getenv("WORKSPACE_DIR")
|
WORKSPACE_DIR = WorkspaceManager.get_workspace_dir()
|
||||||
|
|
||||||
logger.add(
|
logger.add(
|
||||||
os.path.join(WORKSPACE_DIR, "swarms.log"),
|
os.path.join(WORKSPACE_DIR, "swarms.log"),
|
||||||
level="INFO",
|
|
||||||
colorize=True,
|
|
||||||
backtrace=True,
|
|
||||||
diagnose=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def loguru_logger(file_path: str = "swarms.log"):
|
|
||||||
return logger.add(
|
|
||||||
os.path.join(WORKSPACE_DIR, file_path),
|
|
||||||
level="INFO",
|
level="INFO",
|
||||||
colorize=True,
|
colorize=True,
|
||||||
backtrace=True,
|
backtrace=True,
|
||||||
diagnose=True,
|
diagnose=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to initialize logger: {e}")
|
||||||
|
|
||||||
|
def loguru_logger(file_path: str = "swarms.log"):
|
||||||
|
try:
|
||||||
|
return logger.add(
|
||||||
|
os.path.join(WORKSPACE_DIR, file_path),
|
||||||
|
level="INFO",
|
||||||
|
colorize=True,
|
||||||
|
backtrace=True,
|
||||||
|
diagnose=True,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to create logger for {file_path}: {e}")
|
||||||
|
raise
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
|
class WorkspaceManager:
|
||||||
|
DEFAULT_WORKSPACE = "agent_workspace"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_workspace_dir(cls) -> str:
|
||||||
|
"""Get or create workspace directory with proper fallback"""
|
||||||
|
workspace = os.getenv("WORKSPACE_DIR", cls.DEFAULT_WORKSPACE)
|
||||||
|
workspace_path = Path(workspace)
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Create directory if it doesn't exist
|
||||||
|
workspace_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
# Set environment variable if not already set
|
||||||
|
if "WORKSPACE_DIR" not in os.environ:
|
||||||
|
os.environ["WORKSPACE_DIR"] = str(workspace_path)
|
||||||
|
|
||||||
|
return str(workspace_path)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error creating workspace directory: {e}")
|
||||||
|
raise
|
Loading…
Reference in new issue