unity-builder/src/model/cloud-runner/remote-client/remote-client-logger.ts

53 lines
1.6 KiB
TypeScript
Raw Normal View History

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';
import CloudRunnerOptions from '../options/cloud-runner-options';
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}`);
}
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) {
2023-05-14 20:00:49 +00:00
fs.appendFileSync(RemoteClientLogger.LogFilePath, `${message}\n`);
2023-05-14 16:19:20 +00:00
}
2023-05-13 19:10:19 +00:00
}
2023-08-14 17:59:05 +00:00
public static async handleLogManagementPostJob() {
if (CloudRunnerOptions.providerStrategy !== 'k8s') {
return;
}
2023-05-13 19:10:19 +00:00
CloudRunnerLogger.log(`Collected Logs`);
2023-08-14 17:59:05 +00:00
const hashedLogs = fs.readFileSync(RemoteClientLogger.LogFilePath).toString();
CloudRunnerLogger.log(hashedLogs);
const logs = fs.readFileSync(RemoteClientLogger.LogFilePath).toString();
CloudRunnerLogger.log(logs);
2023-08-14 17:59:05 +00:00
// loop for 5 mins logging the logs every minute
for (let index = 0; index < 5; index++) {
await new Promise((resolve) => setTimeout(resolve, 60000));
CloudRunnerLogger.log(logs);
}
2023-05-13 19:10:19 +00:00
}
2022-02-01 02:31:20 +00:00
}