2023-06-26 08:29:03 +00:00
|
|
|
// Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
|
|
|
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
2021-05-03 17:46:00 +00:00
|
|
|
|
|
|
|
/** Conditional logger singleton */
|
2021-05-07 12:25:42 +00:00
|
|
|
const log = (function() {
|
|
|
|
let mode = MODE.production;
|
2021-05-03 17:46:00 +00:00
|
|
|
return {
|
2021-05-07 12:25:42 +00:00
|
|
|
/** console.error() wrapper */
|
2021-05-03 17:46:00 +00:00
|
|
|
debug: (data: any) => {
|
2021-05-07 12:25:42 +00:00
|
|
|
if (mode == MODE.none) {
|
|
|
|
return;
|
|
|
|
}
|
2021-05-03 17:46:00 +00:00
|
|
|
if (mode == MODE.development) {
|
|
|
|
console.debug(data);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-05-07 12:25:42 +00:00
|
|
|
/** console.error() wrapper */
|
2021-05-03 17:46:00 +00:00
|
|
|
error: (data: any) => {
|
|
|
|
console.error(data);
|
|
|
|
},
|
|
|
|
|
2021-05-07 12:25:42 +00:00
|
|
|
/** console.log() wrapper */
|
2021-05-03 17:46:00 +00:00
|
|
|
log: (data: any) => {
|
2021-05-07 12:25:42 +00:00
|
|
|
if (mode == MODE.none) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-03 17:46:00 +00:00
|
|
|
console.log(data);
|
|
|
|
},
|
2021-05-07 12:25:42 +00:00
|
|
|
|
|
|
|
/** set logging mode */
|
|
|
|
setMode: (newMode: MODE) => (mode = newMode),
|
2021-05-03 17:46:00 +00:00
|
|
|
};
|
|
|
|
})();
|
2021-05-07 12:25:42 +00:00
|
|
|
|
|
|
|
export const enum MODE {
|
|
|
|
production,
|
|
|
|
development,
|
|
|
|
none,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default log;
|