2021-02-12 18:36:09 +05:30
|
|
|
/*
|
2021-03-01 19:31:43 +05:30
|
|
|
Copyright 2021 The Matrix.org Foundation C.I.C.
|
2021-02-12 18:36:09 +05:30
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
2021-11-10 12:36:56 +05:30
|
|
|
import {LogLevel} from "./LogFilter";
|
2021-11-15 17:29:08 +05:30
|
|
|
import type {ILogItem, LabelOrValues, LogCallback, LogItemValues} from "./LogItem";
|
2021-02-12 18:36:09 +05:30
|
|
|
|
2021-11-15 17:29:08 +05:30
|
|
|
function noop (): void {}
|
2021-03-15 17:25:46 +05:30
|
|
|
|
|
|
|
|
2021-02-12 18:36:09 +05:30
|
|
|
export class NullLogger {
|
2021-11-15 17:29:08 +05:30
|
|
|
public readonly item: ILogItem = new NullLogItem(this);
|
2021-02-12 18:36:09 +05:30
|
|
|
|
2021-11-15 17:29:08 +05:30
|
|
|
log(): void {}
|
2021-02-22 15:18:46 +05:30
|
|
|
|
2021-11-15 17:29:08 +05:30
|
|
|
run(_: null, callback) {
|
2021-03-15 17:25:46 +05:30
|
|
|
return callback(this.item);
|
|
|
|
}
|
|
|
|
|
|
|
|
wrapOrRun(item, _, callback) {
|
|
|
|
if (item) {
|
2021-06-23 15:12:32 +05:30
|
|
|
return item.wrap(null, callback);
|
2021-03-15 17:25:46 +05:30
|
|
|
} else {
|
2021-06-23 15:12:32 +05:30
|
|
|
return this.run(null, callback);
|
2021-03-15 17:25:46 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
runDetached(_, callback) {
|
|
|
|
new Promise(r => r(callback(this.item))).then(noop, noop);
|
2021-02-12 18:36:09 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
async export() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
get level() {
|
|
|
|
return LogLevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-15 17:29:08 +05:30
|
|
|
export class NullLogItem implements ILogItem {
|
|
|
|
public readonly logger: NullLogger;
|
|
|
|
public readonly logLevel: LogLevel;
|
|
|
|
public children: Array<ILogItem> | null = null;
|
|
|
|
public values: LogItemValues;
|
|
|
|
public error: Error | null = null;
|
|
|
|
|
|
|
|
constructor(logger: NullLogger) {
|
2021-09-22 00:28:50 +05:30
|
|
|
this.logger = logger;
|
|
|
|
}
|
|
|
|
|
2021-11-15 17:29:08 +05:30
|
|
|
wrap(_: LabelOrValues, callback: LogCallback): unknown {
|
2021-02-16 20:05:30 +05:30
|
|
|
return callback(this);
|
2021-02-12 18:36:09 +05:30
|
|
|
}
|
2021-11-15 17:29:08 +05:30
|
|
|
log(): void {}
|
|
|
|
set(): void {}
|
2021-03-15 17:25:46 +05:30
|
|
|
|
2021-11-15 17:29:08 +05:30
|
|
|
runDetached(_: LabelOrValues, callback: LogCallback): ILogItem {
|
2021-03-15 17:25:46 +05:30
|
|
|
new Promise(r => r(callback(this))).then(noop, noop);
|
2021-11-15 17:29:08 +05:30
|
|
|
return this;
|
2021-03-15 17:25:46 +05:30
|
|
|
}
|
|
|
|
|
2021-11-15 17:29:08 +05:30
|
|
|
wrapDetached(_: LabelOrValues, _callback: LogCallback): void {
|
|
|
|
return this.refDetached();
|
2021-03-15 17:25:46 +05:30
|
|
|
}
|
|
|
|
|
2021-11-15 17:29:08 +05:30
|
|
|
run(callback: LogCallback): unknown {
|
2021-03-15 17:25:46 +05:30
|
|
|
return callback(this);
|
|
|
|
}
|
|
|
|
|
2021-11-15 17:29:08 +05:30
|
|
|
refDetached(): void {}
|
2021-02-12 18:36:09 +05:30
|
|
|
|
2021-11-15 17:29:08 +05:30
|
|
|
ensureRefId(): void {}
|
2021-09-18 03:49:16 +05:30
|
|
|
|
2021-11-15 17:29:08 +05:30
|
|
|
get level(): typeof LogLevel {
|
2021-02-12 18:36:09 +05:30
|
|
|
return LogLevel;
|
|
|
|
}
|
2021-02-12 23:05:33 +05:30
|
|
|
|
2021-11-15 17:29:08 +05:30
|
|
|
get duration(): 0 {
|
2021-03-15 17:25:46 +05:30
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-11-15 17:29:08 +05:30
|
|
|
catch(err: Error): Error {
|
2021-02-12 23:05:33 +05:30
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2021-11-15 17:29:08 +05:30
|
|
|
child() {
|
2021-02-12 23:05:33 +05:30
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2021-11-15 17:29:08 +05:30
|
|
|
finish(): void {}
|
|
|
|
|
|
|
|
serialize() {
|
|
|
|
return null;
|
|
|
|
}
|
2021-02-12 18:36:09 +05:30
|
|
|
}
|
2021-03-15 19:53:35 +05:30
|
|
|
|
|
|
|
export const Instance = new NullLogger();
|