diff --git a/lib/supervisor/client.ts b/lib/supervisor/client.ts index 6c737f2..24cf409 100644 --- a/lib/supervisor/client.ts +++ b/lib/supervisor/client.ts @@ -25,6 +25,7 @@ export class SupervisorClient { private client: xmlrpc.Client; private config: SupervisorClientConfig; private logger: ReturnType; + private cachedLogfilePath?: string; constructor(config: SupervisorClientConfig) { this.config = config; @@ -101,6 +102,40 @@ 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'); } @@ -252,8 +287,10 @@ export class SupervisorClient { return this.call('supervisor.clearAllProcessLogs'); } - async readLog(offset: number, length: number): Promise { - return this.call('supervisor.readLog', [offset, length]); + 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(); + return this.call('supervisor.readLog', [offset, length, path]); } async clearLog(): Promise {