log-mess
Version:
Log messages with tags and configuration
29 lines • 1.22 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.logMessage = logMessage;
const availability_1 = require("./availability.cjs");
const id_1 = require("./id.cjs");
const persistent_1 = require("./persistent.cjs");
const tag_1 = require("./tag.cjs");
function logMessage(tagOrMeta, ...value) {
const omode = typeof tagOrMeta === "object";
const tag = omode ? tagOrMeta.tag : tagOrMeta;
const meta = omode ? tagOrMeta : undefined;
const id = (0, id_1.getId)();
if ((0, availability_1.isVariable)())
persistent_1.store.messages.value.push({ id, tag, timestamp: Date.now(), value });
if ((0, availability_1.isLog)(tag, meta?.silent))
console.log(...(0, tag_1.getTag)(tag, meta), ...value);
return {
update: (...value) => {
const index = persistent_1.store.messages.value.findIndex((x) => x.id === id);
if (index === -1)
return;
persistent_1.store.messages.value[index].value = value;
},
remove: () => {
persistent_1.store.messages.value = persistent_1.store.messages.$value.filter((x) => x.id !== id);
},
};
}
//# sourceMappingURL=message.js.map
;