2023-03-27 11:14:23 +00:00
|
|
|
import CloudRunnerLogger from '../services/core/cloud-runner-logger';
|
2023-05-13 19:10:19 +00:00
|
|
|
import fs from 'node:fs';
|
2023-05-14 15:21:33 +00:00
|
|
|
import path from 'node:path';
|
2023-05-14 16:19:20 +00:00
|
|
|
import CloudRunner from '../cloud-runner';
|
2022-02-01 02:31:20 +00:00
|
|
|
|
|
|
|
export class RemoteClientLogger {
|
2023-05-13 19:10:19 +00:00
|
|
|
private static get LogFilePath() {
|
2023-05-14 16:16:36 +00:00
|
|
|
return path.join(`/home`, `job-log.txt`);
|
2023-05-13 19:10:19 +00:00
|
|
|
}
|
|
|
|
|
2022-02-01 02:31:20 +00:00
|
|
|
public static log(message: string) {
|
2023-05-13 19:10:19 +00:00
|
|
|
const finalMessage = `[Client] ${message}`;
|
|
|
|
this.appendToFile(finalMessage);
|
|
|
|
CloudRunnerLogger.log(finalMessage);
|
2022-02-01 02:31:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static logCliError(message: string) {
|
|
|
|
CloudRunnerLogger.log(`[Client][Error] ${message}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static logCliDiagnostic(message: string) {
|
|
|
|
CloudRunnerLogger.log(`[Client][Diagnostic] ${message}`);
|
|
|
|
}
|
|
|
|
|
2023-03-04 00:25:40 +00:00
|
|
|
public static logWarning(message: string) {
|
2022-02-01 02:31:20 +00:00
|
|
|
CloudRunnerLogger.logWarning(message);
|
|
|
|
}
|
2023-05-13 19:10:19 +00:00
|
|
|
|
|
|
|
public static appendToFile(message: string) {
|
2023-05-14 16:19:20 +00:00
|
|
|
if (CloudRunner.isCloudRunnerEnvironment) {
|
|
|
|
fs.appendFileSync(RemoteClientLogger.LogFilePath, message);
|
|
|
|
}
|
2023-05-13 19:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static printCollectedLogs() {
|
|
|
|
CloudRunnerLogger.log(`Collected Logs`);
|
|
|
|
CloudRunnerLogger.log(fs.readFileSync(RemoteClientLogger.LogFilePath).toString());
|
|
|
|
}
|
2022-02-01 02:31:20 +00:00
|
|
|
}
|