add silent logging (restrict only to the console)

This commit is contained in:
buzz-lightsnack-2007 2024-05-15 17:12:48 +08:00
parent ac34ee55a3
commit 06d460f9c2

View file

@ -18,8 +18,9 @@ export default class logging {
@param {string} TITLE the title @param {string} TITLE the title
@param {string} MESSAGE the message @param {string} MESSAGE the message
@param {bool} PRIORITY automatically dismiss other, older messages */ @param {bool} OPTIONS the options; if boolean, clear the current message
constructor(TITLE, MESSAGE, PRIORITY = false) { */
constructor(TITLE, MESSAGE, OPTIONS = {}) {
// Set this message's properties. // Set this message's properties.
if (!MESSAGE || (typeof MESSAGE).includes(`undef`)) { if (!MESSAGE || (typeof MESSAGE).includes(`undef`)) {
this.message = TITLE; this.message = TITLE;
@ -28,8 +29,6 @@ export default class logging {
this.message = MESSAGE; this.message = MESSAGE;
} }
(PRIORITY) ? this.clear() : false;
// Display the message. // Display the message.
if (MESSAGE) { if (MESSAGE) {
console.log(`%c%s\n%c%s`, `font-weight: bold; font-family: system-ui;`, this.title, `font-family: system-ui;`, this.message); console.log(`%c%s\n%c%s`, `font-weight: bold; font-family: system-ui;`, this.title, `font-family: system-ui;`, this.message);
@ -38,11 +37,18 @@ export default class logging {
} }
try { try {
M.toast({ text: (MESSAGE ? (this.title).concat(`\n`) : ``).concat(this.message) }); (((typeof OPTIONS).includes(`bool`) ? OPTIONS : false) || ((typeof OPTIONS).includes(`obj`) ? OPTIONS[`priority`] : false))
? this.clear()
: false;
(((typeof OPTIONS).includes(`obj`) ? Object.hasOwn(OPTIONS, `silent`) : false) ? !OPTIONS[`silent`] : true)
? M.toast({ text: (MESSAGE ? (this.title).concat(`\n`) : ``).concat(this.message) })
: false;
} catch (err) {} } catch (err) {}
} }
static log(message) { static log(title, message, priority) {
return(new logging(message)); return(new logging(message));
} }