ENGINE: Migrated Logs to Runtime Folders

This commit is contained in:
2025-10-29 15:19:29 -06:00
parent 98737fb737
commit 8fa7bd4fb0
11 changed files with 36 additions and 33 deletions

View File

@@ -242,7 +242,7 @@ class Role:
self._ansible_ready = False
self._ansible_bootstrap_lock = None
try:
base = os.path.join(_project_root(), 'Logs', 'Agent')
base = os.path.join(_project_root(), 'Agent', 'Logs')
os.makedirs(base, exist_ok=True)
self._ansible_log(f"[init] PlaybookExec role init agent_id={ctx.agent_id}")
except Exception:
@@ -580,7 +580,7 @@ class Role:
def _log_local(self, msg: str, error: bool = False):
try:
base = os.path.join(_project_root(), 'Logs', 'Agent')
base = os.path.join(_project_root(), 'Agent', 'Logs')
os.makedirs(base, exist_ok=True)
fn = 'agent.error.log' if error else 'agent.log'
ts = time.strftime('%Y-%m-%d %H:%M:%S')
@@ -600,7 +600,7 @@ class Role:
def _ansible_log(self, msg: str, error: bool = False, run_id: str = None):
try:
d = os.path.join(_project_root(), 'Logs', 'Agent')
d = os.path.join(_project_root(), 'Agent', 'Logs')
ts = time.strftime('%Y-%m-%d %H:%M:%S')
path = os.path.join(d, 'ansible.log')
try:
@@ -716,7 +716,7 @@ class Role:
if os.name != 'nt':
return
mod = self._ps_module_path()
log_dir = os.path.join(_project_root(), 'Logs', 'Agent')
log_dir = os.path.join(_project_root(), 'Agent', 'Logs')
try:
os.makedirs(log_dir, exist_ok=True)
except Exception:

View File

@@ -219,7 +219,7 @@ def _run_powershell_via_system_task(content: str, env_map: Dict[str, str], timeo
with os.fdopen(script_fd, 'w', encoding='utf-8', newline='\n') as f:
f.write(final_content)
try:
log_dir = os.path.join(_project_root(), 'Logs', 'Agent')
log_dir = os.path.join(_project_root(), 'Agent', 'Logs')
os.makedirs(log_dir, exist_ok=True)
with open(os.path.join(log_dir, 'system_last.ps1'), 'w', encoding='utf-8', newline='\n') as df:
df.write(content or '')

View File

@@ -57,9 +57,10 @@ def _iter_exception_chain(exc: BaseException):
def _agent_logs_root() -> str:
try:
root = _find_project_root()
return os.path.abspath(os.path.join(root, 'Logs', 'Agent'))
return os.path.abspath(os.path.join(root, 'Agent', 'Logs'))
except Exception:
return os.path.abspath(os.path.join(os.path.dirname(__file__), 'Logs', 'Agent'))
base_dir = os.path.abspath(os.path.dirname(__file__))
return os.path.abspath(os.path.join(base_dir, 'Logs'))
def _rotate_daily(path: str):
@@ -517,7 +518,7 @@ def _find_project_root():
# Heuristic fallback: two levels up from Agent/Borealis
return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
# Simple file logger under Logs/Agent
# Simple file logger under Agent/Logs
def _log_agent(message: str, fname: str = 'agent.log', *, scope: Optional[str] = None):
try:
log_dir = _agent_logs_root()
@@ -2856,7 +2857,7 @@ def _run_powershell_via_system_task(content: str):
with os.fdopen(fd, 'w', encoding='utf-8', newline='\n') as f:
f.write(content or '')
try:
log_dir = os.path.join(_project_root_for_temp(), 'Logs', 'Agent')
log_dir = os.path.join(_project_root_for_temp(), 'Agent', 'Logs')
os.makedirs(log_dir, exist_ok=True)
debug_copy = os.path.join(log_dir, 'system_last.ps1')
with open(debug_copy, 'w', encoding='utf-8', newline='\n') as df:
@@ -3260,7 +3261,7 @@ if __name__=='__main__':
return
try:
# Save last SYSTEM script for debugging
dbg_dir = os.path.join(_find_project_root(), 'Logs', 'Agent')
dbg_dir = os.path.join(_find_project_root(), 'Agent', 'Logs')
os.makedirs(dbg_dir, exist_ok=True)
with open(os.path.join(dbg_dir, 'system_last.ps1'), 'w', encoding='utf-8', newline='\n') as df:
df.write(content or '')

View File

@@ -14,7 +14,7 @@ def project_paths():
venv_root = os.path.abspath(os.path.join(venv_scripts, os.pardir))
project_root = os.path.abspath(os.path.join(venv_root, os.pardir))
borealis_dir = os.path.join(venv_root, "Borealis")
logs_dir = os.path.join(project_root, "Logs", "Agent")
logs_dir = os.path.join(project_root, "Agent", "Logs")
temp_dir = os.path.join(project_root, "Temp")
return {
"project_root": project_root,

View File

@@ -9,9 +9,11 @@ try {
$scriptDir = Split-Path -Path $PSCommandPath -Parent
Set-Location -Path $scriptDir
# Centralized logs under <ProjectRoot>\Logs\Agent
# Centralized logs under <ProjectRoot>\Agent\Logs
$projRoot = Resolve-Path (Join-Path $scriptDir '..\..')
$logsAgent = Join-Path $projRoot 'Logs\Agent'
$agentRoot = Join-Path $projRoot 'Agent'
if (-not (Test-Path $agentRoot)) { New-Item -ItemType Directory -Path $agentRoot -Force | Out-Null }
$logsAgent = Join-Path $agentRoot 'Logs'
if (-not (Test-Path $logsAgent)) { New-Item -ItemType Directory -Path $logsAgent -Force | Out-Null }
$wrapperLog = Join-Path $logsAgent 'service_wrapper.log'

View File

@@ -34,8 +34,8 @@ defaults that mirror the legacy server runtime. Key environment variables are
When TLS values are not provided explicitly the Engine provisions certificates
under ``Engine/Certificates`` (migrating any legacy material) so the runtime
remains self-contained.
Logs are written to ``Logs/Engine/engine.log`` with daily rotation and
errors are additionally duplicated to ``Logs/Engine/error.log`` so the
Logs are written to ``Engine/Logs/engine.log`` with daily rotation and
errors are additionally duplicated to ``Engine/Logs/error.log`` so the
runtime integrates with the platform's logging policy.
"""
@@ -73,7 +73,7 @@ def _discover_project_root() -> Path:
PROJECT_ROOT = _discover_project_root()
DEFAULT_DATABASE_PATH = PROJECT_ROOT / "database.db"
LOG_ROOT = PROJECT_ROOT / "Logs" / "Engine"
LOG_ROOT = PROJECT_ROOT / "Engine" / "Logs"
LOG_FILE_PATH = LOG_ROOT / "engine.log"
ERROR_LOG_FILE_PATH = LOG_ROOT / "error.log"
API_LOG_FILE_PATH = LOG_ROOT / "api.log"

View File

@@ -11,7 +11,7 @@ Stage 1 introduced the structural skeleton for the Engine runtime. Stage 2
builds upon that foundation by centralising configuration handling and logging
initialisation so the Engine mirrors the legacy server's start-up behaviour.
The factory delegates configuration resolution to :mod:`Data.Engine.config`
and emits structured logs to ``Logs/Engine/engine.log`` (with an accompanying
and emits structured logs to ``Engine/Logs/engine.log`` (with an accompanying
error log) to align with the project's operational practices.
"""
from __future__ import annotations