vector-im-hydrogen-web/src/logging/NullLogger.js

94 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-02-12 14:06:09 +01:00
/*
2021-03-01 15:01:43 +01:00
Copyright 2021 The Matrix.org Foundation C.I.C.
2021-02-12 14:06:09 +01:00
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-02-16 15:35:30 +01:00
import {LogLevel} from "./LogFilter.js";
2021-02-12 14:06:09 +01:00
function noop () {}
2021-02-12 14:06:09 +01:00
export class NullLogger {
constructor() {
this.item = new NullLogItem();
2021-02-12 14:06:09 +01:00
}
2021-02-22 10:48:46 +01:00
log() {}
2021-02-12 18:35:33 +01:00
run(_, callback) {
return callback(this.item);
}
wrapOrRun(item, _, callback) {
if (item) {
return item.wrap(null, callback);
} else {
return this.run(null, callback);
}
}
runDetached(_, callback) {
new Promise(r => r(callback(this.item))).then(noop, noop);
2021-02-12 14:06:09 +01:00
}
async export() {
return null;
}
get level() {
return LogLevel;
}
}
export class NullLogItem {
2021-02-12 14:06:09 +01:00
wrap(_, callback) {
2021-02-16 15:35:30 +01:00
return callback(this);
2021-02-12 14:06:09 +01:00
}
log() {}
set() {}
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 14:06:09 +01:00
get level() {
return LogLevel;
}
2021-02-12 18:35:33 +01:00
get duration() {
return 0;
}
2021-02-12 18:35:33 +01:00
catch(err) {
return err;
}
child() {
return this;
}
finish() {}
2021-02-12 14:06:09 +01:00
}
2021-03-15 15:23:35 +01:00
export const Instance = new NullLogger();