mirror of
https://github.com/coder/code-server.git
synced 2025-09-29 02:56:25 +08:00
Merge commit 'be3e8236086165e5e45a5a10783823874b3f3ebd' as 'lib/vscode'
This commit is contained in:
42
lib/vscode/test/automation/src/logger.ts
Normal file
42
lib/vscode/test/automation/src/logger.ts
Normal file
@ -0,0 +1,42 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { appendFileSync, writeFileSync } from 'fs';
|
||||
import { format } from 'util';
|
||||
import { EOL } from 'os';
|
||||
|
||||
export interface Logger {
|
||||
log(message: string, ...args: any[]): void;
|
||||
}
|
||||
|
||||
export class ConsoleLogger implements Logger {
|
||||
|
||||
log(message: string, ...args: any[]): void {
|
||||
console.log('**', message, ...args);
|
||||
}
|
||||
}
|
||||
|
||||
export class FileLogger implements Logger {
|
||||
|
||||
constructor(private path: string) {
|
||||
writeFileSync(path, '');
|
||||
}
|
||||
|
||||
log(message: string, ...args: any[]): void {
|
||||
const date = new Date().toISOString();
|
||||
appendFileSync(this.path, `[${date}] ${format(message, ...args)}${EOL}`);
|
||||
}
|
||||
}
|
||||
|
||||
export class MultiLogger implements Logger {
|
||||
|
||||
constructor(private loggers: Logger[]) { }
|
||||
|
||||
log(message: string, ...args: any[]): void {
|
||||
for (const logger of this.loggers) {
|
||||
logger.log(message, ...args);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user