unity-builder/src/model/cloud-runner/services/cloud-runner-logger.ts

56 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-08-21 23:26:03 +00:00
import * as core from '@actions/core';
2021-09-21 18:27:04 +00:00
class CloudRunnerLogger {
2021-08-21 23:26:03 +00:00
private static timestamp: number;
private static globalTimestamp: number;
public static setup() {
this.timestamp = this.createTimestamp();
this.globalTimestamp = this.timestamp;
}
2021-09-21 18:27:04 +00:00
public static log(message: string) {
core.info(message);
}
2021-12-26 19:24:10 +00:00
public static logCli(message: string) {
2021-12-27 21:53:22 +00:00
CloudRunnerLogger.log(`[Client] ${message}`);
2021-12-24 04:05:42 +00:00
}
2021-12-29 14:35:13 +00:00
public static logCliError(message: string) {
CloudRunnerLogger.log(`[Client][Error] ${message}`);
}
public static logCliDiagnostic(message: string) {
CloudRunnerLogger.log(`[Client][Diagnostic] ${message}`);
}
public static logLine(message: string) {
core.info(`${message}\n`);
}
2021-09-21 18:27:04 +00:00
public static error(message: string) {
core.error(message);
}
2021-08-21 23:26:03 +00:00
public static logWithTime(message: string) {
const newTimestamp = this.createTimestamp();
core.info(
`${message} (Since previous: ${this.calculateTimeDiff(
newTimestamp,
this.timestamp,
)}, Total time: ${this.calculateTimeDiff(newTimestamp, this.globalTimestamp)})`,
);
this.timestamp = newTimestamp;
}
private static calculateTimeDiff(x: number, y: number) {
return Math.floor((x - y) / 1000);
}
private static createTimestamp() {
return Date.now();
}
}
2021-09-21 18:27:04 +00:00
export default CloudRunnerLogger;