2024-05-29 14:53:58 +02:00
|
|
|
export function log(message, level = 'info') {
|
2024-06-12 09:07:09 +02:00
|
|
|
const wpDebug = window.wc_ppcp_axo?.wp_debug;
|
2024-05-29 15:21:21 +02:00
|
|
|
const endpoint = window.wc_ppcp_axo?.ajax?.frontend_logger?.endpoint;
|
2024-06-12 22:30:33 +02:00
|
|
|
if (!endpoint) {
|
2024-05-29 14:53:58 +02:00
|
|
|
return;
|
|
|
|
}
|
2024-02-12 18:06:48 +00:00
|
|
|
|
2024-05-29 14:53:58 +02:00
|
|
|
fetch(endpoint, {
|
|
|
|
method: 'POST',
|
|
|
|
credentials: 'same-origin',
|
|
|
|
body: JSON.stringify({
|
2024-05-29 15:21:21 +02:00
|
|
|
nonce: window.wc_ppcp_axo.ajax.frontend_logger.nonce,
|
2024-05-29 14:53:58 +02:00
|
|
|
log: {
|
|
|
|
message,
|
|
|
|
level,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}).then(() => {
|
2024-06-12 22:30:33 +02:00
|
|
|
if (wpDebug) {
|
|
|
|
switch (level) {
|
|
|
|
case 'error':
|
|
|
|
console.error(`[AXO] ${message}`);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log(`[AXO] ${message}`);
|
|
|
|
}
|
2024-05-29 14:53:58 +02:00
|
|
|
}
|
|
|
|
});
|
2024-02-12 18:06:48 +00:00
|
|
|
}
|