mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from vscode e0762af258c0b20320ed03f3871a41967acc4421 (#7404)
* Merge from vscode e0762af258c0b20320ed03f3871a41967acc4421 * readd svgs
This commit is contained in:
@@ -7,7 +7,7 @@ import { ILogService, LogLevel, AbstractLogService, DEFAULT_LOG_LEVEL } from 'vs
|
||||
|
||||
interface ILog {
|
||||
level: LogLevel;
|
||||
args: IArguments;
|
||||
args: any[];
|
||||
}
|
||||
|
||||
function getLogFunction(logger: ILogService, level: LogLevel): Function {
|
||||
@@ -49,7 +49,7 @@ export class BufferLogService extends AbstractLogService implements ILogService
|
||||
this.buffer = [];
|
||||
}
|
||||
|
||||
private _log(level: LogLevel, args: IArguments): void {
|
||||
private _log(level: LogLevel, ...args: any[]): void {
|
||||
if (this._logger) {
|
||||
const fn = getLogFunction(this._logger, level);
|
||||
fn.apply(this._logger, args);
|
||||
@@ -58,28 +58,28 @@ export class BufferLogService extends AbstractLogService implements ILogService
|
||||
}
|
||||
}
|
||||
|
||||
trace(): void {
|
||||
this._log(LogLevel.Trace, arguments);
|
||||
trace(message: string, ...args: any[]): void {
|
||||
this._log(LogLevel.Trace, message, ...args);
|
||||
}
|
||||
|
||||
debug(): void {
|
||||
this._log(LogLevel.Debug, arguments);
|
||||
debug(message: string, ...args: any[]): void {
|
||||
this._log(LogLevel.Debug, message, ...args);
|
||||
}
|
||||
|
||||
info(): void {
|
||||
this._log(LogLevel.Info, arguments);
|
||||
info(message: string, ...args: any[]): void {
|
||||
this._log(LogLevel.Info, message, ...args);
|
||||
}
|
||||
|
||||
warn(): void {
|
||||
this._log(LogLevel.Warning, arguments);
|
||||
warn(message: string, ...args: any[]): void {
|
||||
this._log(LogLevel.Warning, message, ...args);
|
||||
}
|
||||
|
||||
error(): void {
|
||||
this._log(LogLevel.Error, arguments);
|
||||
error(message: string | Error, ...args: any[]): void {
|
||||
this._log(LogLevel.Error, message, ...args);
|
||||
}
|
||||
|
||||
critical(): void {
|
||||
this._log(LogLevel.Critical, arguments);
|
||||
critical(message: string | Error, ...args: any[]): void {
|
||||
this._log(LogLevel.Critical, message, ...args);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
|
||||
@@ -3,12 +3,14 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ILogService, LogLevel, AbstractLogService } from 'vs/platform/log/common/log';
|
||||
import { ILogService, LogLevel, AbstractLogService, ILoggerService, ILogger } from 'vs/platform/log/common/log';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
import { Queue } from 'vs/base/common/async';
|
||||
import { VSBuffer } from 'vs/base/common/buffer';
|
||||
import { dirname, joinPath, basename } from 'vs/base/common/resources';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
const MAX_FILE_SIZE = 1024 * 1024 * 5;
|
||||
|
||||
@@ -16,6 +18,7 @@ export class FileLogService extends AbstractLogService implements ILogService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
private readonly initializePromise: Promise<void>;
|
||||
private readonly queue: Queue<void>;
|
||||
private backupIndex: number = 1;
|
||||
|
||||
@@ -28,6 +31,7 @@ export class FileLogService extends AbstractLogService implements ILogService {
|
||||
super();
|
||||
this.setLevel(level);
|
||||
this.queue = this._register(new Queue<void>());
|
||||
this.initializePromise = this.initialize();
|
||||
}
|
||||
|
||||
trace(): void {
|
||||
@@ -82,8 +86,13 @@ export class FileLogService extends AbstractLogService implements ILogService {
|
||||
this._log(level, this.format(args));
|
||||
}
|
||||
|
||||
private async initialize(): Promise<void> {
|
||||
await this.fileService.createFile(this.resource);
|
||||
}
|
||||
|
||||
private _log(level: LogLevel, message: string): void {
|
||||
this.queue.queue(async () => {
|
||||
await this.initializePromise;
|
||||
let content = await this.loadContent();
|
||||
if (content.length > MAX_FILE_SIZE) {
|
||||
await this.fileService.writeFile(this.getBackupResource(), VSBuffer.fromString(content));
|
||||
@@ -145,3 +154,33 @@ export class FileLogService extends AbstractLogService implements ILogService {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export class FileLoggerService extends Disposable implements ILoggerService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
private readonly loggers = new Map<string, ILogger>();
|
||||
|
||||
constructor(
|
||||
@ILogService private logService: ILogService,
|
||||
@IInstantiationService private instantiationService: IInstantiationService,
|
||||
) {
|
||||
super();
|
||||
this._register(logService.onDidChangeLogLevel(level => this.loggers.forEach(logger => logger.setLevel(level))));
|
||||
}
|
||||
|
||||
getLogger(resource: URI): ILogger {
|
||||
let logger = this.loggers.get(resource.toString());
|
||||
if (!logger) {
|
||||
logger = this.instantiationService.createInstance(FileLogService, basename(resource), resource, this.logService.getLevel());
|
||||
this.loggers.set(resource.toString(), logger);
|
||||
}
|
||||
return logger;
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.loggers.forEach(logger => logger.dispose());
|
||||
this.loggers.clear();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,10 @@ import { isWindows } from 'vs/base/common/platform';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { LoggerChannelClient } from 'vs/platform/log/common/logIpc';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
|
||||
export const ILogService = createServiceDecorator<ILogService>('logService');
|
||||
export const ILoggerService = createServiceDecorator<ILoggerService>('loggerService');
|
||||
|
||||
function now(): string {
|
||||
return new Date().toISOString();
|
||||
@@ -28,12 +30,11 @@ export enum LogLevel {
|
||||
|
||||
export const DEFAULT_LOG_LEVEL: LogLevel = LogLevel.Info;
|
||||
|
||||
export interface ILogService extends IDisposable {
|
||||
_serviceBrand: undefined;
|
||||
export interface ILogger extends IDisposable {
|
||||
onDidChangeLogLevel: Event<LogLevel>;
|
||||
|
||||
getLevel(): LogLevel;
|
||||
setLevel(level: LogLevel): void;
|
||||
|
||||
trace(message: string, ...args: any[]): void;
|
||||
debug(message: string, ...args: any[]): void;
|
||||
info(message: string, ...args: any[]): void;
|
||||
@@ -42,6 +43,16 @@ export interface ILogService extends IDisposable {
|
||||
critical(message: string | Error, ...args: any[]): void;
|
||||
}
|
||||
|
||||
export interface ILogService extends ILogger {
|
||||
_serviceBrand: undefined;
|
||||
}
|
||||
|
||||
export interface ILoggerService {
|
||||
_serviceBrand: undefined;
|
||||
|
||||
getLogger(file: URI): ILogger;
|
||||
}
|
||||
|
||||
export abstract class AbstractLogService extends Disposable {
|
||||
|
||||
private level: LogLevel = DEFAULT_LOG_LEVEL;
|
||||
|
||||
50
src/vs/platform/log/node/loggerService.ts
Normal file
50
src/vs/platform/log/node/loggerService.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ILogService, ILoggerService, ILogger } from 'vs/platform/log/common/log';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { basename, extname, dirname } from 'vs/base/common/resources';
|
||||
import { Schemas } from 'vs/base/common/network';
|
||||
import { FileLogService } from 'vs/platform/log/common/fileLogService';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { SpdLogService } from 'vs/platform/log/node/spdlogService';
|
||||
|
||||
export class LoggerService extends Disposable implements ILoggerService {
|
||||
|
||||
_serviceBrand: undefined;
|
||||
|
||||
private readonly loggers = new Map<string, ILogger>();
|
||||
|
||||
constructor(
|
||||
@ILogService private logService: ILogService,
|
||||
@IInstantiationService private instantiationService: IInstantiationService,
|
||||
) {
|
||||
super();
|
||||
this._register(logService.onDidChangeLogLevel(level => this.loggers.forEach(logger => logger.setLevel(level))));
|
||||
}
|
||||
|
||||
getLogger(resource: URI): ILogger {
|
||||
let logger = this.loggers.get(resource.toString());
|
||||
if (!logger) {
|
||||
if (resource.scheme === Schemas.file) {
|
||||
const baseName = basename(resource);
|
||||
const ext = extname(resource);
|
||||
logger = new SpdLogService(baseName.substring(0, baseName.length - ext.length), dirname(resource).path, this.logService.getLevel());
|
||||
} else {
|
||||
logger = this.instantiationService.createInstance(FileLogService, basename(resource), resource, this.logService.getLevel());
|
||||
}
|
||||
this.loggers.set(resource.toString(), logger);
|
||||
}
|
||||
return logger;
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.loggers.forEach(logger => logger.dispose());
|
||||
this.loggers.clear();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,16 +30,19 @@ interface ILog {
|
||||
message: string;
|
||||
}
|
||||
|
||||
function log(logger: spdlog.RotatingLogger, level: LogLevel, message: string): void {
|
||||
function log(logger: spdlog.RotatingLogger, level: LogLevel, message: string, sync: boolean): void {
|
||||
switch (level) {
|
||||
case LogLevel.Trace: return logger.trace(message);
|
||||
case LogLevel.Debug: return logger.debug(message);
|
||||
case LogLevel.Info: return logger.info(message);
|
||||
case LogLevel.Warning: return logger.warn(message);
|
||||
case LogLevel.Error: return logger.error(message);
|
||||
case LogLevel.Critical: return logger.critical(message);
|
||||
case LogLevel.Trace: logger.trace(message); break;
|
||||
case LogLevel.Debug: logger.debug(message); break;
|
||||
case LogLevel.Info: logger.info(message); break;
|
||||
case LogLevel.Warning: logger.warn(message); break;
|
||||
case LogLevel.Error: logger.error(message); break;
|
||||
case LogLevel.Critical: logger.critical(message); break;
|
||||
default: throw new Error('Invalid log level');
|
||||
}
|
||||
if (sync) {
|
||||
logger.flush();
|
||||
}
|
||||
}
|
||||
|
||||
export class SpdLogService extends AbstractLogService implements ILogService {
|
||||
@@ -50,7 +53,7 @@ export class SpdLogService extends AbstractLogService implements ILogService {
|
||||
private _loggerCreationPromise: Promise<void> | undefined = undefined;
|
||||
private _logger: spdlog.RotatingLogger | undefined;
|
||||
|
||||
constructor(private readonly name: string, private readonly logsFolder: string, level: LogLevel) {
|
||||
constructor(private readonly name: string, private readonly logsFolder: string, level: LogLevel, private readonly sync: boolean = false) {
|
||||
super();
|
||||
this.setLevel(level);
|
||||
this._createSpdLogLogger();
|
||||
@@ -69,7 +72,7 @@ export class SpdLogService extends AbstractLogService implements ILogService {
|
||||
this._logger = logger;
|
||||
this._logger.setLevel(this.getLevel());
|
||||
for (const { level, message } of this.buffer) {
|
||||
log(this._logger, level, message);
|
||||
log(this._logger, level, message, this.sync);
|
||||
}
|
||||
this.buffer = [];
|
||||
}
|
||||
@@ -80,53 +83,52 @@ export class SpdLogService extends AbstractLogService implements ILogService {
|
||||
|
||||
private _log(level: LogLevel, message: string): void {
|
||||
if (this._logger) {
|
||||
log(this._logger, level, message);
|
||||
log(this._logger, level, message, this.sync);
|
||||
} else if (this.getLevel() <= level) {
|
||||
this.buffer.push({ level, message });
|
||||
}
|
||||
}
|
||||
|
||||
trace(): void {
|
||||
trace(message: string, ...args: any[]): void {
|
||||
if (this.getLevel() <= LogLevel.Trace) {
|
||||
this._log(LogLevel.Trace, this.format(arguments));
|
||||
this._log(LogLevel.Trace, this.format([message, ...args]));
|
||||
}
|
||||
}
|
||||
|
||||
debug(): void {
|
||||
debug(message: string, ...args: any[]): void {
|
||||
if (this.getLevel() <= LogLevel.Debug) {
|
||||
this._log(LogLevel.Debug, this.format(arguments));
|
||||
this._log(LogLevel.Debug, this.format([message, ...args]));
|
||||
}
|
||||
}
|
||||
|
||||
info(): void {
|
||||
info(message: string, ...args: any[]): void {
|
||||
if (this.getLevel() <= LogLevel.Info) {
|
||||
this._log(LogLevel.Info, this.format(arguments));
|
||||
this._log(LogLevel.Info, this.format([message, ...args]));
|
||||
}
|
||||
}
|
||||
|
||||
warn(): void {
|
||||
warn(message: string, ...args: any[]): void {
|
||||
if (this.getLevel() <= LogLevel.Warning) {
|
||||
this._log(LogLevel.Warning, this.format(arguments));
|
||||
this._log(LogLevel.Warning, this.format([message, ...args]));
|
||||
}
|
||||
}
|
||||
|
||||
error(): void {
|
||||
error(message: string | Error, ...args: any[]): void {
|
||||
if (this.getLevel() <= LogLevel.Error) {
|
||||
const arg = arguments[0];
|
||||
|
||||
if (arg instanceof Error) {
|
||||
if (message instanceof Error) {
|
||||
const array = Array.prototype.slice.call(arguments) as any[];
|
||||
array[0] = arg.stack;
|
||||
array[0] = message.stack;
|
||||
this._log(LogLevel.Error, this.format(array));
|
||||
} else {
|
||||
this._log(LogLevel.Error, this.format(arguments));
|
||||
this._log(LogLevel.Error, this.format([message, ...args]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
critical(): void {
|
||||
critical(message: string | Error, ...args: any[]): void {
|
||||
if (this.getLevel() <= LogLevel.Critical) {
|
||||
this._log(LogLevel.Critical, this.format(arguments));
|
||||
this._log(LogLevel.Critical, this.format([message, ...args]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,4 +165,4 @@ export class SpdLogService extends AbstractLogService implements ILogService {
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user