add silent logging (restrict only to the console)
This commit is contained in:
parent
ac34ee55a3
commit
06d460f9c2
1 changed files with 12 additions and 6 deletions
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue