Consolidate logging

This commit is contained in:
Emili Castells Guasch 2024-05-29 14:53:58 +02:00
parent 4c9ccebd10
commit 1524d03ba2
2 changed files with 45 additions and 53 deletions

View file

@ -1,4 +1,26 @@
export function log(message, level = 'info') {
const endpoint = this.axoConfig?.ajax?.frontend_logger?.endpoint;
if(!endpoint) {
return;
}
export function log(...args) {
//console.log('[AXO] ', ...args);
fetch(endpoint, {
method: 'POST',
credentials: 'same-origin',
body: JSON.stringify({
nonce: this.axoConfig.ajax.frontend_logger.nonce,
log: {
message,
level,
}
})
}).then(() => {
switch (level) {
case 'error':
console.error(`[AXO] ${message}`);
break;
default:
console.log(`[AXO] ${message}`);
}
});
}