diff --git a/.env.example b/.env.example index 749f024..41c8969 100644 --- a/.env.example +++ b/.env.example @@ -11,6 +11,10 @@ SUPERVISOR_PORT=9001 # SUPERVISOR_USERNAME=user # SUPERVISOR_PASSWORD=pass +# Optional: Path to supervisord main logfile (for reading via XML-RPC) +# Default: /var/log/supervisor/supervisord.log +# SUPERVISOR_LOGFILE=/var/log/supervisor/supervisord.log + # Logging Configuration # Log level: debug, info, warn, error (default: info in prod, debug in dev) LOG_LEVEL=info diff --git a/lib/supervisor/client.ts b/lib/supervisor/client.ts index 24cf409..6179aeb 100644 --- a/lib/supervisor/client.ts +++ b/lib/supervisor/client.ts @@ -25,7 +25,6 @@ export class SupervisorClient { private client: xmlrpc.Client; private config: SupervisorClientConfig; private logger: ReturnType; - private cachedLogfilePath?: string; constructor(config: SupervisorClientConfig) { this.config = config; @@ -102,40 +101,6 @@ export class SupervisorClient { return this.call('supervisor.getSupervisorVersion'); } - /** - * Get logfile path from API version metadata - * Caches the result after first call - */ - private async getLogfilePath(): Promise { - if (this.cachedLogfilePath) { - return this.cachedLogfilePath; - } - - // Get API version which should contain logfile path in metadata - const apiVersionData = await this.call('supervisor.getAPIVersion'); - - // Parse the response to extract logfile path - // The exact structure depends on your supervisor API implementation - // Common formats might be: - // - { version: "3.0", logfile: "/path/to/log" } - // - Just a string with embedded metadata - let logfilePath: string; - - if (typeof apiVersionData === 'object' && apiVersionData.logfile) { - logfilePath = apiVersionData.logfile; - } else if (typeof apiVersionData === 'object' && apiVersionData.logfile_path) { - logfilePath = apiVersionData.logfile_path; - } else { - // Fallback to default supervisord log location if not found in metadata - this.logger.warn('Could not extract logfile path from getAPIVersion, using default'); - logfilePath = '/var/log/supervisor/supervisord.log'; - } - - this.cachedLogfilePath = logfilePath; - this.logger.debug({ logfilePath }, 'Retrieved and cached logfile path'); - return logfilePath; - } - async getIdentification(): Promise { return this.call('supervisor.getIdentification'); } @@ -288,8 +253,9 @@ export class SupervisorClient { } async readLog(offset: number, length: number, logfilePath?: string): Promise { - // If logfilePath not provided, get it from API version metadata - const path = logfilePath || await this.getLogfilePath(); + // Use provided path, or fall back to env variable, or use default + const path = logfilePath || process.env.SUPERVISOR_LOGFILE || '/var/log/supervisor/supervisord.log'; + this.logger.debug({ path, offset, length }, 'Reading supervisor main log'); return this.call('supervisor.readLog', [offset, length, path]); }