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-02-12 18:36:09 +05:30
|
|
|
|
2021-03-15 17:25:46 +05:30
|
|
|
function noop () {}
|
|
|
|
|
|
|
|
|
2021-02-12 18:36:09 +05:30
|
|
|
export class NullLogger {
|
|
|
|
constructor() {
|
2021-09-22 00:28:50 +05:30
|
|
|
this.item = new NullLogItem(this);
|
2021-02-12 18:36:09 +05:30
|
|
|
}
|
|
|
|
|
2021-02-22 15:18:46 +05:30
|
|
|
log() {}
|
|
|
|
|
2021-02-12 23:05:33 +05:30
|
|
|
run(_, 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-04-20 19:41:21 +05:30
|
|
|
export class NullLogItem {
|
2021-09-22 00:28:50 +05:30
|
|
|
constructor(logger) {
|
|
|
|
this.logger = logger;
|
|
|
|
}
|
|
|
|
|
2021-02-12 18:36:09 +05:30
|
|
|
wrap(_, callback) {
|
2021-02-16 20:05:30 +05:30
|
|
|
return callback(this);
|
2021-02-12 18:36:09 +05:30
|
|
|
}
|
|
|
|
log() {}
|
|
|
|
set() {}
|
2021-03-15 17:25:46 +05:30
|
|
|
|
|
|
|
runDetached(_, callback) {
|
|
|
|
new Promise(r => r(callback(this))).then(noop, noop);
|
|
|
|
}
|
|
|
|
|
|
|
|
wrapDetached(_, callback) {
|
|
|
|
return this.refDetached(null, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
run(callback) {
|
|
|
|
return callback(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
refDetached() {}
|
2021-02-12 18:36:09 +05:30
|
|
|
|
2021-09-18 03:49:16 +05:30
|
|
|
ensureRefId() {}
|
|
|
|
|
2021-02-12 18:36:09 +05:30
|
|
|
get level() {
|
|
|
|
return LogLevel;
|
|
|
|
}
|
2021-02-12 23:05:33 +05:30
|
|
|
|
2021-03-15 17:25:46 +05:30
|
|
|
get duration() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-02-12 23:05:33 +05:30
|
|
|
catch(err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
child() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
finish() {}
|
2021-02-12 18:36:09 +05:30
|
|
|
}
|
2021-03-15 19:53:35 +05:30
|
|
|
|
|
|
|
export const Instance = new NullLogger();
|