提交 2e257cfc 编写于 作者: B Benjamin Pasero

storage - easier tracing configuration

上级 e4ff4842
......@@ -21,8 +21,6 @@ export interface IStorageOptions {
export interface IStorageLoggingOptions {
logError?: (error: string | Error) => void;
trace?: boolean;
logTrace?: (msg: string) => void;
}
......@@ -509,27 +507,32 @@ export class SQLiteStorageImpl {
}
class SQLiteStorageLogger {
private readonly logTrace: boolean;
private readonly logError: boolean;
private readonly logTrace: (msg: string) => void;
private readonly logError: (error: string | Error) => void;
constructor(options?: IStorageLoggingOptions) {
if (options && typeof options.logTrace === 'function') {
this.logTrace = options.logTrace;
}
constructor(private readonly options?: IStorageLoggingOptions) {
this.logTrace = !!(options && options.trace && typeof options.logTrace === 'function');
this.logError = !!(options && typeof options.logError === 'function');
if (options && typeof options.logError === 'function') {
this.logError = options.logError;
}
}
get isTracing(): boolean {
return this.logTrace;
return !!this.logTrace;
}
trace(msg: string): void {
if (this.logTrace && this.options && this.options.logTrace) {
this.options.logTrace(msg);
if (this.logTrace) {
this.logTrace(msg);
}
}
error(error: string | Error): void {
if (this.logError && this.options && this.options.logError) {
this.options.logError(error);
if (this.logError) {
this.logError(error);
}
}
}
......
......@@ -69,8 +69,7 @@ export class StorageService extends Disposable implements IStorageService {
super();
this.loggingOptions = {
trace: logService.getLevel() === LogLevel.Trace,
logTrace: msg => logService.trace(msg),
logTrace: (logService.getLevel() === LogLevel.Trace) ? msg => logService.trace(msg) : void 0,
logError: error => {
logService.error(error);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册