fix: update supervisor.readLog to accept 3 parameters with logfile path
All checks were successful
Build and Push Docker Image to Gitea / build-and-push (push) Successful in 1m10s
All checks were successful
Build and Push Docker Image to Gitea / build-and-push (push) Successful in 1m10s
Update the readLog method to match custom Supervisor API requirements: - Add third parameter (logfile_path) to supervisor.readLog call - Retrieve logfile path from supervisor.getAPIVersion() metadata - Cache logfile path after first retrieval to avoid repeated API calls - Support optional explicit logfile_path parameter - Fallback to default path if metadata extraction fails Implementation details: - Added cachedLogfilePath private field to SupervisorClient - Added private getLogfilePath() method to extract path from API version - Updated readLog signature: (offset, length, logfilePath?) - Automatic path retrieval when logfilePath not provided - Supports multiple metadata formats (logfile, logfile_path properties) - Logs warnings if path extraction fails, uses sensible default 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -25,6 +25,7 @@ export class SupervisorClient {
|
||||
private client: xmlrpc.Client;
|
||||
private config: SupervisorClientConfig;
|
||||
private logger: ReturnType<typeof createLogger>;
|
||||
private cachedLogfilePath?: string;
|
||||
|
||||
constructor(config: SupervisorClientConfig) {
|
||||
this.config = config;
|
||||
@@ -101,6 +102,40 @@ export class SupervisorClient {
|
||||
return this.call<string>('supervisor.getSupervisorVersion');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get logfile path from API version metadata
|
||||
* Caches the result after first call
|
||||
*/
|
||||
private async getLogfilePath(): Promise<string> {
|
||||
if (this.cachedLogfilePath) {
|
||||
return this.cachedLogfilePath;
|
||||
}
|
||||
|
||||
// Get API version which should contain logfile path in metadata
|
||||
const apiVersionData = await this.call<any>('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<string> {
|
||||
return this.call<string>('supervisor.getIdentification');
|
||||
}
|
||||
@@ -252,8 +287,10 @@ export class SupervisorClient {
|
||||
return this.call<ProcessActionResult[]>('supervisor.clearAllProcessLogs');
|
||||
}
|
||||
|
||||
async readLog(offset: number, length: number): Promise<string> {
|
||||
return this.call<string>('supervisor.readLog', [offset, length]);
|
||||
async readLog(offset: number, length: number, logfilePath?: string): Promise<string> {
|
||||
// If logfilePath not provided, get it from API version metadata
|
||||
const path = logfilePath || await this.getLogfilePath();
|
||||
return this.call<string>('supervisor.readLog', [offset, length, path]);
|
||||
}
|
||||
|
||||
async clearLog(): Promise<boolean> {
|
||||
|
||||
Reference in New Issue
Block a user